fix: add first datapoint tooltip for line graph (#882)

Also clean up logic for smoothing (vs non-smoothing) and put it in a separate code block.
This commit is contained in:
akloeckner
2023-04-22 22:17:49 +02:00
committed by GitHub
parent 057a395ecb
commit 7576fe6460

View File

@@ -118,17 +118,18 @@ export default class Graph {
coords[1] = [this.width + this.margin[X], 0, coords[0][V]];
}
coords = this._calcY(this.coords);
let next; let Z;
let last = coords[0];
coords.shift();
const coords2 = coords.map((point, i) => {
next = point;
Z = this._smoothing ? this._midPoint(last[X], last[Y], next[X], next[Y]) : next;
const sum = this._smoothing ? (next[V] + last[V]) / 2 : next[V];
last = next;
return [Z[X], Z[Y], sum, i + 1];
});
return coords2;
if (this._smoothing) {
let last = coords[0];
coords.shift();
return coords.map((point, i) => {
const Z = this._midPoint(last[X], last[Y], point[X], point[Y]);
const sum = (last[V] + point[V]) / 2;
last = point;
return [Z[X], Z[Y], sum, i + 1];
});
} else {
return coords.map((point, i) => [point[X], point[Y], point[V], i]);
}
}