Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
10.11k stars 713 forks source link

BUG - Decimator does not work with multiple traces #1062

Open AlexandreSajus opened 4 months ago

AlexandreSajus commented 4 months ago

The decimator should work with multiple traces in a line chart

Without decimator:

image

With decimator:

[2024-03-28 15:10:31][Taipy][INFO]  * Server starting on http://127.0.0.1:5000
C:\Users\asaju\Desktop\report_issues\venv\Lib\site-packages\taipy\gui\gui.py:635: TaipyGuiWarning: A problem occurred while resolving variable 'data' in module '__main__'.
  _warn(

image

Code:

from taipy.gui import Gui
from taipy.gui.data.decimator import MinMaxDecimator
import pandas as pd
import numpy as np

NOP = 500
decimator_instance = MinMaxDecimator(n_out=NOP)

data = pd.DataFrame(
    {
        "Time": np.arange(0, 10, 0.1),
        "A": np.arange(0, 10, 0.1) + np.random.randn(100) + 10,
        "B": np.arange(0, 10, 0.1) + np.random.randn(100),
    }
)

page = """
<|{data}|chart|x=Time|y[1]=A|y[2]=B|decimator=decimator_instance|>
"""

Gui(page).run()
arcanaxion commented 4 months ago

I believe you have to index the decimator property when you have multiple traces: https://docs.taipy.io/en/latest/manuals/gui/viselements/chart/#p-decimator

page = """
<|{data}|chart|x=Time|y[1]=A|y[2]=B|decimator[1]=decimator_instance|decimator[2]=decimator_instance|>
"""
arcanaxion commented 4 months ago

I initially couldn't get the decimator to work for your example even after the modification I made, and lowering NOP to 10. Seems like even when Decimator.threshold=None, there's still some threshold before the decimator kicks in. Maybe the devs can shed more light on this.

In the meantime, explicitly setting threshold to NOP seems to work:

from taipy.gui import Gui
from taipy.gui.data.decimator import MinMaxDecimator
import pandas as pd
import numpy as np

NOP = 10
decimator_instance = MinMaxDecimator(n_out=NOP, threshold=NOP)

data = pd.DataFrame(
    {
        "Time": np.arange(0, 10, 0.1),
        "A": np.arange(0, 10, 0.1) + np.random.randn(100) + 10,
        "B": np.arange(0, 10, 0.1) + np.random.randn(100),
    }
)

page = """
<|{data}|chart|x=Time|y[1]=A|y[2]=B|decimator[1]=decimator_instance|decimator[2]=decimator_instance|>
"""

Gui(page).run()
AlexandreSajus commented 4 months ago

Thanks finding the workaround, this does indeed seem to work properly. We should definitely still look at this, having to explicitely set the threshold does not make sense from the user's perspective

github-actions[bot] commented 1 month ago

This issue has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this issue, please add another comment or create a PR that links to this issue. If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. Otherwise, you will be unassigned in 14 days. For more information please refer to the contributing guidelines.

github-actions[bot] commented 1 month ago

This issue has been unassigned automatically because it has been marked as "🥶Waiting for contributor" for more than 14 days with no activity.