diff --git a/tests/expected_meta_hist_choropleth.json b/tests/expected_meta_hist_choropleth.json
index a163fbc..1d610f7 100644
--- a/tests/expected_meta_hist_choropleth.json
+++ b/tests/expected_meta_hist_choropleth.json
@@ -363743,6 +363743,10 @@
"maxbins": 100
},
"field": "pct_estimate",
+ "scale": {
+ "nice": true,
+ "zero": false
+ },
"title": "",
"type": "quantitative"
}
@@ -363801,6 +363805,7 @@
},
"field": "y",
"scale": {
+ "nice": true,
"zero": false
},
"title": "",
@@ -363861,10 +363866,5 @@
"title": "test_choropleth",
"width": 500
}
- ],
- "resolve": {
- "scale": {
- "y": "shared"
- }
- }
+ ]
}
\ No newline at end of file
diff --git a/tests/expected_meta_hist_choropleth.svg b/tests/expected_meta_hist_choropleth.svg
index 2bbd203..a5f88af 100644
--- a/tests/expected_meta_hist_choropleth.svg
+++ b/tests/expected_meta_hist_choropleth.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/tests/expected_meta_hist_choropleth_extent.json b/tests/expected_meta_hist_choropleth_extent.json
index 65e8550..6f2d162 100644
--- a/tests/expected_meta_hist_choropleth_extent.json
+++ b/tests/expected_meta_hist_choropleth_extent.json
@@ -363747,6 +363747,13 @@
"maxbins": 100
},
"field": "pct_estimate",
+ "scale": {
+ "domain": [
+ 0,
+ 100
+ ],
+ "nice": true
+ },
"title": "",
"type": "quantitative"
}
@@ -363808,6 +363815,13 @@
"orient": "right"
},
"field": "y",
+ "scale": {
+ "domain": [
+ 0,
+ 100
+ ],
+ "nice": true
+ },
"title": "",
"type": "quantitative"
},
@@ -363874,10 +363888,5 @@
"title": "test_choropleth_extent",
"width": 500
}
- ],
- "resolve": {
- "scale": {
- "y": "shared"
- }
- }
+ ]
}
\ No newline at end of file
diff --git a/tests/expected_meta_hist_choropleth_extent.svg b/tests/expected_meta_hist_choropleth_extent.svg
index 6ecd985..0cec633 100644
--- a/tests/expected_meta_hist_choropleth_extent.svg
+++ b/tests/expected_meta_hist_choropleth_extent.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/tests/expected_meta_hist_scatterplot.json b/tests/expected_meta_hist_scatterplot.json
index 07b9b18..9491c0a 100644
--- a/tests/expected_meta_hist_scatterplot.json
+++ b/tests/expected_meta_hist_scatterplot.json
@@ -57721,6 +57721,7 @@
},
"field": "y",
"scale": {
+ "nice": true,
"zero": false
},
"title": "",
@@ -57774,10 +57775,5 @@
"mark": "circle",
"title": "test_scatterplot"
}
- ],
- "resolve": {
- "scale": {
- "y": "shared"
- }
- }
+ ]
}
\ No newline at end of file
diff --git a/tests/expected_meta_hist_scatterplot.svg b/tests/expected_meta_hist_scatterplot.svg
index 554d4b6..461649d 100644
--- a/tests/expected_meta_hist_scatterplot.svg
+++ b/tests/expected_meta_hist_scatterplot.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/tests/expected_meta_hist_scatterplot_bin_False.json b/tests/expected_meta_hist_scatterplot_bin_False.json
index 1cd319e..0e4afa8 100644
--- a/tests/expected_meta_hist_scatterplot_bin_False.json
+++ b/tests/expected_meta_hist_scatterplot_bin_False.json
@@ -57715,9 +57715,6 @@
"orient": "right"
},
"field": "y",
- "scale": {
- "zero": false
- },
"title": "",
"type": "quantitative"
},
@@ -57754,10 +57751,5 @@
"mark": "circle",
"title": "test_scatterplot_bin_False"
}
- ],
- "resolve": {
- "scale": {
- "y": "shared"
- }
- }
+ ]
}
\ No newline at end of file
diff --git a/tests/expected_meta_hist_scatterplot_bin_False.svg b/tests/expected_meta_hist_scatterplot_bin_False.svg
index 652e873..21f4ace 100644
--- a/tests/expected_meta_hist_scatterplot_bin_False.svg
+++ b/tests/expected_meta_hist_scatterplot_bin_False.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/ways_py/ways.py b/ways_py/ways.py
index ffa1261..e8d9796 100644
--- a/ways_py/ways.py
+++ b/ways_py/ways.py
@@ -24,9 +24,12 @@ def field(src: alt.Chart) -> str:
@staticmethod
def density_chart(src: alt.Chart) -> alt.Chart:
if src.encoding.color.bin and is_defined(src.encoding.color.bin.extent):
- bin = alt.Bin(maxbins=100, extent=src.encoding.color.bin.extent)
+ extent = src.encoding.color.bin.extent
+ bin = alt.Bin(maxbins=100, extent=extent)
+ y_scale = alt.Scale(domain=extent, nice=True)
else:
bin = alt.Bin(maxbins=100)
+ y_scale = alt.Scale(zero=False, nice=True)
ys = src.data[Ways.field(src)] # assume src.data array-like in an appropriate way
y_min, y_max = min(ys), max(ys)
# tickCount/tickMinStep Axis properties are ignored (perhaps because we specify bins), so hard code
@@ -35,6 +38,7 @@ def density_chart(src: alt.Chart) -> alt.Chart:
bin=bin,
axis=alt.Axis(orient='left', grid=False, values=sorted([0, 50] + [y_min, y_max])),
title="",
+ scale=y_scale
)
x_axis = alt.X(
'sum(proportion):Q',
@@ -53,13 +57,18 @@ def density_chart(src: alt.Chart) -> alt.Chart:
def used_colours(src: alt.Chart) -> alt.Chart:
y_axis = alt.Axis(orient='right', grid=False)
x_axis = alt.Axis(labels=False, tickSize=0, grid=False, titleAngle=270, titleAlign='right')
+ if src.encoding.color.bin and is_defined(src.encoding.color.bin.extent):
+ extent = src.encoding.color.bin.extent
+ y_scale = alt.Scale(domain=extent, nice=True)
+ else:
+ y_scale = alt.Scale(zero=False, nice=True)
if src.encoding.color.bin:
chart = alt.Chart(src.data) \
.mark_rect() \
.transform_bin(as_=['y', 'y2'], bin=src.encoding.color.bin, field=Ways.field(src)) \
.transform_calculate(x='5') \
.encode(
- y=alt.Y('y:Q', axis=y_axis, title=""),
+ y=alt.Y('y:Q', axis=y_axis, title="", scale=y_scale),
y2='y2:Q',
x=alt.X('x:Q', sort='descending', axis=x_axis, title="colours used")
) # noqa: E123
@@ -92,7 +101,7 @@ def altair_meta_hist(src: alt.Chart) -> alt.Chart:
if not is_defined(src.encoding.color.bin):
raise Exception("Can only apply decorator to chart with color.bin defined.")
- meta_chart: alt.Chart = (Ways.density_chart(src) | Ways.used_colours(src)).resolve_scale(y='shared')
+ meta_chart: alt.Chart = (Ways.density_chart(src) | Ways.used_colours(src))
return (meta_chart | src) \
.configure_view(strokeWidth=0) \
.configure_concat(spacing=5)