Skip to content

Commit 334358a

Browse files
jiayiw5j0weiss
authored andcommitted
[IT-2766] scaled data
1 parent a3eac9f commit 334358a

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

frontend/src/app/modules/time-series/services/line-chart.service.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export class LineChartService {
6262
private _margin = { top: 40, right: 70, bottom: 40, left: 60 };
6363
private _width = 600 - this._margin.left - this._margin.right;
6464
private _height = 500 - this._margin.top - this._margin.bottom;
65-
private idleTimeout;
6665
private brush;
6766

6867

@@ -326,7 +325,6 @@ export class LineChartService {
326325
*/
327326
private getLineGenerator(xScale: D3ScaleTime<number, number>,
328327
yScale: D3ScaleLinear<number, number>): D3Line<TimeSeriesPoint> {
329-
console.log(xScale.ticks());
330328
return d3Line<TimeSeriesPoint>() // Setup a line generator
331329
.x((point: TimeSeriesPoint) => {
332330
return xScale(point.date);
@@ -377,8 +375,10 @@ export class LineChartService {
377375
private resetChart(xScale: D3ScaleTime<number, number>, yScale: D3ScaleLinear<number, number>){
378376
d3Select('.x-axis').transition().call(this.updateXAxis, xScale);
379377
d3Select('g#time-series-chart-drawing-area').selectAll('.line').each((data, index, nodes) => {
380-
d3Select(nodes[index]).transition()
381-
.attr('d', (dataItem: TimeSeries) => this.getLineGenerator(xScale,yScale)(dataItem.values))
378+
d3Select(nodes[index])
379+
.transition()
380+
.duration(500)
381+
.attr('d', (dataItem: TimeSeries) => this.getLineGenerator(xScale,yScale)(dataItem.values));
382382
})
383383
}
384384

@@ -387,27 +387,25 @@ export class LineChartService {
387387
let extent = d3Event.selection;
388388
// If no selection, back to initial coordinate. Otherwise, update X axis domain
389389
if(!extent){
390-
if (!this.idleTimeout) return this.idleTimeout = setTimeout(this.idleTimeout = null, 350); // This allows to wait a little bit
391-
//xScale = this.getXScale(data);
392-
390+
return
393391
}else{
394-
xScale.domain([ xScale.invert(extent[0]), xScale.invert(extent[1]) ]);
395-
selection.select(".brush").call(this.brush.move, null);
396-
d3Select('.x-axis').transition().call(this.updateXAxis, xScale);// This remove the grey brush area as soon as the selection has been don
397-
selection.selectAll('.line').each((data, index, nodes) => {
392+
let minDate = xScale.invert(extent[0]);
393+
let maxDate = xScale.invert(extent[1]);
394+
xScale.domain([ minDate, maxDate ]);
395+
selection.select(".brush").call(this.brush.move, null); // This remove the grey brush area
396+
d3Select('.x-axis').transition().call(this.updateXAxis, xScale);
397+
selection.selectAll('.line').each((_, index, nodes) => {
398398
d3Select(nodes[index])
399399
.transition()
400400
.attr('d', (dataItem: TimeSeries) => {
401-
/*let newDataItem = dataItem.values.map((point: TimeSeriesPoint) => {
402-
point.date
403-
})*/
404-
console.log(xScale.ticks());
405-
return this.getLineGenerator(xScale,yScale)(dataItem.values);
401+
let newDataValues = dataItem.values.filter((point) => {
402+
return point.date <= maxDate && point.date >= minDate;
403+
});
404+
return this.getLineGenerator(xScale,yScale)(newDataValues);
406405
})
407406
}
408407
)
409408
}
410-
411409
}
412410

413411
private drawLine(selection: any,

0 commit comments

Comments
 (0)