1
1
<template >
2
2
<div >
3
- <h2 class =" title is-size-5" ><span class =" icon mr-3" ><i class =" fas fa-cogs" ></i ></span >Chart Settings</h2 >
4
- <div class =" columns" >
5
- <div class =" column is-one-third" >
6
- <div class =" field" >
7
- <label class =" label" >X Axis</label >
8
- <div class =" control" >
9
- <div class =" select" >
10
- <select v-model =" dataColumns.xAxis" @change =" updateDataset()" >
11
- <option :value =" null" >Select column</option >
12
- <option v-for =" (header, offset) in continuousHeaders"
13
- :key =" offset"
14
- :value =" header.offset"
15
- >{{ header.title }}</option >
16
- </select >
3
+ <section class =" section" >
4
+ <div class =" container" >
5
+ <h2 class =" title is-size-5" ><span class =" icon mr-3" ><i class =" fas fa-cogs" ></i ></span >Chart Properties</h2 >
6
+ <div class =" columns" >
7
+ <div class =" column is-one-third" >
8
+ <div class =" field" >
9
+ <label class =" label" >X Axis</label >
10
+ <div class =" control" >
11
+ <div class =" select" >
12
+ <select v-model =" settings.dataColumns.xAxis" @change =" updateDataset()" >
13
+ <option :value =" null" >Select column</option >
14
+ <option v-for =" (header, offset) in continuousHeaders"
15
+ :key =" offset"
16
+ :value =" header.offset"
17
+ >{{ header.title }}</option >
18
+ </select >
19
+ </div >
20
+ </div >
17
21
</div >
18
22
</div >
19
- </ div >
20
- </ div >
21
- < div class =" column is-one-third " >
22
- <div class =" field " >
23
- < label class =" label " >Y Axis</ label >
24
- < div class = " control " >
25
- < div class = " select " >
26
- < select v-model = " dataColumns.yAxis " @change = " updateDataset() " >
27
- < option :value = " null " >Select column</ option >
28
- < option v-for = " ( header, offset) in continuousHeaders "
29
- :key = " offset "
30
- :value = " header.offset "
31
- >{{ header.title }}</ option >
32
- </select >
23
+ < div class = " column is-one-third " >
24
+ < div class = " field " >
25
+ < label class =" label " >Y Axis</ label >
26
+ <div class =" control " >
27
+ < div class =" select " >
28
+ < select v-model = " settings.dataColumns.yAxis " @change = " updateDataset() " >
29
+ < option :value = " null " >Select column</ option >
30
+ < option v-for = " (header, offset) in continuousHeaders "
31
+ :key = " offset "
32
+ :value = " header. offset"
33
+ >{{ header.title }}</ option >
34
+ </ select >
35
+ </ div >
36
+ </div >
33
37
</div >
34
38
</div >
35
- </ div >
36
- </ div >
37
- < div class =" column is-one-third " >
38
- <div class =" field " >
39
- < label class =" label " >Scale</ label >
40
- < div class = " control " >
41
- < div class = " select " >
42
- < select v-model = " dataColumns.scale " @change = " updateDataset() " >
43
- < option :value = " null " >Select column</ option >
44
- < option v-for = " ( header, offset) in continuousHeaders "
45
- :key = " offset "
46
- :value = " header.offset "
47
- >{{ header.title }}</ option >
48
- </select >
39
+ < div class = " column is-one-third " >
40
+ < div class = " field " >
41
+ < label class =" label " >Scale</ label >
42
+ <div class =" control " >
43
+ < div class =" select " >
44
+ < select v-model = " settings.dataColumns.scale " @change = " updateDataset() " >
45
+ < option :value = " null " >Select column</ option >
46
+ < option v-for = " (header, offset) in continuousHeaders "
47
+ :key = " offset "
48
+ :value = " header. offset"
49
+ >{{ header.title }}</ option >
50
+ </ select >
51
+ </ div >
52
+ </div >
49
53
</div >
50
54
</div >
51
55
</div >
52
- </div >
53
- </div >
54
- <div class =" columns mb-5" >
55
- <div class =" column is-one-third" >
56
- <div class =" field" >
57
- <label class =" label" >Bubble Radius</label >
58
- <div class =" control" >
59
- <input v-model =" bubbleRadius" class =" slider is-circle has-output is-fullwidth" step =" 1" min =" 1" max =" 50" type =" range" @change =" updateDataset()" />
60
- <output >{{ bubbleRadius }}</output >
61
- </div >
62
- </div >
63
- </div >
64
- <div class =" column is-one-third" >
65
- <div class =" field" >
66
- <label class =" label" >Bubble Stroke</label >
67
- <div class =" control" >
68
- <input v-model =" bubbleStroke" class =" slider is-circle has-output is-fullwidth" step =" 1" min =" 1" max =" 5" type =" range" @change =" updateBubbleStroke()" />
69
- <output >{{ bubbleStroke }}</output >
56
+ <div class =" columns mb-5" >
57
+ <div class =" column is-one-third" >
58
+ <div class =" field" >
59
+ <label class =" label" >Radius</label >
60
+ <div class =" control" >
61
+ <input v-model =" settings.radius" class =" slider is-circle has-output is-fullwidth" step =" 1" min =" 1" max =" 50" type =" range" @change =" updateDataset()" />
62
+ <output >{{ settings.radius }}</output >
63
+ </div >
64
+ </div >
70
65
</div >
71
- </div >
72
- </div >
73
- <div class =" column is-one-third" >
74
- <div class =" field" >
75
- <label class =" label" >Bubble Color</label >
76
- <div class =" control" >
77
- <div class =" dropdown" :class =" { 'is-active' : colorPickerOpen }" >
78
- <div class =" dropdown-trigger" >
79
- <span class =" button" aria-haspopup =" true" aria-controls =" dropdown-menu2" @click =" colorPickerOpen = !colorPickerOpen" >
80
- <span class =" tag mx-2 px-5" :style =" { background: bubbleColorRgbString }" ></span >
81
- <span class =" icon is-small" >
82
- <i class =" fas fa-angle-down" aria-hidden =" true" ></i >
83
- </span >
84
- </span >
66
+ <div class =" column is-one-third" >
67
+ <div class =" field" >
68
+ <label class =" label" >Stroke</label >
69
+ <div class =" control" >
70
+ <input v-model =" settings.stroke" class =" slider is-circle has-output is-fullwidth" step =" 1" min =" 1" max =" 5" type =" range" @change =" updateStroke()" />
71
+ <output >{{ settings.stroke }}</output >
85
72
</div >
86
- <div class =" dropdown-menu" role =" menu" >
87
- <div class =" dropdown-content" >
88
- <div class =" dropdown-item" >
89
- <div >
90
- <input v-model =" bubbleColor.r" class =" slider is-danger is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateBubbleColor()" />
91
- <output >{{ bubbleColor.r }}</output >
92
- </div >
93
- <div >
94
- <input v-model =" bubbleColor.g" class =" slider is-success is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateBubbleColor()" />
95
- <output >{{ bubbleColor.g }}</output >
96
- </div >
97
- <div >
98
- <input v-model =" bubbleColor.b" class =" slider is-info is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateBubbleColor()" />
99
- <output >{{ bubbleColor.b }}</output >
73
+ </div >
74
+ </div >
75
+ <div class =" column is-one-third" >
76
+ <div class =" field" >
77
+ <label class =" label" >Color</label >
78
+ <div class =" control" >
79
+ <div class =" dropdown" :class =" { 'is-active' : colorPickerOpen }" >
80
+ <div class =" dropdown-trigger" >
81
+ <span class =" button" aria-haspopup =" true" aria-controls =" dropdown-menu2" @click =" colorPickerOpen = !colorPickerOpen" >
82
+ <span class =" tag mx-2 px-5" :style =" { background: rgbColorString }" ></span >
83
+ <span class =" icon is-small" >
84
+ <i class =" fas fa-angle-down" aria-hidden =" true" ></i >
85
+ </span >
86
+ </span >
87
+ </div >
88
+ <div class =" dropdown-menu" role =" menu" >
89
+ <div class =" dropdown-content" >
90
+ <div class =" dropdown-item" >
91
+ <div >
92
+ <input v-model =" settings.color.r" class =" slider is-danger is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateColor()" />
93
+ <output >{{ settings.color.r }}</output >
94
+ </div >
95
+ <div >
96
+ <input v-model =" settings.color.g" class =" slider is-success is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateColor()" />
97
+ <output >{{ settings.color.g }}</output >
98
+ </div >
99
+ <div >
100
+ <input v-model =" settings.color.b" class =" slider is-info is-circle has-output is-fullwidth" step =" 1" min =" 0" max =" 255" type =" range" @change =" updateColor()" />
101
+ <output >{{ settings.color.b }}</output >
102
+ </div >
103
+ </div >
100
104
</div >
101
105
</div >
102
106
</div >
105
109
</div >
106
110
</div >
107
111
</div >
108
- </div >
109
- <figure class =" mt-5" >
110
- <canvas id =" dataset-bubble-chart" width =" 550" height =" 550" ></canvas >
111
- </figure >
112
+ </section >
113
+ <section class =" section" >
114
+ <div class =" container" >
115
+ <figure class =" mt-5" >
116
+ <canvas id =" dataset-bubble-chart" width =" 550" height =" 550" ></canvas >
117
+ </figure >
118
+ </div >
119
+ </section >
112
120
</div >
113
121
</template >
114
122
@@ -118,19 +126,21 @@ import bus from '../bus';
118
126
export default {
119
127
data () {
120
128
return {
121
- dataColumns: {
122
- xAxis: null ,
123
- yAxis: null ,
124
- scale: null ,
125
- },
126
- bubbleColor: {
127
- r: 143 ,
128
- g: 59 ,
129
- b: 222 ,
129
+ settings: {
130
+ dataColumns: {
131
+ xAxis: null ,
132
+ yAxis: null ,
133
+ scale: null ,
134
+ },
135
+ radius: 5 ,
136
+ stroke: 2 ,
137
+ color: {
138
+ r: 143 ,
139
+ g: 59 ,
140
+ b: 222 ,
141
+ },
130
142
},
131
143
colorPickerOpen: false ,
132
- bubbleRadius: 5 ,
133
- bubbleStroke: 2 ,
134
144
chart: null ,
135
145
};
136
146
},
@@ -141,6 +151,9 @@ export default {
141
151
},
142
152
},
143
153
computed: {
154
+ rgbColorString () {
155
+ return ' rgb(' + Object .values (this .settings .color ).join (' , ' ) + ' )' ;
156
+ },
144
157
continuousHeaders () {
145
158
return this .dataset .header .map ((title , offset ) => {
146
159
return {
@@ -151,9 +164,6 @@ export default {
151
164
return Number ( this .dataset .data [0 ][offset]) == this .dataset .data [0 ][offset];
152
165
});
153
166
},
154
- bubbleColorRgbString () {
155
- return ' rgb(' + Object .values (this .bubbleColor ).join (' , ' ) + ' )' ;
156
- },
157
167
},
158
168
mounted () {
159
169
let context = document .getElementById (' dataset-bubble-chart' ).getContext (' 2d' );
@@ -164,8 +174,8 @@ export default {
164
174
datasets: [
165
175
{
166
176
label: ' Bubbles' ,
167
- borderColor: this .bubbleColorRgbString ,
168
- borderWidth: this .bubbleStroke ,
177
+ borderColor: this .rgbColorString ,
178
+ borderWidth: this .settings . stroke ,
169
179
fill: true ,
170
180
},
171
181
],
@@ -211,24 +221,24 @@ export default {
211
221
});
212
222
213
223
bus .$on (' dataset-imported' , (payload ) => {
214
- this .dataColumns .xAxis = null ;
215
- this .dataColumns .yAxis = null ;
216
- this .dataColumns .scale = null ;
224
+ this .settings . dataColumns .xAxis = null ;
225
+ this .settings . dataColumns .yAxis = null ;
226
+ this .settings . dataColumns .scale = null ;
217
227
218
228
this .updateDataset ();
219
229
});
220
230
},
221
231
methods: {
222
232
updateDataset () {
223
- if (this .dataColumns .xAxis !== null && this .dataColumns .yAxis !== null ) {
224
- this .chart .options .scales .xAxes [0 ].scaleLabel .labelString = this .dataset .header [this .dataColumns .xAxis ];
225
- this .chart .options .scales .yAxes [0 ].scaleLabel .labelString = this .dataset .header [this .dataColumns .yAxis ];
233
+ if (this .settings . dataColumns .xAxis !== null && this . settings .dataColumns .yAxis !== null ) {
234
+ this .chart .options .scales .xAxes [0 ].scaleLabel .labelString = this .dataset .header [this .settings . dataColumns .xAxis ];
235
+ this .chart .options .scales .yAxes [0 ].scaleLabel .labelString = this .dataset .header [this .settings . dataColumns .yAxis ];
226
236
227
- if (this .dataColumns .scale !== null ) {
237
+ if (this .settings . dataColumns .scale !== null ) {
228
238
let values = [];
229
239
230
240
this .dataset .data .forEach ((row ) => {
231
- values .push (row[this .dataColumns .scale ])
241
+ values .push (row[this .settings . dataColumns .scale ])
232
242
});
233
243
234
244
const min = Math .min (... values);
@@ -247,9 +257,9 @@ export default {
247
257
248
258
this .dataset .data .forEach ((row , offset ) => {
249
259
data .push ({
250
- x: row[this .dataColumns .xAxis ],
251
- y: row[this .dataColumns .yAxis ],
252
- r: weights[offset] * this .bubbleRadius ,
260
+ x: row[this .settings . dataColumns .xAxis ],
261
+ y: row[this .settings . dataColumns .yAxis ],
262
+ r: weights[offset] * this .settings . radius ,
253
263
});
254
264
});
255
265
@@ -260,13 +270,13 @@ export default {
260
270
261
271
this .chart .update ();
262
272
},
263
- updateBubbleStroke () {
264
- this .chart .data .datasets [0 ].borderWidth = this .bubbleStroke ;
273
+ updateStroke () {
274
+ this .chart .data .datasets [0 ].borderWidth = this .settings . stroke ;
265
275
266
276
this .chart .update ();
267
277
},
268
- updateBubbleColor () {
269
- this .chart .data .datasets [0 ].borderColor = this .bubbleColorRgbString ;
278
+ updateColor () {
279
+ this .chart .data .datasets [0 ].borderColor = this .rgbColorString ;
270
280
271
281
this .chart .update ();
272
282
},
0 commit comments