Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart animation #2443

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Chart animation #2443

wants to merge 2 commits into from

Conversation

namnguyen20999
Copy link
Member

@namnguyen20999 namnguyen20999 commented Feb 11, 2025

What type of PR is this? (check all applicable)

Description

from taipy.gui import Gui

# Original data
data = {
    "x": [
        "2024-01-01 00:00:00", "2024-01-01 01:00:00", "2024-01-01 02:00:00",
        "2024-01-01 03:00:00", "2024-01-01 04:00:00", "2024-01-01 05:00:00",
        "2024-01-01 06:00:00", "2024-01-01 07:00:00", "2024-01-01 08:00:00",
        "2024-01-01 09:00:00"
    ],
    "y1": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
}

layout = {
    "title": "Animation of Weather Data",
    "xaxis": {"title": "Altitude (m)"},
    "yaxis": {"title": "Value"},
    "updatemenus": [
        {
            "type": "buttons",
            "showactive": False,
            "buttons": [
                {
                    "method": "animate",
                    "args": [
                        ["to"],
                        {
                            "fromcurrent": True,
                            "mode": "immediate",
                            "frame": {"duration": 500, "redraw": True},
                            "transition": {"duration": 2000, "easing": "linear"}
                        }
                    ],
                    "label": "Play"
                }
            ]
        }
    ],
}

animation_data = {
    "y1": [v + 1 for v in data["y1"]],
}


def change_data_inc(state):
    state.animation_data["y1"] = [value + 1 for value in state.animation_data["y1"]]

def change_data_dec(state):
    state.animation_data["y1"] = [value - 1 for value in state.animation_data["y1"]]


# Define the page layout
page = """
<|{data}|chart|mode=lines+markers|x=x|y=y1|layout={layout}|animation_data={animation_data}|>
<|Increase|button|on_action=change_data_inc|>
<|Decrease|button|on_action=change_data_dec|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Animation on", port=8081, use_reloader=True)

Related Tickets & Documents

  • Related Issue #
  • Closes #

How to reproduce the issue

Please replace this line with instructions on how to reproduce the issue or test the feature.

Other branches or releases that this needs to be backported

Describe which projects this change will impact and that needs to be backported.

Checklist

We encourage you to keep the code coverage percentage at 80% and above.

  • This solution meets the acceptance criteria of the related issue.
  • The related issue checklist is completed.
  • This PR adds unit tests for the developed code. If not, why?
  • End-to-End tests have been added or updated. If not, why?
  • The documentation has been updated, or a dedicated issue created. (If applicable)
  • The release notes have been updated? (If applicable)

@namnguyen20999 namnguyen20999 self-assigned this Feb 11, 2025
@namnguyen20999 namnguyen20999 linked an issue Feb 11, 2025 that may be closed by this pull request
6 tasks
@namnguyen20999 namnguyen20999 changed the title demo purposes Chart animation Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Plotly animation
1 participant