vega-tooltip icon indicating copy to clipboard operation
vega-tooltip copied to clipboard

Tooltip values are wrong if css alters width of svg

Open caHaber opened this issue 5 years ago • 11 comments

Hey Ya'll.

I am using vega-embed to create charts dynamically of specified width and height. I am also applying a width via css on top of that so that the svg will resize to a proper window size. I'm afraid that when I do this the tooltip still functionally acts correctly but the values are fetched using the original size of the svg. (See image below.)

incorrect_tooltip_values

This seems like a bug but I would not be surprised if there is a simple work around I am missing.

Thank you for the great work you all are doing on vega and altair. The entire ecosystem is great and I hope to contribute as I get more comfortable with things.

caHaber avatar Dec 11 '19 23:12 caHaber

Thank you for filing the issue @caHaber. Can you look whether the issue is in this plugin or whether the locations that Vega gives us are incorrect when the image is scaled?

domoritz avatar Jan 21 '20 22:01 domoritz

@domoritz yup, i'll take a closer look and post here.

caHaber avatar Jan 22 '20 18:01 caHaber

Any updates on this? I have the same issue here https://github.com/vega/vega-embed/issues/432 on mobile devices when css takes over the responsiveness of the chart. Live demo of the issue here.

armsp avatar May 10 '20 18:05 armsp

I recommend scaling your chart in Vega instead. See https://vega.github.io/editor/#/examples/vega-lite/bar_size_responsive for an example of how you can listen to changes to the container size (also look at the generated Vega).

domoritz avatar May 10 '20 18:05 domoritz

@domoritz Just one clarification - how is the above example responsive? When I open the link and resize my window, the chart gets cropped. Am I missing something here?

armsp avatar May 11 '20 04:05 armsp

You can resize the chart from the bottom right corner of the chart.

domoritz avatar May 11 '20 06:05 domoritz

@domoritz pardon me, but I am having a hard time thinking....if I have to resize using the bottom right corner then how is it responsive? It should automatically happen when the window resizes, right? I am sorry, but I am just quite new to js and web dev things.

armsp avatar May 15 '20 06:05 armsp

No worries. The editor adds a handle to resize the container. The visualization adjusts to the container. In your application, the container would be sized relative to the overall window size.

domoritz avatar May 15 '20 15:05 domoritz

MTABcom6 avatar Jan 23 '21 05:01 MTABcom6

I recommend scaling your chart in Vega instead. See https://vega.github.io/editor/#/examples/vega-lite/bar_size_responsive for an example of how you can listen to changes to the container size (also look at the generated Vega).

@domoritz sorry for noob question, but where is the code that listen to size change ? All I see are a vega config but nothing related to embeding it in the container.

challet avatar Jul 05 '21 14:07 challet

Look for window:resize.

Screen Shot 2021-07-06 at 08 12 40

domoritz avatar Jul 06 '21 15:07 domoritz