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

No tool tips for Histogram with time x_scale #1474

Closed
mtanco opened this issue Jun 3, 2022 · 3 comments · Fixed by #1594
Closed

No tool tips for Histogram with time x_scale #1474

mtanco opened this issue Jun 3, 2022 · 3 comments · Fixed by #1594
Assignees
Labels
bug Bug in code plot Related to plotting ui Related to UI

Comments

@mtanco
Copy link
Contributor

mtanco commented Jun 3, 2022

Wave SDK Version, OS

h2o_wave 0.22.0

Actual behavior

tool tip hover for linear scale
image

no tool tip hover for time scale ( I can make a gif as needed since it's not really showing that my curser is on the plot...)
image

Expected behavior

Tool tip to work for all scale times

Please note I did not test other x_scale types or other plot types with time scale

Steps To Reproduce

from h2o_wave import main, app, Q, ui, data


@app('/')
async def serve(q: Q):
    q.page['ex1'] = ui.plot_card(
        box='1 1 4 3',
        title='Dates',
        data=data('low high price', 3, rows=[
            ("2022-01-01", "2022-01-31", 100),
            ("2022-02-01", "2022-02-28", 150),
            ("2022-03-01", "2022-03-31", 200),
        ]),
        plot=ui.plot([ui.mark(
            type='interval',
            y='=price', y_min=0,
            x1='=low', x2='=high', x_scale="time"
        )])
    )
    q.page['ex2'] = ui.plot_card(
        box='1 4 4 3',
        title='Numbers',
        data=data('low high price', 3, rows=[
            (1, 2, 100),
            (2, 3, 150),
            (3, 4, 200),
        ]),
        plot=ui.plot([ui.mark(
            type='interval',
            y='=price', y_min=0,
            x1='=low', x2='=high', x_scale="linear"
        )])
    )

    await q.page.save()
@mtanco mtanco added ui Related to UI bug Bug in code plot Related to plotting labels Jun 3, 2022
@marek-mihok
Copy link
Contributor

The problem lies in tooltip.ts:L98 in titleScale.getText(originData[titleField]) where

originData: {
  high: "2022-03-31"
  low: "2022-03-01"
  low - high: ['2022-03-01', '2022-03-31']
  price: 200
}

and titleField: "low - high".

When x_scale="time" the data are treated as a date objects. In our ranged low - high data an array is passed to the G2 date parsing function and it throws error as seen on the picture below:

image

However, in the second example there is no x_scale specified and therefore the data are not passed to date parsing function and therefore there is no error while showing the tooltip.

originData: {
  high: 4
  low: 3
  low - high: (2) [3, 4]
  price: 200
}

image

Looking on the G2 examples and API I couldn't find a direct support for histogram ranged data. Probably we need to find a different way how to refactor data passed to chart.

@lo5 you are an expert here. How do you think we should proceed?

cc @mturoci

@mturoci
Copy link
Collaborator

mturoci commented Aug 15, 2022

@marek-mihok one way to fix this is providing our own string for the tooltip title instead of having it computed by G2. This can basically be any string since we overwrite the tooltip with our custom React component without a title anyway. Wdyt?

Solution:

chart.tooltip({
    title: ' ', // HACK: Ignore tooltip title computation by G2 since we overwrite it anyway.
    showCrosshairs: true,
    crosshairs: { type: 'xy' },
    ...
)}

@marek-mihok
Copy link
Contributor

Thanks @mturoci. That's a perfect idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in code plot Related to plotting ui Related to UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants