-
Notifications
You must be signed in to change notification settings - Fork 606
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
Small non-zero values for size scale are not visible #3488
Comments
I also consider this a bug. We should map the range to [0..max] but 0 should map to a circle that doesn't have an empty area inside. |
Instead of setting the domain, we should set the range.
|
I wonder whether this is actually a Vega bug. With size 1, points are visible and even have a hole, while with size 0, they completely disappear. The documentation says that cc @jheer |
Yes, you can add production rule, instead of making scale inaccurate. |
Can you show an example in Vega? I can implement it in Vega-Lite afterwards. |
Just test if the size field is too small (need some epsilon constant), then apply different size, fill, stroke instead. |
Idea: You can even set the color to be different color for non-positive number, if color/fill/stroke is not set. (This is a bit more controversial so I'm not 100% sure if we should do this.) |
Something like {
"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"autosize": "pad",
"padding": 5,
"width": 500,
"height": 500,
"style": "cell",
"data": [
{
"name": "source_0",
"url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv",
"format": {
"type": "csv",
"parse": {
"precipitation": "number",
"temp_min": "number",
"temp_max": "number"
},
"delimiter": ","
},
"transform": [
{
"type": "filter",
"expr": "datum[\"precipitation\"] !== null && !isNaN(datum[\"precipitation\"]) && datum[\"temp_min\"] !== null && !isNaN(datum[\"temp_min\"]) && datum[\"temp_max\"] !== null && !isNaN(datum[\"temp_max\"])"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "symbol",
"style": ["point"],
"from": {"data": "source_0"},
"encode": {
"update": {
"opacity": {"value": 0.7},
"fill": {
"signal": "scale('size', datum.precipitation) < 1 ? scale('color', datum.weather) : 'transparent'"
},
"stroke": {"scale": "color", "field": "weather"},
"x": {"scale": "x", "field": "temp_min"},
"y": {"scale": "y", "field": "temp_max"},
"size": {
"signal": "scale('size', datum.precipitation) < 1 ? 1 : scale('size', datum.precipitation)"
}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {"data": "source_0", "field": "temp_min"},
"range": [0, {"signal": "width"}],
"nice": true,
"zero": true
},
{
"name": "y",
"type": "linear",
"domain": {"data": "source_0", "field": "temp_max"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "source_0", "field": "weather", "sort": true},
"range": "category"
},
{
"name": "size",
"type": "linear",
"domain": {"data": "source_0", "field": "precipitation"},
"range": [0.1, 361],
"nice": false,
"zero": true
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"title": "temp_min",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 1
},
{
"scale": "x",
"orient": "bottom",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"gridScale": "y",
"domain": false,
"labels": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"title": "temp_max",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 1
},
{
"scale": "y",
"orient": "left",
"grid": true,
"tickCount": {"signal": "ceil(height/40)"},
"gridScale": "x",
"domain": false,
"labels": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
}
],
"legends": [
{
"stroke": "color",
"title": "weather",
"encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}}
},
{
"size": "size",
"title": "precipitation",
"encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}}
}
],
"config": {"axisY": {"minExtent": 30}}
} |
I think the workaround to set domain to I think it is actually better to set both domain and range with minimum value and clamp the scale
By setting range to be domain multiply by 8, then we still preserve the ratio, while having minimum size = 1. Note that
Full spec:
|
There can be a similar issue for bars with very small non-zero value -- we should consider if we want to apply the same trick #255. |
Actually bump scale like #255 could be slightly different in the sense that users may want to keep zero 0px but have min size for non-zero length. |
Actually thinking more, it's probably more maintainable if we just modify the default scale range to include small non zero values. (It'll be slightly less precise than condition encoding, but it will add way less complexity to the system.) The relevant code is here. https://github.com/vega/vega-lite/blob/next/src/compile/scale/range.ts#L453 The question is what should be the property names for these min size for zero? Note that we already have So we're adding its counter part to handle min range when zero is true. Design Decision 1: What's the name for the new config?a) (Same pattern for I like c) for brevity. Design Decision 2: Do we rename existing config for when
|
So, first off it's important to know that size encoding is actually not perceptually linear. This means that people cannot compare ratios of sizes. Therefore, I think it's totally okay to have symbol size start at some value. How about we do 1b) and the new config ( |
Thinking more, let's not overcomplicate things. I think let's use existing |
If it becomes a problem we can always split the config later. |
…nts will be ever hidden (#9347) Also adjust the default `defaultMinSize` to be `4`, so the smallest point is not too big. fix #3488 --------- Co-authored-by: GitHub Actions Bot <[email protected]>
In Vega-Lite 2.x, if you encode a quantity with size and that quantity has elements with value zero, those points do not appear on the plot with the default scale:
In Vega-Lite 1.x, this was not the case; here's the result of the above spec with VL1:
In VL2, you can fix this by setting the size scale domain to start at a negative number:
I think that silently hiding valid data should be considered a bug, and that the domain should default to something like what is in the final panel.
The text was updated successfully, but these errors were encountered: