@@ -27,7 +27,7 @@ var lineGraph = function chart(mode) {
27
27
*/
28
28
var cs = {
29
29
palette : {
30
- lineFill : '#ffcdcd' ,
30
+ lineFill : [ '#ffcdcd' , '#005792' ] ,
31
31
pointFill : '#005792' ,
32
32
pointStroke : '#d1f4fa'
33
33
} ,
@@ -49,18 +49,23 @@ var lineGraph = function chart(mode) {
49
49
* @param {Object } points (svg element)
50
50
*/
51
51
var enter = function enter ( points , path ) {
52
- if ( mode === 'init' ) path . enter ( ) . append ( 'path' ) . attr ( 'd' , cs . lineFunction ( _this . ds ) ) . attr ( 'fill' , 'none' ) . attr ( 'stroke' , cs . palette . lineFill ) . attr ( 'stroke-width' , 3 ) ;
53
-
54
- points . enter ( ) . append ( 'circle' ) . attr ( 'class' , _this . selector ) . attr ( 'r' , 2 ) . on ( 'mouseover' , function ( d ) {
55
- _this . addTooltip ( d , window . event ) ;
56
- } ) . on ( 'mouseout' , function ( d ) {
57
- _this . removeTooltip ( d ) ;
58
- } ) . attr ( 'cx' , function ( d ) {
59
- return cs . x . scale ( d . dim ) + cs . y . axisWidth + 5 ;
60
- } ) . attr ( 'cy' , function ( d ) {
61
- return cs . y . scale ( d . metric ) ;
52
+ _this . metric . forEach ( function ( e , i ) {
53
+ path [ i ] . enter ( ) . append ( 'path' ) . attr ( 'd' , cs . lineFunction [ i ] ( _this . ds ) ) . attr ( 'fill' , 'none' ) . attr ( 'id' , 'p' + i ) . attr ( 'stroke' , cs . palette . lineFill [ i ] ) . attr ( 'stroke-width' , 3 ) ;
62
54
} ) ;
63
- return points ;
55
+
56
+ // points.enter()
57
+ // .append('circle')
58
+ // .attr('class', this.selector)
59
+ // .attr('r', 2)
60
+ // .on('mouseover', (d) => {
61
+ // this.addTooltip(d, window.event);
62
+ // })
63
+ // .on('mouseout', (d) => {
64
+ // this.removeTooltip(d);
65
+ // })
66
+ // .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
67
+ // .attr('cy', d => cs.y.scale(d.metric[0]));
68
+ // return points;
64
69
} ;
65
70
/**
66
71
* Runs when a value of an element in dataset is changed
@@ -69,18 +74,16 @@ var lineGraph = function chart(mode) {
69
74
* @param {Object } points (svg element)
70
75
*/
71
76
var transition = function transition ( points , path ) {
72
- path . transition ( ) . attr ( 'd' , cs . lineFunction ( _this . ds ) ) ;
73
-
74
- points . transition ( ) . attr ( 'cx' , function ( d ) {
75
- return cs . x . scale ( d . dim ) + cs . y . axisWidth + 5 ;
76
- } ) . attr ( 'cy' , function ( d ) {
77
- return cs . y . scale ( d . metric ) ;
78
- } ) . attr ( 'cx' , function ( d ) {
79
- return cs . x . scale ( d . dim ) + cs . y . axisWidth + 5 ;
80
- } ) . attr ( 'cy' , function ( d ) {
81
- return cs . y . scale ( d . metric ) ;
77
+ _this . metric . forEach ( function ( e , i ) {
78
+ path [ i ] . transition ( ) . attr ( 'd' , cs . lineFunction [ i ] ( _this . ds ) ) ;
82
79
} ) ;
83
- return points ;
80
+
81
+ // points.transition()
82
+ // .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
83
+ // .attr('cy', d => cs.y.scale(d.metric[0]))
84
+ // .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
85
+ // .attr('cy', d => cs.y.scale(d.metric[0]));
86
+ // return points;
84
87
} ;
85
88
86
89
/**
@@ -91,7 +94,9 @@ var lineGraph = function chart(mode) {
91
94
*/
92
95
var exit = function exit ( points , path ) {
93
96
points . exit ( ) . remove ( ) ;
94
- path . exit ( ) . remove ( ) ;
97
+ _this . metric . forEach ( function ( e , i ) {
98
+ path [ i ] . exit ( ) . remove ( ) ;
99
+ } ) ;
95
100
return points ;
96
101
} ;
97
102
@@ -100,9 +105,8 @@ var lineGraph = function chart(mode) {
100
105
* @member buildScales
101
106
* @function
102
107
*/
103
- var buildScales = function buildScales ( ) {
108
+ var buildScales = function buildScales ( cs ) {
104
109
cs . y . scale = d3 . scaleLinear ( ) . domain ( [ _this . min , _this . max ] ) . range ( [ _this . displayHeight - cs . x . axisHeight , _this . header ] ) ;
105
- cs . y . axis = d3 . axisLeft ( ) . ticks ( cs . y . ticks , 's' ) . scale ( cs . y . scale ) ;
106
110
_this . ds . forEach ( function ( t ) {
107
111
return cs . x . domain . push ( t . dim ) ;
108
112
} ) ;
@@ -116,22 +120,31 @@ var lineGraph = function chart(mode) {
116
120
* @member drawAxis
117
121
* @function
118
122
*/
119
- var drawAxis = function drawAxis ( ) {
123
+ var drawAxis = function drawAxis ( cs ) {
120
124
cs . x . axis = d3 . axisBottom ( ) . scale ( cs . x . scale ) ;
121
125
cs . x . xOffset = cs . y . axisWidth + 5 ;
122
126
cs . x . yOffset = _this . displayHeight - cs . x . axisHeight ;
127
+ cs . y . axis = d3 . axisLeft ( ) . ticks ( cs . y . ticks , 's' ) . scale ( cs . y . scale ) ;
123
128
cs . y . xOffset = cs . y . axisWidth ;
124
129
cs . y . yOffset = 0 ;
130
+ svgContainer . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . x . xOffset + ', ' + cs . x . yOffset + ')' ) . call ( cs . x . axis ) ;
131
+ svgContainer . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . y . xOffset + ',' + cs . y . yOffset + ')' ) . call ( cs . y . axis ) ;
125
132
} ;
126
133
127
- cs . lineFunction = d3 . line ( ) . x ( function ( d ) {
128
- return cs . x . scale ( d . dim ) + cs . y . axisWidth + 5 ;
129
- } ) . y ( function ( d ) {
130
- return cs . y . scale ( d . metric ) ;
134
+ cs . lineFunction = [ ] ;
135
+ this . metric . forEach ( function ( e , i ) {
136
+ cs . lineFunction . push ( d3 . line ( ) . x ( function ( d ) {
137
+ return cs . x . scale ( d . dim ) + cs . y . axisWidth + 5 ;
138
+ } ) . y ( function ( d ) {
139
+ return cs . y . scale ( d . metric [ i ] ) ;
140
+ } ) ) ;
131
141
} ) ;
132
142
133
143
var points = svgContainer . selectAll ( 'circle' ) . data ( this . ds ) ;
134
- var path = svgContainer . selectAll ( 'path' ) . data ( this . ds ) ;
144
+ var path = [ ] ;
145
+ this . metric . forEach ( function ( e , i ) {
146
+ path . push ( svgContainer . selectAll ( 'path#p' + i ) . data ( _this . ds ) ) ;
147
+ } ) ;
135
148
136
149
cs = this . setOverrides ( cs , this . chartData . overrides ) ;
137
150
@@ -141,9 +154,6 @@ var lineGraph = function chart(mode) {
141
154
transition ( points , path ) ;
142
155
exit ( points , path ) ;
143
156
144
- svgContainer . append ( 'g' ) . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . x . xOffset + ', ' + cs . x . yOffset + ')' ) . call ( cs . x . axis ) ;
145
- svgContainer . append ( 'g' ) . append ( 'g' ) . attr ( 'class' , 'axis' ) . attr ( 'transform' , 'translate(' + cs . y . xOffset + ',' + cs . y . yOffset + ')' ) . call ( cs . y . axis ) ;
146
-
147
157
return cs ;
148
158
} ;
149
159
0 commit comments