Created
May 10, 2024 10:14
-
-
Save vnegi10/4f0d90d3431fc33e413219dfc11fab1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function plotBreakdownChange(stackArray, date, {width} = {}) { | |
const bisector = d3.bisector((i) => stackArray[i].time); | |
const basis = (I, Y) => Y[I[bisector.center(I, date)]]; | |
return Plot.plot({ | |
style: "overflow: visible;", | |
y: { | |
//type: "log", | |
grid: true, | |
label: "Change in individual value (%)", | |
tickFormat: ((f) => (x) => f((x - 1) * 100))(d3.format("+d")), | |
//domain: [0, 100] | |
}, | |
width, | |
//title: "", | |
x: {label: "Time [days]"}, | |
color: {legend: true}, | |
marks: [ | |
Plot.ruleY([1]), | |
Plot.ruleX([date]), | |
Plot.lineY(stackArray, Plot.normalizeY(basis, { | |
x: "time", | |
y: "value", | |
interval: "day", | |
stroke: "name", | |
//marker: true | |
//tip: true | |
})), | |
] | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment