1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-27 09:09:41 +02:00

Implement empty state

This commit is contained in:
Jose Farias 2024-04-19 10:02:37 -06:00
parent f40cb215f7
commit 39ebf7f129

View file

@ -34,13 +34,42 @@ export default class extends Controller {
} }
#normalizeDataPoints() { #normalizeDataPoints() {
this.#dataPoints = this.seriesValue.values.map((d) => ({ this.#dataPoints = (this.seriesValue.values || []).map((d) => ({
date: new Date(d.date), date: new Date(d.date),
value: d.value.amount ? +d.value.amount : +d.value, value: d.value.amount ? +d.value.amount : +d.value,
})) }))
} }
#draw() { #draw() {
if (this.#dataPoints.length < 2) {
this.#drawEmpty()
} else {
this.#drawLine()
}
}
#drawEmpty() {
this.#d3Svg.selectAll(".tick").remove()
this.#d3Svg.selectAll(".domain").remove()
this.#d3Svg
.append("line")
.attr("x1", this.#d3Svg.node().clientWidth / 2)
.attr("y1", 0)
.attr("x2", this.#d3Svg.node().clientWidth / 2)
.attr("y2", this.#d3Svg.node().clientHeight)
.attr("stroke", tailwindColors.gray[300])
.attr("stroke-dasharray", "4, 4")
this.#d3Svg
.append("circle")
.attr("cx", this.#d3Svg.node().clientWidth / 2)
.attr("cy", this.#d3Svg.node().clientHeight / 2)
.attr("r", 4)
.style("fill", tailwindColors.gray[400])
}
#drawLine() {
this.#d3Svg this.#d3Svg
.append("path") .append("path")
.datum(this.#dataPoints) .datum(this.#dataPoints)