Skip to content

Commit 4b48fe6

Browse files
author
Gustavo Antonio Lastra Colorado
committed
[IT-2793] edit labels initialization
1 parent 1a4b4fe commit 4b48fe6

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

frontend/src/app/modules/time-series/components/time-series-line-chart/time-series-line-chart.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export class TimeSeriesLineChartComponent implements AfterContentInit, OnChanges
4949
}
5050

5151
redraw() {
52+
this.lineChartService.initLegendData(this.timeSeriesResults);
5253
this.lineChartService.drawLegends(this.timeSeriesResults);
5354
this.lineChartService.drawLineChart(this.timeSeriesResults);
5455
}
5556

5657
ngAfterContentInit(): void {
5758
this.lineChartService.initChart(this.svgElement);
58-
this.lineChartService.initLegendData();
5959
}
6060

6161
ngOnChanges(changes: SimpleChanges): void {

frontend/src/app/modules/time-series/models/time-series-legend.model.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class LineChartService {
8989
return;
9090
}
9191

92+
9293
this._labelGroupHeight = data.length * this._labelHeight;
9394

9495
d3Select('osm-time-series-line-chart').transition().duration(500).style('visibility', 'visible');
@@ -101,16 +102,13 @@ export class LineChartService {
101102
this.addDataLinesToChart(chart, xScale, yScale, data);
102103
}
103104

104-
public initLegendData(){
105+
public initLegendData(incomingData: EventResultDataDTO){
105106
const TimeSeriesSVG = d3Select("#time-series-svg");
107+
let labelDataMap= {}
106108
TimeSeriesSVG.append('g')
107109
.attr('class', 'legend-group')
108110
.attr('transform', `translate(${this._legendGroupLeft}, ${this._legendGroupTop })`)
109-
}
110111

111-
public drawLegends(incomingData: EventResultDataDTO): void {
112-
let labelDataMap= {}
113-
let chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}> = d3Select('g#time-series-chart-drawing-area');
114112
incomingData.series.forEach((data: EventResultSeriesDTO) => {
115113
let label = data.identifier;
116114
let key = this.generateKey(data);
@@ -120,8 +118,12 @@ export class LineChartService {
120118
show: true,
121119
}
122120
});
123-
this.legendDataMap= labelDataMap;
124-
this.addIdentifierLegendsToChart(chart, incomingData)
121+
this.legendDataMap=labelDataMap;
122+
}
123+
124+
public drawLegends(incomingData: EventResultDataDTO): void {
125+
let chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}> = d3Select('g#time-series-chart-drawing-area');
126+
this.addLegendsToChart(chart, incomingData)
125127
}
126128

127129
/**
@@ -391,10 +393,10 @@ export class LineChartService {
391393
.append('g') // Group each line so we can add dots to this group latter
392394
.append('path') // Draw one path for every item in the data set
393395
.attr('fill', 'none')
394-
.attr('stroke', (d, index: number) => { return getColorScheme()[index]; /*console.log("d: " + JSON.stringify(d));*/ /*this.legendDataMap[d].color*/ /*this.legendDataMap[d].color; getColorScheme()[index];*/ })
396+
.attr('stroke', (d, index: number) => { return getColorScheme()[index]; })
395397
.attr('stroke-width', 1.5)
396398
.style('opacity', (d) => {
397-
return ( this.legendDataMap[d.key].show) ? 1 : 0.1;
399+
return ( this.legendDataMap[d.key].show) ? 1 : 0.2;
398400
})
399401
.attr('d', (dataItem: TimeSeries) => {
400402
return this.getLineGenerator(xScale, yScale)(dataItem.values);
@@ -408,7 +410,7 @@ export class LineChartService {
408410
});
409411
}
410412

411-
private addIdentifierLegendsToChart(chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}>,
413+
private addLegendsToChart(chart: D3Selection<D3BaseType, {}, D3ContainerElement, {}>,
412414
incomingData: EventResultDataDTO) {
413415
chart.selectAll('.legend-entry').remove();
414416
const legendEntry = d3Select('.legend-group').selectAll('.legend-entry').data(Object.keys(this.legendDataMap));
@@ -439,7 +441,7 @@ export class LineChartService {
439441
.transition()
440442
.duration(ChartCommons.TRANSITION_DURATION)
441443
.style('opacity', (datum)=>{
442-
return (this.legendDataMap[datum].show) ? 1 : 0.1;
444+
return (this.legendDataMap[datum].show) ? 1 : 0.2;
443445
});
444446
return update;
445447
},
@@ -476,8 +478,8 @@ export class LineChartService {
476478
}
477479
});
478480
}
479-
this.drawLineChart(incomingData);
480481
this.drawLegends(incomingData);
482+
this.drawLineChart(incomingData);
481483
}
482484

483485
//private addDataPointsToChart(chartLineGroups: D3Selection<any, LineChartDataDTO, D3ContainerElement, {}>,

0 commit comments

Comments
 (0)