Skip to content

Commit 049c4be

Browse files
authored
Merge pull request #218 from labmlai/compare-fix
Compare fix
2 parents f349dc3 + 357ab70 commit 049c4be

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

app/ui/src/components/charts/spark_lines/chart.ts

+9-15
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ export class SparkLines {
3535
uniqueItems: Map<string, number>
3636
onlySelected: boolean
3737

38-
private readonly currentSmoothedValues: number[][]
39-
private readonly baseSmoothedValues: number[][]
40-
4138
constructor(opt: CompareSparkLinesOptions) {
4239
this.currentSeries = opt.series
4340
this.baseSeries = opt.baseSeries ?? []
@@ -59,17 +56,16 @@ export class SparkLines {
5956
const margin = Math.floor(opt.width / 64)
6057
this.rowWidth = Math.min(450, opt.width - Math.max(3 * margin, 60))
6158

62-
this.currentSmoothedValues = []
63-
this.baseSmoothedValues = []
6459
let [smoothWindow, _] = getSmoothWindow(this.currentSeries, this.baseSeries, opt.smoothValue)
65-
for (let i = 0; i < this.currentSeries.length; i++) {
66-
let smoothedSeries = smoothSeries(this.currentSeries[i].series, smoothWindow[0][i])
67-
this.currentSmoothedValues.push(smoothedSeries.map(d => d.smoothed))
68-
}
69-
for (let i = 0; i < this.baseSeries.length; i++) {
70-
let smoothedSeries = smoothSeries(this.baseSeries[i].series, smoothWindow[0][1])
71-
this.baseSmoothedValues.push(smoothedSeries.map(d => d.smoothed))
72-
}
60+
61+
this.currentSeries = this.currentSeries.map((s, i) => {
62+
s.series = smoothSeries(s.series, smoothWindow[0][i])
63+
return s
64+
})
65+
this.baseSeries = this.baseSeries.map((s, i) => {
66+
s.series = smoothSeries(s.series, smoothWindow[1][i])
67+
return s
68+
})
7369

7470
this.stepExtent = getExtent(this.currentSeries.concat(this.baseSeries).map(s => s.series), d => d.step)
7571

@@ -104,7 +100,6 @@ export class SparkLines {
104100
onClick: onClick,
105101
color: this.chartColors.getColor(this.uniqueItems.get(s.name)),
106102
isMouseMoveOpt: this.isMouseMoveOpt,
107-
smoothedValues: this.currentSmoothedValues[i],
108103
isComparison: this.baseSeries.length > 0
109104
})
110105
this.sparkLines.push(sparkLine)
@@ -130,7 +125,6 @@ export class SparkLines {
130125
isMouseMoveOpt: this.isMouseMoveOpt,
131126
isBase: true,
132127
isComparison: this.baseSeries.length > 0,
133-
smoothedValues: this.baseSmoothedValues[i]
134128
})
135129
this.sparkLines.push(sparkLine)
136130
})

app/ui/src/components/charts/spark_lines/spark_line.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface SparkLineOptions {
1717
color: string
1818
isComparison?: boolean
1919
isBase?: boolean
20-
smoothedValues: number[]
2120
}
2221

2322
export class SparkLine {
@@ -37,16 +36,13 @@ export class SparkLine {
3736
bisect: d3.Bisector<number, number>
3837
linePlot: LinePlot
3938
isBase: boolean
40-
smoothedValues: number[]
4139
isComparison: boolean
4240

4341
constructor(opt: SparkLineOptions) {
4442
this.series = opt.series
45-
this.smoothedValues = opt.smoothedValues
4643

4744
if (opt.selected == -1) {
4845
this.series = [this.series[this.series.length - 1]]
49-
this.smoothedValues = [this.smoothedValues[this.smoothedValues.length - 1]]
5046
}
5147
this.name = opt.name
5248
this.selected = opt.selected
@@ -86,14 +82,13 @@ export class SparkLine {
8682
const index = this.isSelected ?
8783
getSelectedIdx(this.series, this.bisect, cursorStep) : this.series.length - 1
8884
const last = this.series[index]
89-
const lastSmoothed = this.smoothedValues[index]
9085

91-
if (Math.abs(last.value - lastSmoothed) > Math.abs(last.value) / 1e6) {
86+
if (Math.abs(last.value - last.smoothed) > Math.abs(last.value) / 1e6) {
9287
this.secondaryElem.textContent = formatFixed(last.value, 6)
9388
} else {
9489
this.secondaryElem.textContent = ''
9590
}
96-
this.primaryElem.textContent = formatFixed(lastSmoothed, 6)
91+
this.primaryElem.textContent = formatFixed(last.smoothed, 6)
9792
}
9893

9994
render($: WeyaElementFunction) {

0 commit comments

Comments
 (0)