vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.56k stars 594 forks source link

Clamp scale extents when zooming #4886

Open zufanka opened 5 years ago

zufanka commented 5 years ago

Originally opened an issue for this on altair, got referred to vega-lite

I am making an interactive barchart with altair : Chart.interactive(). I would like it not to be able to go beyond the 0 and above 1000 on the X axis when zooming in and moving the bars around.

I am trying to set boundaries to the X axis with alt.X(scale = alt.scale(domain=(0,1000))) but that does not prevent the visualization going into out of these bounds on the X axis.

image

Could there be some way to set the limits to scales on interactive visualizations in vega-lite?

jheer commented 5 years ago

In Altair, try adding a clip=True argument to your barMark method?

jakevdp commented 5 years ago

I think @zufanka is asking for something different: the ability to constrain the interactivity of the axes to a particular range. So that, e.g. you could zoom freely within the range 0...1000, but the axis extent would be prevented from being larger than [0, 1000].

jheer commented 5 years ago

Thanks @jakevdp, it appears I pattern-matched too quickly! I agree that this would be a great feature to include.

zufanka commented 5 years ago

@jakevdp yes indeed! In the case of barcharts it's namely not that intuitive (for me at least) that I will be zooming in where the mouse pointer is. That is why constraining the axis would be a very welcome feature

Benjamin-Lee commented 4 years ago

To add another use case, I'm trying to make a Gantt chart using relative times (i.e. we don't care the time a step happens, only its time relative to the other ones). To make it work, I'm offsetting from 0 Unix time, which works perfectly unless the user scrolls to the left:

image

I want to limit scroll to only time range of the Gantt chart to prevent confusion with an "overflow".

riledigital commented 4 years ago

I agree that this would be very useful. The unbounded interactions can be a bit distracting when you are exploring a dataset with integer quantities but looking between gaps of decimal point axes.

aldanor commented 4 years ago

Agreed, this would be very nice to have.

(In fact if you think about it this might have even been a reasonable default option since there's always a limited amount of data and it doesn't make much sense to navigate and scroll beyond it.)

PBrockmann commented 3 years ago

Investigating clipping from vega-lite in an Observable notebook. https://observablehq.com/@pbrockmann/untitled/4

Is there a way to clip when bars are outside the scale domain ?

image

jwoLondon commented 3 years ago

This is probably the kind of question that is best asked on Slack rather than as a GitHub issue.

But, yes, simply use vl.markBar({"clip":true})

al6x commented 2 years ago

Would be better to make clip default. Usually what happens is that you set domain and you got empty chart (because overflow area is so huge that the actual chart shrinks to nothing) and have no idea what's going on and why there's absolutely nothing on the screen if there's some bug or something like that.