From c78e7cc48360140609c91f7378a62f7c191eb82d Mon Sep 17 00:00:00 2001 From: Toph Tucker Date: Wed, 15 Mar 2023 10:30:32 -0400 Subject: [PATCH 1/2] Auto mark: zero baseline default for rules --- src/marks/auto.js | 4 ++-- test/plots/autoplot.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/marks/auto.js b/src/marks/auto.js index 677556bd06..513da17611 100644 --- a/src/marks/auto.js +++ b/src/marks/auto.js @@ -216,8 +216,8 @@ export function auto(data, options) { // If zero-ness is not specified, default based on whether the resolved mark // type will include a zero baseline. TODO Move this to autoSpec. - if (xZero === undefined) xZero = transform !== binX && (mark === barX || mark === areaX || mark === rectX); - if (yZero === undefined) yZero = transform !== binY && (mark === barY || mark === areaY || mark === rectY); + if (xZero === undefined) xZero = transform !== binX && (mark === barX || mark === areaX || mark === rectX || mark === ruleY); + if (yZero === undefined) yZero = transform !== binY && (mark === barY || mark === areaY || mark === rectY || mark === ruleX); // In the case of filled marks (particularly bars and areas) the frame and // rules should come after the mark; in the case of stroked marks diff --git a/test/plots/autoplot.ts b/test/plots/autoplot.ts index b6badf0426..85d8195ae6 100644 --- a/test/plots/autoplot.ts +++ b/test/plots/autoplot.ts @@ -162,6 +162,11 @@ export async function autoRectColorReducer() { return Plot.auto(penguins, {x: "culmen_length_mm", color: {value: "island", reduce: "mode"}}).plot(); } +export async function autoRuleZero() { + const athletes = await d3.csv("data/athletes.csv", d3.autoType); + return Plot.auto(athletes, {x: "date_of_birth", y: {value: "height", reduce: "mean"}, mark: "rule"}).plot(); +} + export async function autoLineColor() { const aapl = await d3.csv("data/aapl.csv", d3.autoType); return Plot.auto(aapl, {x: "Date", y: "Close", color: "Close"}).plot(); From c37ed5dbd1c3d46442b057a6dbcd8706c7e11a58 Mon Sep 17 00:00:00 2001 From: Toph Tucker Date: Wed, 15 Mar 2023 10:45:58 -0400 Subject: [PATCH 2/2] fix existing tests, commit new test output --- src/marks/auto.js | 6 +- test/output/autoRuleZero.svg | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 test/output/autoRuleZero.svg diff --git a/src/marks/auto.js b/src/marks/auto.js index 513da17611..062bd43f46 100644 --- a/src/marks/auto.js +++ b/src/marks/auto.js @@ -216,8 +216,10 @@ export function auto(data, options) { // If zero-ness is not specified, default based on whether the resolved mark // type will include a zero baseline. TODO Move this to autoSpec. - if (xZero === undefined) xZero = transform !== binX && (mark === barX || mark === areaX || mark === rectX || mark === ruleY); - if (yZero === undefined) yZero = transform !== binY && (mark === barY || mark === areaY || mark === rectY || mark === ruleX); + if (xZero === undefined) + xZero = X && transform !== binX && (mark === barX || mark === areaX || mark === rectX || mark === ruleY); + if (yZero === undefined) + yZero = Y && transform !== binY && (mark === barY || mark === areaY || mark === rectY || mark === ruleX); // In the case of filled marks (particularly bars and areas) the frame and // rules should come after the mark; in the case of stroked marks diff --git a/test/output/autoRuleZero.svg b/test/output/autoRuleZero.svg new file mode 100644 index 0000000000..35f7f63579 --- /dev/null +++ b/test/output/autoRuleZero.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + 0.0 + 0.2 + 0.4 + 0.6 + 0.8 + 1.0 + 1.2 + 1.4 + 1.6 + 1.8 + + + ↑ height + + + + + + + + + + + + + + + 1955 + 1960 + 1965 + 1970 + 1975 + 1980 + 1985 + 1990 + 1995 + 2000 + + + date_of_birth → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file