Skip to content

Commit

Permalink
Auto mark: zero baseline default for rules (observablehq#1341)
Browse files Browse the repository at this point in the history
* Auto mark: zero baseline default for rules

* fix existing tests, commit new test output
  • Loading branch information
tophtucker authored and chaichontat committed Jan 14, 2024
1 parent e100f11 commit e0a87ba
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/marks/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
if (yZero === undefined) yZero = transform !== binY && (mark === barY || mark === areaY || mark === rectY);
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
Expand Down
124 changes: 124 additions & 0 deletions test/output/autoRuleZero.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/plots/autoplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>("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<any>("data/aapl.csv", d3.autoType);
return Plot.auto(aapl, {x: "Date", y: "Close", color: "Close"}).plot();
Expand Down

0 comments on commit e0a87ba

Please sign in to comment.