2024-04-19 09:50:15 -06:00
|
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
import tailwindColors from "@maybe/tailwindcolors"
|
|
|
|
import * as d3 from "d3"
|
|
|
|
|
|
|
|
export default class extends Controller {
|
2024-04-20 12:26:59 -06:00
|
|
|
static values = {
|
|
|
|
series: Object,
|
|
|
|
useLabels: Boolean,
|
|
|
|
useTooltip: Boolean,
|
|
|
|
strokeWidth: { type: Number, default: 2 }
|
|
|
|
}
|
2024-04-19 09:50:15 -06:00
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#_d3MainSvg = null
|
2024-04-20 12:26:59 -06:00
|
|
|
#_d3MainGroup = null
|
2024-04-19 18:30:25 -06:00
|
|
|
#d3Tooltip = null
|
|
|
|
#dataPoints = []
|
|
|
|
#d3InitialContainerWidth = 0
|
|
|
|
#d3InitialContainerHeight = 0
|
2024-04-19 09:50:15 -06:00
|
|
|
|
|
|
|
connect() {
|
|
|
|
this.#install()
|
|
|
|
document.addEventListener("turbo:load", this.#reinstall)
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnect() {
|
2024-04-20 12:28:10 -06:00
|
|
|
this.#teardown()
|
2024-04-19 09:50:15 -06:00
|
|
|
document.removeEventListener("turbo:load", this.#reinstall)
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-19 09:50:15 -06:00
|
|
|
#reinstall = () => {
|
|
|
|
this.#teardown()
|
|
|
|
this.#install()
|
|
|
|
}
|
|
|
|
|
|
|
|
#teardown() {
|
2024-04-19 18:30:25 -06:00
|
|
|
this.#_d3MainSvg = null
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#_d3MainGroup = null
|
2024-04-19 18:30:25 -06:00
|
|
|
this.#d3Tooltip = null
|
|
|
|
this.#dataPoints = []
|
|
|
|
|
2024-04-19 09:50:15 -06:00
|
|
|
this.#d3Container.selectAll("*").remove()
|
|
|
|
}
|
|
|
|
|
|
|
|
#install() {
|
|
|
|
this.#normalizeDataPoints()
|
2024-04-19 18:17:54 -06:00
|
|
|
this.#rememberInitialContainerSize()
|
2024-04-19 09:50:15 -06:00
|
|
|
this.#draw()
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-19 09:50:15 -06:00
|
|
|
#normalizeDataPoints() {
|
2024-04-19 10:02:37 -06:00
|
|
|
this.#dataPoints = (this.seriesValue.values || []).map((d) => ({
|
2024-04-19 17:37:48 -06:00
|
|
|
...d,
|
2024-04-19 09:50:15 -06:00
|
|
|
date: new Date(d.date),
|
|
|
|
value: d.value.amount ? +d.value.amount : +d.value,
|
2024-04-19 19:27:24 -06:00
|
|
|
currency: d.value.currency
|
2024-04-19 09:50:15 -06:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
#rememberInitialContainerSize() {
|
|
|
|
this.#d3InitialContainerWidth = this.#d3Container.node().clientWidth
|
|
|
|
this.#d3InitialContainerHeight = this.#d3Container.node().clientHeight
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-19 09:50:15 -06:00
|
|
|
#draw() {
|
2024-04-19 19:05:27 -06:00
|
|
|
if (this.#dataPoints.length < 2) {
|
2024-04-19 10:02:37 -06:00
|
|
|
this.#drawEmpty()
|
|
|
|
} else {
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#drawChart()
|
2024-04-19 10:02:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-19 10:02:37 -06:00
|
|
|
#drawEmpty() {
|
2024-04-19 18:30:25 -06:00
|
|
|
this.#d3MainSvg.selectAll(".tick").remove()
|
|
|
|
this.#d3MainSvg.selectAll(".domain").remove()
|
2024-04-19 10:02:37 -06:00
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
this.#drawDashedLineEmptyState()
|
|
|
|
this.#drawCenteredCircleEmptyState()
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#drawDashedLineEmptyState() {
|
|
|
|
this.#d3MainSvg
|
2024-04-19 10:02:37 -06:00
|
|
|
.append("line")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("x1", this.#d3InitialContainerWidth / 2)
|
2024-04-19 10:02:37 -06:00
|
|
|
.attr("y1", 0)
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("x2", this.#d3InitialContainerWidth / 2)
|
2024-04-19 18:43:21 -06:00
|
|
|
.attr("y2", this.#d3InitialContainerHeight)
|
2024-04-19 10:02:37 -06:00
|
|
|
.attr("stroke", tailwindColors.gray[300])
|
|
|
|
.attr("stroke-dasharray", "4, 4")
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
2024-04-19 10:02:37 -06:00
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#drawCenteredCircleEmptyState() {
|
|
|
|
this.#d3MainSvg
|
2024-04-19 10:02:37 -06:00
|
|
|
.append("circle")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("cx", this.#d3InitialContainerWidth / 2)
|
2024-04-19 18:43:21 -06:00
|
|
|
.attr("cy", this.#d3InitialContainerHeight / 2)
|
2024-04-19 10:02:37 -06:00
|
|
|
.attr("r", 4)
|
|
|
|
.style("fill", tailwindColors.gray[400])
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
2024-04-20 12:26:59 -06:00
|
|
|
#drawChart() {
|
2024-04-19 18:30:25 -06:00
|
|
|
this.#drawTrendline()
|
2024-04-20 12:26:59 -06:00
|
|
|
|
|
|
|
if (this.useLabelsValue) {
|
|
|
|
this.#drawXAxisLabels()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.useTooltipValue) {
|
|
|
|
this.#drawTooltip()
|
|
|
|
this.#trackMouseForShowingTooltip()
|
|
|
|
}
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
2024-04-19 17:37:48 -06:00
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
#drawXAxisLabels() {
|
|
|
|
// Add ticks
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup
|
|
|
|
.append("g")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("transform", `translate(0,${this.#d3ContainerHeight})`)
|
|
|
|
.call(
|
|
|
|
d3
|
|
|
|
.axisBottom(this.#d3XScale)
|
|
|
|
.tickValues([ this.#dataPoints[0].date, this.#dataPoints[this.#dataPoints.length - 1].date ])
|
|
|
|
.tickSize(0)
|
|
|
|
.tickFormat(d3.timeFormat("%b %Y"))
|
|
|
|
)
|
|
|
|
.select(".domain")
|
|
|
|
.remove()
|
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
// Style ticks
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup.selectAll(".tick text")
|
2024-04-19 17:37:48 -06:00
|
|
|
.style("fill", tailwindColors.gray[500])
|
|
|
|
.style("font-size", "12px")
|
|
|
|
.style("font-weight", "500")
|
|
|
|
.attr("text-anchor", "middle")
|
|
|
|
.attr("dx", (_d, i) => {
|
|
|
|
// We know we only have 2 values
|
|
|
|
return i === 0 ? "5em" : "-5em"
|
|
|
|
})
|
|
|
|
.attr("dy", "0em")
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
2024-04-19 17:37:48 -06:00
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#drawTrendline() {
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup
|
2024-04-19 18:17:54 -06:00
|
|
|
.append("path")
|
2024-04-19 17:37:48 -06:00
|
|
|
.datum(this.#dataPoints)
|
|
|
|
.attr("fill", "none")
|
2024-04-19 18:17:54 -06:00
|
|
|
.attr("stroke", this.#trendColor)
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("d", this.#d3Line)
|
2024-04-20 12:26:59 -06:00
|
|
|
.attr("stroke-linejoin", "round")
|
|
|
|
.attr("stroke-linecap", "round")
|
|
|
|
.attr("stroke-width", this.strokeWidthValue)
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#drawTooltip() {
|
|
|
|
this.#d3Tooltip = d3
|
2024-04-19 17:37:48 -06:00
|
|
|
.select("#lineChart")
|
|
|
|
.append("div")
|
|
|
|
.style("position", "absolute")
|
|
|
|
.style("padding", "8px")
|
|
|
|
.style("font", "14px Inter, sans-serif")
|
|
|
|
.style("background", tailwindColors.white)
|
|
|
|
.style("border", `1px solid ${tailwindColors["alpha-black"][100]}`)
|
|
|
|
.style("border-radius", "10px")
|
|
|
|
.style("pointer-events", "none")
|
|
|
|
.style("opacity", 0) // Starts as hidden
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
2024-04-19 17:37:48 -06:00
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
#trackMouseForShowingTooltip() {
|
|
|
|
const bisectDate = d3.bisector(d => d.date).left
|
2024-04-19 17:37:48 -06:00
|
|
|
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup.append("rect")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("width", this.#d3ContainerWidth)
|
|
|
|
.attr("height", this.#d3ContainerHeight)
|
|
|
|
.attr("fill", "none")
|
|
|
|
.attr("pointer-events", "all")
|
|
|
|
.on("mousemove", (event) => {
|
2024-04-19 18:17:54 -06:00
|
|
|
const estimatedTooltipWidth = 250
|
2024-04-19 17:37:48 -06:00
|
|
|
const pageWidth = document.body.clientWidth
|
|
|
|
const tooltipX = event.pageX + 10
|
2024-04-19 18:17:54 -06:00
|
|
|
const overflowX = tooltipX + estimatedTooltipWidth - pageWidth
|
|
|
|
const adjustedX = overflowX > 0 ? event.pageX - overflowX - 20 : tooltipX
|
2024-04-19 17:37:48 -06:00
|
|
|
|
|
|
|
const [xPos] = d3.pointer(event)
|
|
|
|
const x0 = bisectDate(this.#dataPoints, this.#d3XScale.invert(xPos), 1)
|
|
|
|
const d0 = this.#dataPoints[x0 - 1]
|
|
|
|
const d1 = this.#dataPoints[x0]
|
|
|
|
const d = xPos - this.#d3XScale(d0.date) > this.#d3XScale(d1.date) - xPos ? d1 : d0
|
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
// Reset
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup.selectAll(".data-point-circle").remove()
|
|
|
|
this.#d3MainGroup.selectAll(".guideline").remove()
|
2024-04-19 17:37:48 -06:00
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
// Big circle
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup
|
2024-04-19 18:32:47 -06:00
|
|
|
.append("circle")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("class", "data-point-circle")
|
|
|
|
.attr("cx", this.#d3XScale(d.date))
|
|
|
|
.attr("cy", this.#d3YScale(d.value))
|
|
|
|
.attr("r", 8)
|
2024-04-19 18:32:47 -06:00
|
|
|
.attr("fill", this.#trendColor)
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("fill-opacity", "0.1")
|
|
|
|
.attr("pointer-events", "none")
|
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
// Small circle
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup
|
2024-04-19 18:32:47 -06:00
|
|
|
.append("circle")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("class", "data-point-circle")
|
|
|
|
.attr("cx", this.#d3XScale(d.date))
|
|
|
|
.attr("cy", this.#d3YScale(d.value))
|
|
|
|
.attr("r", 3)
|
2024-04-19 18:32:47 -06:00
|
|
|
.attr("fill", this.#trendColor)
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("pointer-events", "none")
|
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
// Guideline
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup
|
2024-04-19 18:32:47 -06:00
|
|
|
.append("line")
|
2024-04-19 17:37:48 -06:00
|
|
|
.attr("class", "guideline")
|
|
|
|
.attr("x1", this.#d3XScale(d.date))
|
|
|
|
.attr("y1", 0)
|
|
|
|
.attr("x2", this.#d3XScale(d.date))
|
|
|
|
.attr("y2", this.#d3ContainerHeight)
|
|
|
|
.attr("stroke", tailwindColors.gray[300])
|
|
|
|
.attr("stroke-dasharray", "4, 4")
|
2024-04-19 18:17:54 -06:00
|
|
|
|
|
|
|
// Render tooltip
|
|
|
|
this.#d3Tooltip
|
|
|
|
.html(this.#tooltipTemplate(d))
|
|
|
|
.style("opacity", 1)
|
|
|
|
.style("left", adjustedX + "px")
|
|
|
|
.style("top", event.pageY - 10 + "px")
|
2024-04-19 17:37:48 -06:00
|
|
|
})
|
|
|
|
.on("mouseout", () => {
|
2024-04-20 12:26:59 -06:00
|
|
|
this.#d3MainGroup.selectAll(".guideline").remove()
|
|
|
|
this.#d3MainGroup.selectAll(".data-point-circle").remove()
|
2024-04-19 18:17:54 -06:00
|
|
|
this.#d3Tooltip.style("opacity", 0)
|
2024-04-19 17:37:48 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:17:54 -06:00
|
|
|
|
|
|
|
#tooltipTemplate(data) {
|
2024-04-19 19:27:24 -06:00
|
|
|
if (data.currency) {
|
|
|
|
return(`
|
|
|
|
<div style="margin-bottom: 4px; color: ${tailwindColors.gray[500]};">
|
|
|
|
${d3.timeFormat("%b %d, %Y")(data.date)}
|
|
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
|
|
<svg width="10" height="10">
|
|
|
|
<circle cx="5" cy="5" r="4" stroke="${this.#dataTrendColor(data)}" fill="transparent" stroke-width="1"></circle>
|
|
|
|
</svg>
|
|
|
|
${this.#currencyValue(data)} <span style="color: ${this.#dataTrendColor(data)};">${this.#currencyChange(data)} (${data.trend.percent}%)</span>
|
|
|
|
</div>
|
|
|
|
`)
|
|
|
|
} else {
|
|
|
|
return(`
|
|
|
|
<div style="margin-bottom: 4px; color: ${tailwindColors.gray[500]};">
|
|
|
|
${d3.timeFormat("%b %d, %Y")(data.date)}
|
|
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
|
|
<svg width="10" height="10">
|
|
|
|
<circle cx="5" cy="5" r="4" stroke="${this.#dataTrendColor(data)}" fill="transparent" stroke-width="1"></circle>
|
|
|
|
</svg>
|
|
|
|
${data.value} <span style="color: ${this.#dataTrendColor(data)};">${this.#decimalChange(data)} (${data.trend.percent}%)</span>
|
|
|
|
</div>
|
|
|
|
`)
|
|
|
|
}
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#dataTrendColor(data) {
|
|
|
|
return {
|
|
|
|
up: tailwindColors.success,
|
|
|
|
down: tailwindColors.error,
|
|
|
|
flat: tailwindColors.gray[500],
|
|
|
|
}[data.trend.direction]
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#currencyValue(data) {
|
|
|
|
return Intl.NumberFormat(undefined, {
|
|
|
|
style: "currency",
|
2024-04-19 19:27:24 -06:00
|
|
|
currency: data.currency,
|
2024-04-19 18:30:25 -06:00
|
|
|
}).format(data.value)
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#currencyChange(data) {
|
|
|
|
return Intl.NumberFormat(undefined, {
|
|
|
|
style: "currency",
|
2024-04-19 19:27:24 -06:00
|
|
|
currency: data.currency,
|
2024-04-19 18:30:25 -06:00
|
|
|
signDisplay: "always",
|
|
|
|
}).format(data.trend.value.amount)
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 19:27:24 -06:00
|
|
|
#decimalChange(data) {
|
|
|
|
return Intl.NumberFormat(undefined, {
|
|
|
|
style: "decimal",
|
|
|
|
signDisplay: "always",
|
|
|
|
}).format(data.trend.value)
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
|
|
|
#createMainSvg() {
|
|
|
|
return this.#d3Container
|
|
|
|
.append("svg")
|
|
|
|
.attr("width", this.#d3InitialContainerWidth)
|
|
|
|
.attr("height", this.#d3InitialContainerHeight)
|
|
|
|
.attr("viewBox", [ 0, 0, this.#d3InitialContainerWidth, this.#d3InitialContainerHeight ])
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
#createFullChartGroup() {
|
|
|
|
return this.#d3MainSvg
|
|
|
|
.append("g")
|
|
|
|
.attr("transform", `translate(${this.#margin.left},${this.#margin.top})`)
|
2024-04-19 17:37:48 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
|
|
|
|
get #d3MainSvg() {
|
|
|
|
if (this.#_d3MainSvg) {
|
|
|
|
return this.#_d3MainSvg
|
2024-04-19 09:50:15 -06:00
|
|
|
} else {
|
2024-04-19 18:30:25 -06:00
|
|
|
return this.#_d3MainSvg = this.#createMainSvg()
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-20 12:26:59 -06:00
|
|
|
get #d3MainGroup() {
|
|
|
|
if (this.#_d3MainGroup) {
|
|
|
|
return this.#_d3MainGroup
|
2024-04-19 18:30:25 -06:00
|
|
|
} else {
|
2024-04-20 12:26:59 -06:00
|
|
|
return this.#_d3MainGroup = this.#createFullChartGroup()
|
2024-04-19 18:30:25 -06:00
|
|
|
}
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:30:25 -06:00
|
|
|
get #margin() {
|
2024-04-20 12:26:59 -06:00
|
|
|
if (this.useLabelsValue) {
|
2024-04-19 18:30:25 -06:00
|
|
|
return { top: 20, right: 1, bottom: 30, left: 1 }
|
|
|
|
} else {
|
|
|
|
return { top: 0, right: 0, bottom: 0, left: 0 }
|
|
|
|
}
|
2024-04-19 18:17:54 -06:00
|
|
|
}
|
|
|
|
|
2024-04-19 09:50:15 -06:00
|
|
|
get #d3ContainerWidth() {
|
2024-04-19 17:37:48 -06:00
|
|
|
return this.#d3InitialContainerWidth - this.#margin.left - this.#margin.right
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
get #d3ContainerHeight() {
|
2024-04-19 18:30:25 -06:00
|
|
|
return this.#d3InitialContainerHeight - this.#margin.top - this.#margin.bottom
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
get #d3Container() {
|
|
|
|
return d3.select(this.element)
|
|
|
|
}
|
|
|
|
|
|
|
|
get #trendColor() {
|
|
|
|
if (this.#trendDirection === "flat") {
|
|
|
|
return tailwindColors.gray[500]
|
|
|
|
} else if (this.#trendDirection === this.#favorableDirection) {
|
|
|
|
return tailwindColors.green[500]
|
|
|
|
} else {
|
|
|
|
return tailwindColors.error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get #trendDirection() {
|
|
|
|
return this.seriesValue.trend.direction
|
|
|
|
}
|
|
|
|
|
|
|
|
get #favorableDirection() {
|
|
|
|
return this.seriesValue.trend.favorableDirection
|
|
|
|
}
|
|
|
|
|
|
|
|
get #d3Line() {
|
|
|
|
return d3
|
|
|
|
.line()
|
|
|
|
.x(d => this.#d3XScale(d.date))
|
|
|
|
.y(d => this.#d3YScale(d.value))
|
|
|
|
}
|
|
|
|
|
|
|
|
get #d3XScale() {
|
|
|
|
return d3
|
|
|
|
.scaleTime()
|
2024-04-19 17:37:48 -06:00
|
|
|
.rangeRound([ 0, this.#d3ContainerWidth ])
|
2024-04-19 09:50:15 -06:00
|
|
|
.domain(d3.extent(this.#dataPoints, d => d.date))
|
|
|
|
}
|
|
|
|
|
|
|
|
get #d3YScale() {
|
2024-04-20 12:26:59 -06:00
|
|
|
const reductionPercent = this.useLabelsValue ? 0.15 : 0.05
|
2024-04-19 09:50:15 -06:00
|
|
|
const dataMin = d3.min(this.#dataPoints, d => d.value)
|
|
|
|
const dataMax = d3.max(this.#dataPoints, d => d.value)
|
2024-04-20 12:26:59 -06:00
|
|
|
const padding = (dataMax - dataMin) * reductionPercent
|
2024-04-19 09:50:15 -06:00
|
|
|
|
|
|
|
return d3
|
|
|
|
.scaleLinear()
|
2024-04-19 17:37:48 -06:00
|
|
|
.rangeRound([ this.#d3ContainerHeight, 0 ])
|
|
|
|
.domain([ dataMin - padding, dataMax + padding ])
|
2024-04-19 09:50:15 -06:00
|
|
|
}
|
|
|
|
}
|