Skip to content

Commit 05713b5

Browse files
added bubble chart
1 parent 92a78ee commit 05713b5

File tree

6 files changed

+618
-319
lines changed

6 files changed

+618
-319
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@ export default {
9292
}
9393
}
9494
```
95+
Bubble Charts require three metrics (v1, v2, and v3). These should be passed as triplets
96+
97+
```JavaScript
98+
export default {
99+
name: 'example',
100+
data () {
101+
return {
102+
chartData: {
103+
chartType: "bubbleChart",
104+
selector: "chart",
105+
title: "Important Data",
106+
width: 400,
107+
height: 200,
108+
triplet: ['count', 'pyCount', 'revenue']
109+
data: [
110+
{'count': 120,
111+
'fruit': 'apples'},
112+
{'count': 250,
113+
'fruit': 'oranges'}
114+
]
115+
}
116+
}
117+
}
118+
}
119+
```
95120
### Overrides
96121
If you need to override any of the default values of the charts (pallette colors, ticks, margins, etc) you can pass an overrides object to you chartData.
97122

@@ -131,6 +156,7 @@ chartData: {
131156
* scatterPlot: a graph in which the values of two variables are plotted along two axes, the pattern of the resulting points revealing any correlation present.
132157
* pieChart: a chart in which a circle is divided into slices to illustrate proportion
133158
* areaChart: a chart which displays graphically quantitative data
159+
* bubleChart: a bubble chart is a variation of a scatter chart in which the data points are replaced with bubbles, and an additional dimension of the data is represented in the size of the bubbles.
134160

135161
### Charts that support two or more metrics
136162
* barChart

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "v-chart-plugin",
33
"main": "./dist/module/v-chart-plugin.js",
4-
"version": "0.2.15",
4+
"version": "0.3.0",
55
"description": "This plugin is designed to allow Vue.js developers to incorporate fully reactive and customizable charts into your applications. Uses D3.js for charting.",
66
"keywords": [
77
"vue",

src/components/chartExample.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default {
8282
subtitle: "Sales by month",
8383
width: 600,
8484
height: 500,
85-
metric: ["total", "forecast", "yoy"],
85+
triplet: ["total", "forecast", "yoy"],
8686
data: sales,
8787
goal: 500,
8888
legends: {

src/import/bubbleChart.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,9 @@ const lineGraph = function chart(mode) {
5555
points.enter()
5656
.append('circle')
5757
.attr('class', this.selector)
58-
.attr('r', d => cs.r.scale(d.metric[2]))
59-
.on('mouseover', (d) => {
60-
this.addTooltip(d, window.event);
61-
})
62-
.on('mouseout', (d) => {
63-
this.removeTooltip(d);
64-
})
65-
.attr('cx', d => cs.x.scale(d.metric[0]) + cs.y.axisWidth + 5)
66-
.attr('cy', d => cs.y.scale(d.metric[1]));
58+
.attr('r', d => cs.r.scale(d.metric[0][this.triplet[2]]))
59+
.attr('cx', d => cs.x.scale(d.metric[0][this.triplet[0]]) + cs.y.axisWidth + 5)
60+
.attr('cy', d => cs.y.scale(d.metric[0][this.triplet[1]]));
6761
return points;
6862
};
6963
/**
@@ -74,11 +68,9 @@ const lineGraph = function chart(mode) {
7468
*/
7569
const transition = (points) => {
7670
points.transition()
77-
.attr('r', d => cs.r.scale(d.metric[2]))
78-
.attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
79-
.attr('cy', d => cs.y.scale(d.metric[0]))
80-
.attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
81-
.attr('cy', d => cs.y.scale(d.metric[1]));
71+
.attr('r', d => cs.r.scale(d.metric[0][this.triplet[2]]))
72+
.attr('cx', d => cs.x.scale(d.metric[0][this.triplet[0]]) + cs.y.axisWidth + 5)
73+
.attr('cy', d => cs.y.scale(d.metric[0][this.triplet[1]]));
8274
return points;
8375
};
8476

@@ -100,13 +92,13 @@ const lineGraph = function chart(mode) {
10092
*/
10193
const buildScales = cs => {
10294
cs.y.scale = d3.scaleLinear()
103-
.domain([this.min, this.max])
95+
.domain([this.minTriplet.v1, this.maxTriplet.v1])
10496
.range([this.displayHeight - cs.x.axisHeight, this.header]);
10597
cs.x.scale = d3.scaleLinear()
106-
.domain([this.min, this.max])
98+
.domain([this.minTriplet.v2, this.maxTriplet.v2])
10799
.range([0, this.width]);
108100
cs.r.scale = d3.scaleLinear()
109-
.domain([0, 2])
101+
.domain([this.minTriplet.v3, this.maxTriplet.v3])
110102
.range([0, 20]);
111103
};
112104
/**

src/v-chart-plugin.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const Chart = {
206206
return ds.data.map((d) => {
207207
const td = { metric: [] };
208208
if (!ds.metric[0])
209-
td.metric[0] = d;
209+
td.metric[0] = d || 0;
210210
else {
211211
ds.metric.forEach(function(e, i){
212212
td.metric[i] = d[e] || 0;
@@ -230,7 +230,16 @@ const Chart = {
230230
* @returns {array} Metrics
231231
*/
232232
metric() {
233-
return (Array.isArray(this.chartData.metric)) ? this.chartData.metric : new Array(this.chartData.metric);
233+
const metric = (Array.isArray(this.chartData.metric)) ? this.chartData.metric : new Array(this.chartData.metric);
234+
return metric;
235+
},
236+
/**
237+
* triplet getter function
238+
* @memberOf Chart
239+
* @returns {array} Metrics
240+
*/
241+
triplet() {
242+
return this.chartData.triplet;
234243
},
235244
/**
236245
* Height getter function
@@ -264,19 +273,58 @@ const Chart = {
264273
});
265274
return max;
266275
},
276+
/**
277+
* Get the maxium value for triplet
278+
* @memberOf Chart
279+
* @returns {Array} Max values for triplet
280+
*/
281+
maxTriplet() {
282+
const max = {
283+
v1: 0,
284+
v2: 0,
285+
v3: 0
286+
};
287+
this.ds.forEach(e => {
288+
max.v1 = max.v1 > e.metric[0][this.triplet[0]] ? max.v1 : e.metric[0][this.triplet[0]];
289+
max.v2 = max.v2 > e.metric[0][this.triplet[1]] ? max.v2 : e.metric[0][this.triplet[1]];
290+
max.v3 = max.v3 > e.metric[0][this.triplet[2]] ? max.v3 : e.metric[0][this.triplet[2]];
291+
});
292+
return max;
293+
},
267294
/**
268295
* Get the minimum value for dataset
269296
* @memberOf Chart
270297
* @returns {number} Min value for metric
271298
*/
272299
min() {
273-
let max = 0;
274300
var results = [];
275301
this.ds.forEach(e => {
276302
results = results.concat([...e.metric]);
277303
});
278304
return Math.min(...results.map(o => o));
279305
},
306+
/**
307+
* Get the minimum value for triplet
308+
* @memberOf Chart
309+
* @returns {Array} Min values for triplet
310+
*/
311+
minTriplet() {
312+
var results = {
313+
v1: [],
314+
v2: [],
315+
v3: []
316+
};
317+
this.ds.forEach(e => {
318+
results.v1.push(e.metric[0][this.triplet[0]])
319+
results.v2.push(e.metric[0][this.triplet[1]])
320+
results.v3.push(e.metric[0][this.triplet[2]])
321+
})
322+
return {
323+
v1: (Math.min(...results.v1.map(o => o))),
324+
v2: (Math.min(...results.v2.map(o => o))),
325+
v3: (Math.min(...results.v3.map(o => o)))
326+
};
327+
},
280328
/**
281329
* Gets the height of the dispaly area
282330
* @memberOf Chart

0 commit comments

Comments
 (0)