Skip to content

Commit 4985313

Browse files
committed
smoothing with step trimming
1 parent aa11e00 commit 4985313

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

app/ui/src/components/charts/lines/plot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class LinePlot {
8989
})
9090
})
9191

92-
if (this.series.length == 1) {
92+
if (this.series.length == 1) { // allways render circle for single point
9393
this.renderCircle(0)
9494
}
9595
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SparkLines {
5656
const margin = Math.floor(opt.width / 64)
5757
this.rowWidth = Math.min(450, opt.width - Math.max(3 * margin, 60))
5858

59-
this.stepExtent = getExtent(this.currentSeries.concat(this.baseSeries).map(s => s.series), d => d.step)
59+
this.stepExtent = getExtent(this.currentSeries.concat(this.baseSeries).map(s => s.trimmedSeries), d => d.step)
6060

6161
this.chartColors = new ChartColors({nColors: this.uniqueItems.size, secondNColors: this.uniqueItems.size, isDivergent: opt.isDivergent})
6262
}
@@ -82,7 +82,7 @@ export class SparkLines {
8282
}
8383
let sparkLine = new SparkLine({
8484
name: s.name,
85-
series: s.series,
85+
series: s.trimmedSeries,
8686
selected: this.currentPlotIdx[i],
8787
stepExtent: this.stepExtent,
8888
width: this.rowWidth,
@@ -105,7 +105,7 @@ export class SparkLines {
105105
}
106106
let sparkLine = new SparkLine({
107107
name: s.name,
108-
series: s.series,
108+
series: s.trimmedSeries,
109109
selected: this.basePlotIdx[i],
110110
stepExtent: this.stepExtent,
111111
width: this.rowWidth,

app/ui/src/components/charts/utils.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,22 @@ export function trimSteps(series: Indicator[], min: number, max: number, smoothR
255255
s.highTrimIndex = maxIndex
256256

257257
if (s.lowTrimIndex > s.highTrimIndex) { // if trim covers all just give the middle value
258-
s.lowTrimIndex = s.series.length / 2
259-
s.highTrimIndex = s.series.length / 2
258+
localMax = max == -1 ? s.series[s.series.length - 1].step : max
259+
localMin = min == -1 ? s.series[0].step : min
260+
261+
minIndex = s.series.length - 1
262+
maxIndex = 0
263+
264+
for (let i = 0; i < s.series.length; i++) {
265+
let p = s.series[i]
266+
if (p.step >= localMin && p.step <= localMax) {
267+
minIndex = Math.min(i, minIndex)
268+
maxIndex = Math.max(i, maxIndex)
269+
}
270+
}
271+
272+
s.lowTrimIndex = (minIndex + maxIndex) / 2
273+
s.highTrimIndex = (minIndex + maxIndex) / 2
260274
}
261275
})
262276
}

0 commit comments

Comments
 (0)