Skip to content

Commit

Permalink
line & area sort by z
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 9, 2021
1 parent 0edb9b7 commit 54e79fc
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 138 deletions.
15 changes: 0 additions & 15 deletions src/group.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/marks/area.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {group, sort} from "d3-array";
import {create} from "d3-selection";
import {area as shapeArea} from "d3-shape";
import {Curve} from "../curve.js";
import {defined} from "../defined.js";
import {group} from "../group.js";
import {Mark, indexOf, maybeColor, maybeZero, maybeSort, titleGroup} from "../mark.js";
import {Mark, indexOf, maybeColor, maybeZero, maybeSort, first, second, titleGroup} from "../mark.js";
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";

export class Area extends Mark {
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Area extends Mark {
.call(applyIndirectStyles, this)
.call(applyTransform, x, y)
.call(g => g.selectAll()
.data(Z ? group(I, Z) : [I])
.data(Z ? sort(group(I, i => Z[i]), first).map(second) : [I])
.join("path")
.call(applyDirectStyles, this)
.attr("fill", F && (([i]) => color(F[i])))
Expand Down
4 changes: 2 additions & 2 deletions src/marks/line.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {group, sort} from "d3-array";
import {create} from "d3-selection";
import {line as shapeLine} from "d3-shape";
import {Curve} from "../curve.js";
import {defined} from "../defined.js";
import {group} from "../group.js";
import {Mark, indexOf, identity, first, second, maybeColor, maybeSort, titleGroup} from "../mark.js";
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";

Expand Down Expand Up @@ -53,7 +53,7 @@ export class Line extends Mark {
.call(applyIndirectStyles, this)
.call(applyTransform, x, y, 0.5, 0.5)
.call(g => g.selectAll()
.data(Z ? group(I, Z) : [I])
.data(Z ? sort(group(I, i => Z[i]), first).map(second) : [I])
.join("path")
.call(applyDirectStyles, this)
.attr("fill", F && (([i]) => color(F[i])))
Expand Down
114 changes: 57 additions & 57 deletions test/output/carsParcoords.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions test/output/industryUnemployment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions test/output/industryUnemploymentShare.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions test/output/industryUnemploymentStream.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions test/output/metroUnemploymentHighlight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/policeDeaths.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {default as letterFrequencyLollipop} from "./letter-frequency-lollipop.js
export {default as metroInequalityChange} from "./metro-inequality-change.js";
export {default as metroInequality} from "./metro-inequality.js";
export {default as metroUnemploymentIndex} from "./metro-unemployment-index.js";
export {default as metroUnemploymentHighlight} from "./metro-unemployment-highlight.js";
export {default as metroUnemploymentMoving} from "./metro-unemployment-moving.js";
export {default as metroUnemploymentRidgeline} from "./metro-unemployment-ridgeline.js";
export {default as metroUnemployment} from "./metro-unemployment.js";
Expand Down
26 changes: 26 additions & 0 deletions test/plots/metro-unemployment-highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

export default async function() {
const bls = await d3.csv("data/bls-metro-unemployment.csv", d3.autoType);
const highlight = d => /, MI /.test(d.division);
return Plot.plot({
y: {
grid: true,
label: "↑ Unemployment (%)"
},
color: {
domain: [false, true],
range: ["#ccc", "red"]
},
marks: [
Plot.ruleY([0]),
Plot.line(bls, {
x: "date",
y: "unemployment",
z: d => `${highlight(d)}/${d.division}`,
stroke: highlight
})
]
});
}

0 comments on commit 54e79fc

Please sign in to comment.