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 @@ -0.000.020.040.060.08density65062colours used567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162test_choropleth1015202530354045505560pct_estimate (binned) \ No newline at end of file +0.000.020.040.060.08density65062colours used102030405060test_choropleth1015202530354045505560pct_estimate (binned) \ 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 @@ -0.000.020.040.060.08density065062colours used0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100test_choropleth_extent5101520253035404550556065707580859095pct_estimate (binned) \ No newline at end of file +0.000.020.040.060.08density065062colours used0102030405060708090100test_choropleth_extent5101520253035404550556065707580859095pct_estimate (binned) \ 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 @@ -0.00.10.2density050218300,000,000colours used05,000,00010,000,00015,000,00020,000,00025,000,00030,000,00035,000,00040,000,00045,000,00050,000,00055,000,00060,000,00065,000,00070,000,00075,000,00080,000,00085,000,00090,000,00095,000,000100,000,000105,000,000110,000,000115,000,000120,000,000125,000,000130,000,000135,000,000140,000,000145,000,000150,000,000155,000,000160,000,000165,000,000170,000,000175,000,000180,000,000185,000,000190,000,000195,000,000200,000,000205,000,000210,000,000215,000,000220,000,000225,000,000230,000,000235,000,000240,000,000245,000,000250,000,000255,000,000260,000,000265,000,000270,000,000275,000,000280,000,000285,000,000290,000,000295,000,000300,000,000012345678910IMDB_Rating05,000,00010,000,00015,000,00020,000,00025,000,00030,000,00035,000,00040,000,00045,000,00050,000,00055,000,00060,000,00065,000,00070,000,00075,000,00080,000,00085,000,00090,000,00095,000,000100,000,000105,000,000110,000,000115,000,000120,000,000125,000,000130,000,000135,000,000140,000,000145,000,000150,000,000155,000,000160,000,000165,000,000170,000,000175,000,000180,000,000185,000,000190,000,000195,000,000200,000,000205,000,000210,000,000215,000,000220,000,000225,000,000230,000,000235,000,000240,000,000245,000,000250,000,000255,000,000260,000,000265,000,000270,000,000275,000,000280,000,000285,000,000290,000,000295,000,000300,000,000Rotten_Tomatoes_Ratingtest_scatterplot20,000,00040,000,00060,000,00080,000,000100,000,000120,000,000140,000,000160,000,000180,000,000200,000,000220,000,000240,000,000260,000,000280,000,000Production_Budget (binned) \ No newline at end of file +0.00.10.2density050218300,000,000colours used050,000,000100,000,000150,000,000200,000,000250,000,000300,000,000012345678910IMDB_Rating0102030405060708090100Rotten_Tomatoes_Ratingtest_scatterplot20,000,00040,000,00060,000,00080,000,000100,000,000120,000,000140,000,000160,000,000180,000,000200,000,000220,000,000240,000,000260,000,000280,000,000Production_Budget (binned) \ 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 @@ -0.00.10.2density050218300,000,000colours used05,000,00010,000,00015,000,00020,000,00025,000,00030,000,00035,000,00040,000,00045,000,00050,000,00055,000,00060,000,00065,000,00070,000,00075,000,00080,000,00085,000,00090,000,00095,000,000100,000,000105,000,000110,000,000115,000,000120,000,000125,000,000130,000,000135,000,000140,000,000145,000,000150,000,000155,000,000160,000,000165,000,000170,000,000175,000,000180,000,000185,000,000190,000,000195,000,000200,000,000205,000,000210,000,000215,000,000220,000,000225,000,000230,000,000235,000,000240,000,000245,000,000250,000,000255,000,000260,000,000265,000,000270,000,000275,000,000280,000,000285,000,000290,000,000295,000,000300,000,000012345678910IMDB_Rating05,000,00010,000,00015,000,00020,000,00025,000,00030,000,00035,000,00040,000,00045,000,00050,000,00055,000,00060,000,00065,000,00070,000,00075,000,00080,000,00085,000,00090,000,00095,000,000100,000,000105,000,000110,000,000115,000,000120,000,000125,000,000130,000,000135,000,000140,000,000145,000,000150,000,000155,000,000160,000,000165,000,000170,000,000175,000,000180,000,000185,000,000190,000,000195,000,000200,000,000205,000,000210,000,000215,000,000220,000,000225,000,000230,000,000235,000,000240,000,000245,000,000250,000,000255,000,000260,000,000265,000,000270,000,000275,000,000280,000,000285,000,000290,000,000295,000,000300,000,000Rotten_Tomatoes_Ratingtest_scatterplot_bin_False100,000,000200,000,000300,000,000Production_Budget \ No newline at end of file +0.00.10.2density050218300,000,000colours used0012345678910IMDB_Rating0102030405060708090100Rotten_Tomatoes_Ratingtest_scatterplot_bin_False100,000,000200,000,000300,000,000Production_Budget \ 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)