Search code examples
vega-litedeneb

Set domainMax to max of brushed values


I am working with the Overview and Detail Vega-Lite sample at https://vega.github.io/vega-lite/examples/interactive_overview_detail.html

I would like the Detail chart to dynamically adjust the y-axis to reflect the brushed values in the Overview chart, not the entire dataset. So when I select this valley in 2009, I want the y-axis on the Detail chart to be more like 1000 than 1500. Brushed data

So for this modified sample, how do I dynamically set domainMax based on the brushed data?

        "y": {
          "field": "price", 
          "type": "quantitative",
          "scale": {"domainMax": 1000}
        }

Open the Chart in the Vega Editor


Solution

  • The right way to zoom in is to use "scale": {"zero": false} but you also have to set "stack": false. According to guru @jakevdp here, each area has an implicit stacked zero-height area for the group that does not appear but affects the automatically chosen axis limits.

            "y": {
              "field": "price", 
              "type": "quantitative",
              "stack": false,
              "scale": {
                "zero": false
              }
            }
    

    Working chart

    Open the Chart in the Vega Editor