Deneb Dynamic Y axis Range

Hi,

I am trying to get dynamic range for the y-axis. In other words i would like y axis range to remain static based on the country selection. I tried to use the transform and params block to create Min and Max range and then used in the domain, but its not working.
appreciate any help in this regard.
I am attaching the pbix for your review.
Dynamic Y Range.pbix (1.5 MB)

Hi @dahlia.carroll:

Vega-Lite automatically calculates axis scales, so I was able to get this merely by removing the transform, params, and scale blocks from your original code:

Here’s the code:

{
  "title": {
    "anchor": "start",
    "align": "left",
    "orient": "top",
    "offset": 24,
    "text": "eDNA Forum - Deneb Dynamic Y-axis Range",
    "font": "Segoe UI",
    "fontSize": 24,
    "fontWeight": "bold",
    "fontStyle": "normal"
  },
  "data": {"name": "dataset"},
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "dollar_price",
      "type": "quantitative"
    },
    "color": {
      "field": "country_name",
      "type": "nominal"
    }
  },
  "layer": [
    {
      "name": "LINES",
      "mark": {
        "type": "line",
        "point": true
      }
    },
    {
      "name": "DATA_LABELS",
      "transform": [
        {
          "calculate": "format( datum.dollar_price, '.1f' )",
          "as": "New_Text"
        }
      ],
      "mark": {
        "type": "text",
        "align": "left",
        "baseline": "middle",
        "yOffset": -10
      },
      "encoding": {
        "text": {
          "field": "New_Text",
          "type": "quantitative"
        }
      }
    }
  ]
}

If I’ve misunderstood the issue, please clarify.

Hope it helps.
Greg
eDNA Forum - Deneb Dynamic Y-axis Range.pbix (1.5 MB)

Hi Greg,
Thank you for your quick reply. However I do not want Vega-lite to recalculate the Y-axis every time I had a new selection. For this complete dataset the Min is 0.80 and Max is 8.06. So I want the y-axis to have this range and should not change irrespective of any country selection.
Let me know if you have any further questions.
Thank you.

OK, the add back the scale block with your values. I don’t believe Vega-Lite permits calculations in scale domains.

Here’s my scale block inside the y-axis block:

    "y": {
      "field": "dollar_price",
      "type": "quantitative",
      "scale": {"domain": [0.8, 8.06]}
    }

Hope it helps.
Greg

Thanks for your quick reply. There seems to be a solution to this post (link below), it does answer my question. However i am unable to understand the expressions used in the param block
“params”:
[ {“name”: “max”, “expr”: “data(‘data_0’)[0][‘max’]”},
{“name”: “min”, “expr”: “data('data_0 *)[0][‘min’]”} ]
https://stackoverflow.com/questions/75456476/setting-a-dynamic-domain-in-vega-lite-deneb/

OK2, well news to me. I’d go with David’s Bacci’s insight every time. As far as the syntax goes, I’ve seen something like this only once (by the author of the Deneb custom visual); I’ve no experience directly and don’t fully understand it myself, so I’ll reserve comment until I’ve gained more experience.
Greg

Hi @dahlia.carroll:

You gave the example:

"params": [
	{"name": "max", "expr": "data('data_0')[0]['max']"},
	{"name": "min", "expr": "data('data_0')[0]['min']"}
]

I’ve reviewed my notes and explored a bit and here’s my understanding:

data 	= the "data" function (allows access to all datasets)
data_0 	= the name of the desired dataset
0 		= the index of the desired row in the dataset's array (i.e., the accessor)
max 	= the name of the desired field from the referenced dataset

So, I stand corrected: you can use an expression in the scale domain.

I successfully used a mildly-modified version of the code you referenced from Davide Bacci which uses a “line” mark as a test case.

I also tried it out using an “arc” mark with a small dataset of the top 5 countries by population (2023) to confirm.

Please note that this is only my interpretation, and may not be correct. Hope it helps anyway.
Greg
eDNA Forum - Deneb Dynamic Y-axis Range - V3.pbix (1.5 MB)