fix(plugins/lines): handle no history data
This commit is contained in:
1
.github/workflows/examples.yml
vendored
1
.github/workflows/examples.yml
vendored
@@ -289,7 +289,6 @@ jobs:
|
|||||||
@use.patterns
|
@use.patterns
|
||||||
*/*
|
*/*
|
||||||
+lowlighter/metrics
|
+lowlighter/metrics
|
||||||
+lowlighter/brain
|
|
||||||
output_action: none
|
output_action: none
|
||||||
delay: 120
|
delay: 120
|
||||||
user: lowlighter
|
user: lowlighter
|
||||||
|
|||||||
@@ -20,4 +20,3 @@
|
|||||||
@use.patterns
|
@use.patterns
|
||||||
*/*
|
*/*
|
||||||
+lowlighter/metrics
|
+lowlighter/metrics
|
||||||
+lowlighter/brain
|
|
||||||
|
|||||||
@@ -71,54 +71,60 @@ export default async function({login, data, imports, rest, q, account}, {enabled
|
|||||||
|
|
||||||
//Diff graphs
|
//Diff graphs
|
||||||
if (sections.includes("history")) {
|
if (sections.includes("history")) {
|
||||||
//Generate SVG
|
|
||||||
const height = 315, width = 480
|
|
||||||
const margin = 5, offset = 34
|
|
||||||
const {d3} = imports
|
|
||||||
const weeks = result.weeks.filter(({date}) => !_history_limit ? true : new Date(date) > new Date(new Date().getFullYear() - _history_limit, 0, 0))
|
const weeks = result.weeks.filter(({date}) => !_history_limit ? true : new Date(date) > new Date(new Date().getFullYear() - _history_limit, 0, 0))
|
||||||
const d3n = new imports.D3node()
|
if (weeks.length) {
|
||||||
const svg = d3n.createSVG(width, height)
|
//Generate SVG
|
||||||
|
const height = 315, width = 480
|
||||||
|
const margin = 5, offset = 34
|
||||||
|
const {d3} = imports
|
||||||
|
const d3n = new imports.D3node()
|
||||||
|
const svg = d3n.createSVG(width, height)
|
||||||
|
|
||||||
//Time range
|
//Time range
|
||||||
const start = new Date(weeks.at(0).date)
|
const start = new Date(weeks.at(0).date)
|
||||||
const end = new Date(weeks.at(-1).date)
|
const end = new Date(weeks.at(-1).date)
|
||||||
const x = d3.scaleTime()
|
const x = d3.scaleTime()
|
||||||
.domain([start, end])
|
.domain([start, end])
|
||||||
.range([margin + offset, width - (offset + margin)])
|
.range([margin + offset, width - (offset + margin)])
|
||||||
svg.append("g")
|
svg.append("g")
|
||||||
.attr("transform", `translate(0,${height - (offset + margin)})`)
|
.attr("transform", `translate(0,${height - (offset + margin)})`)
|
||||||
.call(d3.axisBottom(x))
|
.call(d3.axisBottom(x))
|
||||||
.selectAll("text")
|
.selectAll("text")
|
||||||
.attr("transform", "translate(-5,5) rotate(-45)")
|
.attr("transform", "translate(-5,5) rotate(-45)")
|
||||||
.style("text-anchor", "end")
|
.style("text-anchor", "end")
|
||||||
.style("font-size", 20)
|
.style("font-size", 20)
|
||||||
|
|
||||||
//Diff range
|
//Diff range
|
||||||
const points = weeks.flatMap(({added, deleted, changed}) => [added + changed, deleted + changed])
|
const points = weeks.flatMap(({added, deleted, changed}) => [added + changed, deleted + changed])
|
||||||
const extremum = Math.max(...points)
|
const extremum = Math.max(...points)
|
||||||
const y = d3.scaleLinear()
|
const y = d3.scaleLinear()
|
||||||
.domain([extremum, -extremum])
|
.domain([extremum, -extremum])
|
||||||
.range([margin, height - (offset + margin)])
|
.range([margin, height - (offset + margin)])
|
||||||
svg.append("g")
|
svg.append("g")
|
||||||
.attr("transform", `translate(${margin + offset},0)`)
|
.attr("transform", `translate(${margin + offset},0)`)
|
||||||
.call(d3.axisLeft(y).ticks(7).tickFormat(d3.format(".2s")))
|
.call(d3.axisLeft(y).ticks(7).tickFormat(d3.format(".2s")))
|
||||||
.selectAll("text")
|
.selectAll("text")
|
||||||
.style("font-size", 20)
|
.style("font-size", 20)
|
||||||
|
|
||||||
//Generate history
|
//Generate history
|
||||||
for (const {type, sign, fill} of [{type: "added", sign: +1, fill: "rgb(63, 185, 80)"}, {type: "deleted", sign: -1, fill: "rgb(218, 54, 51)"}]) {
|
for (const {type, sign, fill} of [{type: "added", sign: +1, fill: "rgb(63, 185, 80)"}, {type: "deleted", sign: -1, fill: "rgb(218, 54, 51)"}]) {
|
||||||
svg.append("path")
|
svg.append("path")
|
||||||
.datum(weeks.map(({date, ...diff}) => [new Date(date), sign * (diff[type] + diff.changed)]))
|
.datum(weeks.map(({date, ...diff}) => [new Date(date), sign * (diff[type] + diff.changed)]))
|
||||||
.attr(
|
.attr(
|
||||||
"d",
|
"d",
|
||||||
d3.area()
|
d3.area()
|
||||||
.x(d => x(d[0]))
|
.x(d => x(d[0]))
|
||||||
.y0(d => y(d[1]))
|
.y0(d => y(d[1]))
|
||||||
.y1(() => y(0)),
|
.y1(() => y(0)),
|
||||||
)
|
)
|
||||||
.attr("fill", fill)
|
.attr("fill", fill)
|
||||||
|
}
|
||||||
|
result.history = d3n.svgString()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > lines > no history data`)
|
||||||
|
result.history = null
|
||||||
}
|
}
|
||||||
result.history = d3n.svgString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Results
|
//Results
|
||||||
|
|||||||
1
tests/cases/lines.plugin.yml
generated
1
tests/cases/lines.plugin.yml
generated
@@ -18,6 +18,5 @@
|
|||||||
@use.patterns
|
@use.patterns
|
||||||
*/*
|
*/*
|
||||||
+lowlighter/metrics
|
+lowlighter/metrics
|
||||||
+lowlighter/brain
|
|
||||||
use_mocked_data: 'yes'
|
use_mocked_data: 'yes'
|
||||||
verify: 'yes'
|
verify: 'yes'
|
||||||
|
|||||||
Reference in New Issue
Block a user