@@ -47,6 +47,7 @@ import {TimeSeriesPoint} from 'src/app/modules/time-series/models/time-series-po
47
47
import { parseDate } from 'src/app/utils/date.util' ;
48
48
import { getColorScheme } from 'src/app/enums/color-scheme.enum' ;
49
49
import { ChartCommons } from "../../../enums/chart-commons.enum" ;
50
+ import { SummaryLabel } from "../models/summary-label.model" ;
50
51
51
52
/**
52
53
* Generate line charts with ease and fun 😎
@@ -67,10 +68,9 @@ export class LineChartService {
67
68
private _height : number = 550 - this . _margin . top - this . _margin . bottom ;
68
69
private _labelGroupHeight : number ;
69
70
private _legendGroupTop : number = this . _margin . top + this . _height + 50 ;
70
- private _legendGroupLeft : number = this . _margin . left ;
71
- private _legendGroupHeight ;
72
- private _legendGroupColumnWidth ;
73
- private _legendGroupColumns ;
71
+ private _legendGroupHeight : number ;
72
+ private _legendGroupColumnWidth : number ;
73
+ private _legendGroupColumns : number ;
74
74
private legendDataMap : Object = { } ;
75
75
private brush : BrushBehavior < { } > ;
76
76
private focusedLegendEntry : string ;
@@ -118,6 +118,7 @@ this.calculateLegendDimensions();
118
118
119
119
this . addBrush ( chart , xScale , yScale , data ) ;
120
120
this . addLegendsToChart ( chart , incomingData ) ;
121
+ this . setSummaryLabel ( chart , incomingData . summaryLabels ) ;
121
122
this . addDataLinesToChart ( chart , xScale , yScale , data ) ;
122
123
123
124
this . bringMouseMarkerToTheFront ( xScale , yScale ) ;
@@ -141,12 +142,14 @@ this.calculateLegendDimensions();
141
142
142
143
let labelDataMap = { } ;
143
144
incomingData . series . forEach ( ( data : EventResultSeriesDTO ) => {
144
- let label = data . identifier ;
145
+ if ( incomingData . summaryLabels . length > 0 && incomingData . summaryLabels [ 0 ] . key != "measurand" ) {
146
+ data . identifier = this . translateMeasurand ( data ) ;
147
+ }
145
148
let key = this . generateKey ( data ) ;
146
149
labelDataMap [ key ] = {
147
- text : label ,
150
+ text : data . identifier ,
148
151
key : key ,
149
- show : true ,
152
+ show : true
150
153
}
151
154
} ) ;
152
155
this . legendDataMap = labelDataMap ;
@@ -156,27 +159,40 @@ this.calculateLegendDimensions();
156
159
* Prepares the incoming data for drawing with D3.js
157
160
*/
158
161
private prepareData ( incomingData : EventResultDataDTO ) : TimeSeries [ ] {
159
-
160
162
return incomingData . series . map ( ( data : EventResultSeriesDTO ) => {
161
163
let lineChartData : TimeSeries = new TimeSeries ( ) ;
164
+ if ( incomingData . summaryLabels . length > 0 && incomingData . summaryLabels [ 0 ] . key != "measurand" ) {
165
+ data . identifier = this . translateMeasurand ( data ) ;
166
+ }
162
167
lineChartData . key = this . generateKey ( data ) ;
163
168
164
169
lineChartData . values = data . data . map ( ( point : EventResultPointDTO ) => {
165
170
let lineChartDataPoint : TimeSeriesPoint = new TimeSeriesPoint ( ) ;
166
171
lineChartDataPoint . date = parseDate ( point . date ) ;
167
172
lineChartDataPoint . value = point . value ;
168
- lineChartDataPoint . tooltipText = data . jobGroup + ' | ' + data . measuredEvent + ' : '; // TODO Set exact label text when IT-2793 is implemented
173
+ lineChartDataPoint . tooltipText = data . identifier + ' : ' ;
169
174
return lineChartDataPoint ;
170
175
} ) ;
171
176
172
177
return lineChartData ;
173
178
} ) ;
174
179
}
175
180
181
+ private translateMeasurand ( data : EventResultSeriesDTO ) : string {
182
+ let splitLabelList : string [ ] = data . identifier . split ( ' | ' ) ;
183
+ let splitLabel : string = this . translationService . instant ( 'frontend.de.iteratec.isr.measurand.' + splitLabelList [ 0 ] ) ;
184
+ if ( ! splitLabel . startsWith ( 'frontend.de.iteratec.isr.measurand.' ) ) {
185
+ splitLabelList [ 0 ] = splitLabel ;
186
+ }
187
+ return splitLabelList . join ( ' | ' ) ;
188
+ }
189
+
176
190
private generateKey ( data : EventResultSeriesDTO ) : string {
177
- return data . jobGroup
178
- + data . measuredEvent
179
- + data . data . length ;
191
+ let key : string = data . identifier . replace ( / [ ^ _ a - z A - Z 0 - 9 - ] / g, "" ) ;
192
+ if ( new RegExp ( '[0-9]' ) . test ( key . charAt ( 0 ) ) ) {
193
+ key = key . replace ( / [ 0 - 9 ] / , '_' ) ;
194
+ }
195
+ return key ;
180
196
}
181
197
182
198
/**
@@ -189,14 +205,69 @@ this.calculateLegendDimensions();
189
205
. attr ( 'width' , this . _width + this . _margin . left + this . _margin . right )
190
206
. attr ( 'height' , 0 ) ;
191
207
208
+ svg . append ( 'g' )
209
+ . attr ( 'id' , 'header-group' )
210
+ . attr ( 'transform' , `translate(${ this . _margin . left } , ${ this . _margin . top - 16 } )` ) ;
211
+
212
+ let chart = svg . append ( 'g' ) // g = grouping element; group all other stuff into the chart
213
+ . attr ( 'id' , 'time-series-chart-drawing-area' )
214
+ . attr ( 'transform' , `translate(${ this . _margin . left } , ${ this . _margin . top } )` ) ; // translates the origin to the top left corner (default behavior of D3)
215
+
192
216
svg . append ( 'g' )
193
217
. attr ( 'id' , 'time-series-chart-legend' )
194
218
. attr ( 'class' , 'legend-group' )
195
- . attr ( 'transform' , `translate(${ this . _legendGroupLeft } , ${ this . _legendGroupTop } )` ) ;
219
+ . attr ( 'transform' , `translate(${ this . _margin . left } , ${ this . _legendGroupTop } )` ) ;
196
220
197
- return svg . append ( 'g' ) // g = grouping element; group all other stuff into the chart
198
- . attr ( 'id' , 'time-series-chart-drawing-area' )
199
- . attr ( 'transform' , 'translate(' + this . _margin . left + ', ' + this . _margin . top + ')' ) ; // translates the origin to the top left corner (default behavior of D3)
221
+ return chart ;
222
+ }
223
+
224
+ private setSummaryLabel ( chart : D3Selection < D3BaseType , { } , D3ContainerElement , { } > , summaryLabels : SummaryLabel [ ] ) : void {
225
+ d3Select ( 'g#header-group' ) . selectAll ( '.summary-label-text' ) . remove ( ) ;
226
+ if ( summaryLabels . length > 0 ) {
227
+ d3Select ( '#header-group' )
228
+ . append ( 'g' )
229
+ . attr ( 'class' , 'summary-label-text' )
230
+ . append ( 'text' )
231
+ . attr ( 'id' , 'summary-label-part0' )
232
+ . attr ( 'x' , this . _width / 2 )
233
+ . attr ( 'text-anchor' , 'middle' )
234
+ . attr ( 'fill' , '#555555' ) ;
235
+
236
+ summaryLabels . forEach ( ( summaryLabel : SummaryLabel , index : number ) => {
237
+ this . translationService
238
+ . get ( 'frontend.de.iteratec.osm.timeSeries.chart.label.' + summaryLabel . key )
239
+ . pipe ( take ( 1 ) )
240
+ . subscribe ( ( key : string ) => {
241
+ if ( summaryLabel . key == 'measurand' ) {
242
+ this . translationService
243
+ . get ( 'frontend.de.iteratec.isr.measurand.' + summaryLabel . label )
244
+ . pipe ( take ( 1 ) )
245
+ . subscribe ( ( label : string ) => {
246
+ if ( label . startsWith ( 'frontend.de.iteratec.isr.measurand.' ) ) {
247
+ label = summaryLabel . label
248
+ }
249
+ label = index < summaryLabels . length - 1 ? `${ label } | ` : label ;
250
+ this . addSummaryLabel ( key , label , index ) ;
251
+ } ) ;
252
+ } else {
253
+ const label : string = index < summaryLabels . length - 1 ? `${ summaryLabel . label } | ` : summaryLabel . label ;
254
+ this . addSummaryLabel ( key , label , index ) ;
255
+ }
256
+ } ) ;
257
+ } ) ;
258
+ chart . selectAll ( '.summary-label-text' ) . remove ( ) ;
259
+ }
260
+ }
261
+
262
+ private addSummaryLabel ( key : string , label : string , index : number ) : void {
263
+ d3Select ( `#summary-label-part${ index } ` )
264
+ . append ( 'tspan' )
265
+ . attr ( 'id' , `summary-label-part${ index + 1 } ` )
266
+ . attr ( 'class' , 'summary-label-key' )
267
+ . text ( `${ key } : ` )
268
+ . append ( 'tspan' )
269
+ . attr ( 'class' , 'summary-label' )
270
+ . text ( label ) ;
200
271
}
201
272
202
273
public startResize ( svgElement : ElementRef ) : void {
@@ -538,7 +609,7 @@ this.calculateLegendDimensions();
538
609
} )
539
610
// fade in
540
611
. transition ( ) . duration ( 500 ) . style ( 'opacity' , ( timeSeries : TimeSeries ) => {
541
- return ( this . legendDataMap [ timeSeries . key ] . show ) ? '1' : '0.2 ' ;
612
+ return ( this . legendDataMap [ timeSeries . key ] . show ) ? '1' : '0.1 ' ;
542
613
} ) ;
543
614
544
615
return resultingSelection ;
0 commit comments