@@ -273,15 +273,15 @@ export class LineChartService {
273273 visibleDots
274274 . each ( ( timeSeriesPoint : TimeSeriesPoint , index : number , nodes : D3BaseType [ ] ) => {
275275 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
278278 } ) ;
279279 if ( index === 0 ) {
280280 testAgent = generateTooltipTestAgentRow ( timeSeriesPoint ) ;
281281 }
282282 } ) ;
283283 tempArray
284- . sort ( ( a , b ) => b . value - a . value )
284+ . sort ( ( a , b ) => a . yPosition - b . yPosition )
285285 . forEach ( elem => tableBody . append ( elem . htmlNode ) ) ;
286286 tableBody . append ( testAgent ) ;
287287
@@ -405,11 +405,10 @@ export class LineChartService {
405405
406406 const drawLine = ( selection : D3Selection < D3BaseType , TimeSeries , D3BaseType , { } > ,
407407 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 , { } > => {
410409 const resultingSelection = selection
411410 . 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 } ` )
413412 . style ( 'opacity' , '0' )
414413 . append ( 'path' ) // Draw one path for every item in the data set
415414 . style ( 'pointer-events' , 'none' )
@@ -438,11 +437,6 @@ export class LineChartService {
438437 const drawSinglePointsDots = ( data : TimeSeries [ ] ,
439438 xScale : D3ScaleTime < number , number > ,
440439 yScale : D3ScaleLinear < number , number > ) : void => {
441- // Remove old dots
442- this . _chartContentContainer
443- . select ( '.single-dots' )
444- . remove ( ) ;
445-
446440 const minDate = xScale . domain ( ) [ 0 ] ;
447441 const maxDate = xScale . domain ( ) [ 1 ] ;
448442
@@ -495,11 +489,6 @@ export class LineChartService {
495489 const addDataPointsToChart = ( timeSeries : TimeSeries [ ] ,
496490 xScale : D3ScaleTime < number , number > ,
497491 yScale : D3ScaleLinear < number , number > ) : void => {
498- // Remove old dots
499- this . _chartContentContainer
500- . select ( '.dots' )
501- . remove ( ) ;
502-
503492 this . _chartContentContainer
504493 . append ( 'g' )
505494 . attr ( 'class' , 'dots' )
@@ -547,17 +536,21 @@ export class LineChartService {
547536 index : number ) : void => {
548537 if ( index === 0 ) {
549538 // 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 ( ) ;
551544 }
552545 // Create one group per line / data entry
553546 this . _chartContentContainer
554547 . append ( 'g' )
555- . attr ( 'class' , ' lines' )
548+ . attr ( 'class' , ` lines y-axis- ${ index } ` )
556549 . selectAll ( '.line' ) // Get all lines already drawn
557550 . data ( data , ( timeSeries : TimeSeries ) => timeSeries . key ) // ... for this data
558551 . join ( enter => {
559552 addDataPointsToXAxisCluster ( enter ) ;
560- const lineSelection : any = drawLine ( enter , xScale , yScale , index ) ;
553+ const lineSelection : any = drawLine ( enter , xScale , yScale ) ;
561554 drawSinglePointsDots ( data , xScale , yScale ) ;
562555 addDataPointsToChart ( data , xScale , yScale ) ;
563556 return lineSelection ;
@@ -709,7 +702,7 @@ export class LineChartService {
709702 // Update X axis with smooth transition
710703 d3Select ( '.x-axis' ) . transition ( ) . call ( ( transition ) => this . updateXAxis ( transition , xScale ) ) ;
711704 // 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 ) ;
713706 this . updateYAxes ( yNewScales ) ;
714707 // Redraw lines and dots
715708 yNewScales . forEach ( ( yScale , index ) => {
@@ -976,7 +969,8 @@ export class LineChartService {
976969
977970 const chart = svg . append ( 'g' ) // g = grouping element; group all other stuff into the chart
978971 . 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 } )` ) ;
980974
981975 svg . append ( 'g' )
982976 . attr ( 'id' , 'time-series-chart-legend' )
@@ -1046,7 +1040,8 @@ export class LineChartService {
10461040 // Add the X-Axis to the chart
10471041 chart . append ( 'g' ) // new group for the X-Axis (see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g)
10481042 . 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 } )` )
10501045 . call ( xAxis ) ;
10511046 }
10521047
@@ -1181,7 +1176,8 @@ export class LineChartService {
11811176 . tickSize ( drawingAreaWidth ) // background line over complete chart width
11821177 )
11831178 . 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' )
11851181 . attr ( 'stroke-opacity' , strokeOpacity )
11861182 . attr ( 'stroke-dasharray' , '1,1' ) )
11871183 . call ( g => g . selectAll ( '.tick text' ) // move the text a little so it does not overlap with the lines
0 commit comments