Skip to content

difference as a composite mark #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
difference tip
  • Loading branch information
Fil committed Oct 19, 2023
commit a93cc563bf5cc45818a81e57770d3c79bc76f800
20 changes: 18 additions & 2 deletions src/marks/difference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {area as shapeArea} from "d3";
import {create} from "../context.js";
import {identity, indexOf} from "../options.js";
import {identity, indexOf, column, valueof} from "../options.js";
import {basic as transform} from "../transforms/basic.js";
import {groupIndex, getClipId} from "../style.js";
import {marks} from "../mark.js";
import {area} from "./area.js";
Expand Down Expand Up @@ -114,6 +115,21 @@ export function differenceY(
}),

// reference line
lineY(data, {x: x1, y: y1, tip, channels: {...channels, y2}, ...options})
lineY(data, maybeDifferenceChannelsY({x: x1, y: y1, y2, tip, ...options}))
);
}

// Adds the y2 and difference channels for the default tip mark.
function maybeDifferenceChannelsY(options) {
if (!options.tip) return options;
const [Y1, setY1] = column(options.y);
const [Y2, setY2] = column(options.y2);
const [D, setD] = column();
options = transform(options, function (data, facets) {
const Y1 = setY1(valueof(data, options.y));
const Y2 = setY2(valueof(data, options.y2));
setD(Float64Array.from(Y1, (y1, i) => y1 - Y2[i]));
return {data, facets};
});
return {channels: {x: true, y: true, y2: Y2, difference: D}, ...options, y: Y1};
}