1
1
import ScatterplotRenderer from '../scatterplot/ScatterplotRenderer.js' ;
2
+ import * as d3 from 'd3' ;
2
3
3
4
class ControlRenderer extends ScatterplotRenderer {
4
5
color = '#0ea5e9' ;
5
6
timeScale = 'linear' ;
7
+ connectDots = false ;
6
8
7
9
constructor ( data , avgMovingRange ) {
8
10
super ( data ) ;
@@ -21,10 +23,17 @@ class ControlRenderer extends ScatterplotRenderer {
21
23
renderGraph ( graphElementSelector ) {
22
24
this . drawSvg ( graphElementSelector ) ;
23
25
this . drawAxes ( ) ;
24
- this . drawArea ( ) ;
25
26
this . avgLeadTime = this . getAvgLeadTime ( ) ;
26
27
this . topLimit = Math . ceil ( this . avgLeadTime + this . avgMovingRange * 2.66 ) ;
28
+
27
29
this . bottomLimit = Math . ceil ( this . avgLeadTime - this . avgMovingRange * 2.66 ) ;
30
+ const maxY = this . y . domain ( ) [ 1 ] > this . topLimit ? this . y . domain ( ) [ 1 ] : this . topLimit + 2 ;
31
+ let minY = this . y . domain ( ) [ 0 ] ;
32
+ if ( this . bottomLimit > 0 ) {
33
+ minY = this . y . domain ( ) [ 0 ] < this . bottomLimit ? this . y . domain ( ) [ 0 ] : this . bottomLimit - 2 ;
34
+ }
35
+ this . y . domain ( [ minY , maxY ] ) ;
36
+ this . drawArea ( ) ;
28
37
this . drawHorizontalLine ( this . y , this . topLimit , 'purple' , 'top' ) ;
29
38
this . drawHorizontalLine ( this . y , this . avgLeadTime , 'orange' , 'center' ) ;
30
39
this . bottomLimit > 0 && this . drawHorizontalLine ( this . y , this . bottomLimit , 'purple' , 'bottom' ) ;
@@ -45,14 +54,41 @@ class ControlRenderer extends ScatterplotRenderer {
45
54
. style ( 'cursor' , 'pointer' )
46
55
. attr ( 'fill' , this . color )
47
56
. on ( 'click' , ( event , d ) => this . handleMouseClickEvent ( event , d ) ) ;
57
+ this . connectDots && this . generateLines ( chartArea , data , x , y ) ;
48
58
}
49
59
50
60
getAvgLeadTime ( ) {
51
61
return Math . ceil ( this . data . reduce ( ( acc , curr ) => acc + curr . leadTime , 0 ) / this . data . length ) ;
52
62
}
53
63
64
+ generateLines ( chartArea , data , x , y ) {
65
+ // Define the line generator
66
+ const line = d3
67
+ . line ( )
68
+ . x ( ( d ) => x ( d . deliveredDate ) )
69
+ . y ( ( d ) => y ( d . leadTime ) ) ;
70
+ chartArea
71
+ . selectAll ( 'dot-line' )
72
+ . data ( [ data ] )
73
+ . enter ( )
74
+ . append ( 'path' )
75
+ . attr ( 'class' , 'dot-line' )
76
+ . attr ( 'id' , ( d ) => `line-${ d . ticketId } ` )
77
+ . attr ( 'd' , line )
78
+ . attr ( 'stroke' , 'black' )
79
+ . attr ( 'stroke-width' , 2 )
80
+ . attr ( 'fill' , 'none' ) ;
81
+ }
82
+
54
83
updateGraph ( domain ) {
55
84
this . updateChartArea ( domain ) ;
85
+ if ( this . connectDots ) {
86
+ const line = d3
87
+ . line ( )
88
+ . x ( ( d ) => this . currentXScale ( d . deliveredDate ) )
89
+ . y ( ( d ) => this . currentYScale ( d . leadTime ) ) ;
90
+ this . chartArea . selectAll ( '.dot-line' ) . attr ( 'd' , line ) ;
91
+ }
56
92
this . drawHorizontalLine ( this . currentYScale , this . topLimit , 'purple' , 'top' ) ;
57
93
this . drawHorizontalLine ( this . currentYScale , this . avgLeadTime , 'orange' , 'center' ) ;
58
94
this . bottomLimit > 0 && this . drawHorizontalLine ( this . currentYScale , this . bottomLimit , 'purple' , 'bottom' ) ;
0 commit comments