From bc8f189862ac3abd599c881392b92a8f4aeb7f9b Mon Sep 17 00:00:00 2001 From: Toph Tucker Date: Mon, 3 Apr 2023 22:11:22 -0400 Subject: [PATCH 1/3] Sketch: adding override-only mark types to auto --- src/marks/auto.d.ts | 2 +- src/marks/auto.js | 10 ++++++++++ test/plots/autoplot.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/marks/auto.d.ts b/src/marks/auto.d.ts index 760cfc6d21..c6d5aa4ea5 100644 --- a/src/marks/auto.d.ts +++ b/src/marks/auto.d.ts @@ -92,7 +92,7 @@ export interface AutoOptions { * should usually suffice, and setting an explicit mark type may lead to a * nonsensical plot (especially if you change other options). */ - mark?: "area" | "bar" | "dot" | "line" | "rule"; + mark?: "area" | "bar" | "dot" | "line" | "rule" | "box" | "voronoi"; } /** diff --git a/src/marks/auto.js b/src/marks/auto.js index d2556138b9..a42fa8d8e8 100644 --- a/src/marks/auto.js +++ b/src/marks/auto.js @@ -11,6 +11,8 @@ import {frame} from "./frame.js"; import {line, lineX, lineY} from "./line.js"; import {rectX, rectY} from "./rect.js"; import {ruleX, ruleY} from "./rule.js"; +import {boxX, boxY} from "./box.js"; +import {voronoi} from "./delaunay.js"; export function autoSpec(data, options) { const {x, y, fx, fy, color, size, mark} = autoImpl(data, options); @@ -126,6 +128,14 @@ function autoImpl(data, options) { : rectY; colorMode = "fill"; break; + case "box": + markImpl = isOrdinalReduced(xReduce, X) ? boxY : boxX; + colorMode = "fill"; + break; + case "voronoi": + markImpl = voronoi; + colorMode = "stroke"; + break; default: throw new Error(`invalid mark: ${mark}`); } diff --git a/test/plots/autoplot.ts b/test/plots/autoplot.ts index a5a63c169c..5c6d4666ff 100644 --- a/test/plots/autoplot.ts +++ b/test/plots/autoplot.ts @@ -1,6 +1,16 @@ import * as Plot from "@observablehq/plot"; import * as d3 from "d3"; +export async function autoBox() { + const athletes = await d3.csv("data/athletes.csv", d3.autoType); + return Plot.auto(athletes, {x: "weight", y: "sex", mark: "box", color: "sex"}).plot(); +} + +export async function autoVoronoi() { + const penguins = await d3.csv("data/penguins.csv", d3.autoType); + return Plot.auto(penguins, {x: "culmen_depth_mm", y: "culmen_length_mm", color: "species", mark: "voronoi"}).plot(); +} + // Tanner's bug https://github.com/observablehq/plot/issues/1365 export async function autoLineZero() { const industries = await d3.csv("data/bls-industry-unemployment.csv", d3.autoType); From 151a3782a6b7a2c5be604fefe4fbb77019b90863 Mon Sep 17 00:00:00 2001 From: Toph Tucker Date: Mon, 3 Apr 2023 22:12:56 -0400 Subject: [PATCH 2/3] tests --- test/output/autoBox.svg | 286 +++++++++++++++++++++++++ test/output/autoVoronoi.svg | 416 ++++++++++++++++++++++++++++++++++++ 2 files changed, 702 insertions(+) create mode 100644 test/output/autoBox.svg create mode 100644 test/output/autoVoronoi.svg diff --git a/test/output/autoBox.svg b/test/output/autoBox.svg new file mode 100644 index 0000000000..e3f3cd0cc7 --- /dev/null +++ b/test/output/autoBox.svg @@ -0,0 +1,286 @@ + + + + + + + + female + male + + + sex + + + + + + + + + + + + 40 + 60 + 80 + 100 + 120 + 140 + 160 + + + weight → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/output/autoVoronoi.svg b/test/output/autoVoronoi.svg new file mode 100644 index 0000000000..2e7455107c --- /dev/null +++ b/test/output/autoVoronoi.svg @@ -0,0 +1,416 @@ + + + + + + + + + + + + + + + + + + + 34 + 36 + 38 + 40 + 42 + 44 + 46 + 48 + 50 + 52 + 54 + 56 + 58 + + + ↑ culmen_length_mm + + + + + + + + + + + + + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + + + culmen_depth_mm → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9f846319df04e18f570ae1b93993017f7e7510bb Mon Sep 17 00:00:00 2001 From: Toph Tucker Date: Thu, 24 Aug 2023 16:31:29 -0400 Subject: [PATCH 3/3] box only, forget voronoi --- src/marks/auto.js | 9 +++------ test/plots/autoplot.ts | 5 ----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/marks/auto.js b/src/marks/auto.js index 3d9320e551..63a7ecc4d2 100644 --- a/src/marks/auto.js +++ b/src/marks/auto.js @@ -12,7 +12,6 @@ import {line, lineX, lineY} from "./line.js"; import {rect, rectX, rectY} from "./rect.js"; import {ruleX, ruleY} from "./rule.js"; import {boxX, boxY} from "./box.js"; -import {voronoi} from "./delaunay.js"; export function autoSpec(data, options) { options = normalizeOptions(options); @@ -144,13 +143,9 @@ export function autoSpec(data, options) { colorMode = "fill"; break; case "box": - markImpl = isOrdinalReduced(xReduce, X) ? boxY : boxX; + markImpl = X && isOrdinal(X) ? boxY : boxX; colorMode = "fill"; break; - case "voronoi": - markImpl = voronoi; - colorMode = "stroke"; - break; default: throw new Error(`invalid mark: ${mark}`); } @@ -369,6 +364,8 @@ const impls = { rectX, rectY, cell, + boxX, + boxY, bin, binX, binY, diff --git a/test/plots/autoplot.ts b/test/plots/autoplot.ts index 906632e5ad..5711ce35e9 100644 --- a/test/plots/autoplot.ts +++ b/test/plots/autoplot.ts @@ -6,11 +6,6 @@ export async function autoBox() { return Plot.auto(athletes, {x: "weight", y: "sex", mark: "box", color: "sex"}).plot(); } -export async function autoVoronoi() { - const penguins = await d3.csv("data/penguins.csv", d3.autoType); - return Plot.auto(penguins, {x: "culmen_depth_mm", y: "culmen_length_mm", color: "species", mark: "voronoi"}).plot(); -} - // Tanner's bug https://github.com/observablehq/plot/issues/1365 export async function autoLineZero() { const industries = await d3.csv("data/bls-industry-unemployment.csv", d3.autoType);