@@ -273,15 +273,15 @@ export class LineChartService {
273
273
visibleDots
274
274
. each ( ( timeSeriesPoint : TimeSeriesPoint , index : number , nodes : D3BaseType [ ] ) => {
275
275
tempArray . push ( {
276
- 'value ' : timeSeriesPoint . value ,
277
- 'htmlNode ' : generateTooltipDataPointRow ( timeSeriesPoint , nodes [ index ] , nearestDotData )
276
+ 'htmlNode ' : generateTooltipDataPointRow ( timeSeriesPoint , nodes [ index ] , nearestDotData ) ,
277
+ 'yPosition ' : nodes [ index ] [ 'cy' ] . animVal . value
278
278
} ) ;
279
279
if ( index === 0 ) {
280
280
testAgent = generateTooltipTestAgentRow ( timeSeriesPoint ) ;
281
281
}
282
282
} ) ;
283
283
tempArray
284
- . sort ( ( a , b ) => b . value - a . value )
284
+ . sort ( ( a , b ) => a . yPosition - b . yPosition )
285
285
. forEach ( elem => tableBody . append ( elem . htmlNode ) ) ;
286
286
tableBody . append ( testAgent ) ;
287
287
@@ -405,11 +405,10 @@ export class LineChartService {
405
405
406
406
const drawLine = ( selection : D3Selection < D3BaseType , TimeSeries , D3BaseType , { } > ,
407
407
xScale : D3ScaleTime < number , number > ,
408
- yScale : D3ScaleLinear < number , number > ,
409
- index : number ) : D3Selection < D3BaseType , TimeSeries , D3BaseType , { } > => {
408
+ yScale : D3ScaleLinear < number , number > ) : D3Selection < D3BaseType , TimeSeries , D3BaseType , { } > => {
410
409
const resultingSelection = selection
411
410
. append ( 'g' ) // Group each line so we can add dots to this group latter
412
- . attr ( 'class' , ( timeSeries : TimeSeries ) => `line line-group ${ index } line- ${ timeSeries . key } ` )
411
+ . attr ( 'class' , ( timeSeries : TimeSeries ) => `line line-${ timeSeries . key } ` )
413
412
. style ( 'opacity' , '0' )
414
413
. append ( 'path' ) // Draw one path for every item in the data set
415
414
. style ( 'pointer-events' , 'none' )
@@ -438,11 +437,6 @@ export class LineChartService {
438
437
const drawSinglePointsDots = ( data : TimeSeries [ ] ,
439
438
xScale : D3ScaleTime < number , number > ,
440
439
yScale : D3ScaleLinear < number , number > ) : void => {
441
- // Remove old dots
442
- this . _chartContentContainer
443
- . select ( '.single-dots' )
444
- . remove ( ) ;
445
-
446
440
const minDate = xScale . domain ( ) [ 0 ] ;
447
441
const maxDate = xScale . domain ( ) [ 1 ] ;
448
442
@@ -495,11 +489,6 @@ export class LineChartService {
495
489
const addDataPointsToChart = ( timeSeries : TimeSeries [ ] ,
496
490
xScale : D3ScaleTime < number , number > ,
497
491
yScale : D3ScaleLinear < number , number > ) : void => {
498
- // Remove old dots
499
- this . _chartContentContainer
500
- . select ( '.dots' )
501
- . remove ( ) ;
502
-
503
492
this . _chartContentContainer
504
493
. append ( 'g' )
505
494
. attr ( 'class' , 'dots' )
@@ -547,17 +536,21 @@ export class LineChartService {
547
536
index : number ) : void => {
548
537
if ( index === 0 ) {
549
538
// Remove after resize
550
- chart . select ( '.lines' ) . remove ( ) ;
539
+ chart . selectAll ( '.lines' ) . remove ( ) ;
540
+ // Remove old dots
541
+ this . _chartContentContainer . select ( '.single-dots' ) . remove ( ) ;
542
+ // Remove old dots
543
+ this . _chartContentContainer . select ( '.dots' ) . remove ( ) ;
551
544
}
552
545
// Create one group per line / data entry
553
546
this . _chartContentContainer
554
547
. append ( 'g' )
555
- . attr ( 'class' , ' lines' )
548
+ . attr ( 'class' , ` lines y-axis- ${ index } ` )
556
549
. selectAll ( '.line' ) // Get all lines already drawn
557
550
. data ( data , ( timeSeries : TimeSeries ) => timeSeries . key ) // ... for this data
558
551
. join ( enter => {
559
552
addDataPointsToXAxisCluster ( enter ) ;
560
- const lineSelection : any = drawLine ( enter , xScale , yScale , index ) ;
553
+ const lineSelection : any = drawLine ( enter , xScale , yScale ) ;
561
554
drawSinglePointsDots ( data , xScale , yScale ) ;
562
555
addDataPointsToChart ( data , xScale , yScale ) ;
563
556
return lineSelection ;
@@ -709,7 +702,7 @@ export class LineChartService {
709
702
// Update X axis with smooth transition
710
703
d3Select ( '.x-axis' ) . transition ( ) . call ( ( transition ) => this . updateXAxis ( transition , xScale ) ) ;
711
704
// Update Y axis with smooth transition
712
- const yNewScales = this . lineChartScaleService . getYScalesInRange ( data , minDate , maxDate , this . _height ) ;
705
+ const yNewScales = this . lineChartScaleService . getYScalesInTimeRange ( data , minDate , maxDate , this . _height ) ;
713
706
this . updateYAxes ( yNewScales ) ;
714
707
// Redraw lines and dots
715
708
yNewScales . forEach ( ( yScale , index ) => {
@@ -976,7 +969,8 @@ export class LineChartService {
976
969
977
970
const chart = svg . append ( 'g' ) // g = grouping element; group all other stuff into the chart
978
971
. attr ( 'id' , 'time-series-chart-drawing-area' )
979
- . attr ( 'transform' , `translate(${ this . _margin . left } , ${ this . _margin . top } )` ) ; // translates the origin to the top left corner (default behavior of D3)
972
+ // translates the origin to the top left corner (default behavior of D3)
973
+ . attr ( 'transform' , `translate(${ this . _margin . left } , ${ this . _margin . top } )` ) ;
980
974
981
975
svg . append ( 'g' )
982
976
. attr ( 'id' , 'time-series-chart-legend' )
@@ -1046,7 +1040,8 @@ export class LineChartService {
1046
1040
// Add the X-Axis to the chart
1047
1041
chart . append ( 'g' ) // new group for the X-Axis (see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g)
1048
1042
. attr ( 'class' , 'axis x-axis' ) // a css class to style it later
1049
- . attr ( 'transform' , `translate(0, ${ this . _height } )` ) // even if the D3 method called `axisBottom` we have to move it to the bottom by ourselves
1043
+ // even if the D3 method called `axisBottom` we have to move it to the bottom by ourselves
1044
+ . attr ( 'transform' , `translate(0, ${ this . _height } )` )
1050
1045
. call ( xAxis ) ;
1051
1046
}
1052
1047
@@ -1181,7 +1176,8 @@ export class LineChartService {
1181
1176
. tickSize ( drawingAreaWidth ) // background line over complete chart width
1182
1177
)
1183
1178
. attr ( 'transform' , 'translate(0, 0)' ) // move the axis to the left
1184
- . call ( g => g . selectAll ( '.tick:not(:first-of-type) line' ) // make all line dotted, except the one on the bottom as this will indicate the x-axis
1179
+ // make all line dotted, except the one on the bottom as this will indicate the x-axis
1180
+ . call ( g => g . selectAll ( '.tick:not(:first-of-type) line' )
1185
1181
. attr ( 'stroke-opacity' , strokeOpacity )
1186
1182
. attr ( 'stroke-dasharray' , '1,1' ) )
1187
1183
. call ( g => g . selectAll ( '.tick text' ) // move the text a little so it does not overlap with the lines
0 commit comments