Created
May 10, 2024 10:15
-
-
Save vnegi10/fb2c8b7033133ea8b08b7444d827e7df 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 plotValueChange(breakdown, date, {width} = {}) { | |
const bisector = d3.bisector((i) => breakdown[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 total 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(breakdown, 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