Skip to content

Commit 84b4174

Browse files
Merge pull request #145 from ignoreintuition/development
Development
2 parents 0495b6d + c7fb041 commit 84b4174

File tree

4 files changed

+79
-81
lines changed

4 files changed

+79
-81
lines changed

src/components/chartExample.vue

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ import sales from "../assets/data/sales";
4444
export default {
4545
name: "barChartExample",
4646
methods: {
47-
newItem: function(){
47+
newItem: function() {
4848
this.sales.push({
49-
"month": null,
50-
"year": null,
51-
"total": null,
52-
"actual": false
53-
})
49+
month: null,
50+
year: null,
51+
total: null,
52+
actual: false
53+
});
5454
},
55-
removeItem: function(d, e){
55+
removeItem: function(d, e) {
5656
e.preventDefault();
57-
this.sales.splice(d, 1)
57+
this.sales.splice(d, 1);
5858
}
5959
},
6060
data() {
@@ -73,12 +73,12 @@ export default {
7373
enabled: true,
7474
height: 25,
7575
width: 50
76-
},
76+
}
7777
},
7878
bubbleChartData: {
7979
chartType: "bubbleChart",
8080
selector: "chart",
81-
title: "Bar Chart",
81+
title: "Bubble Plot",
8282
subtitle: "Sales by month",
8383
width: 600,
8484
height: 500,
@@ -89,14 +89,14 @@ export default {
8989
enabled: true,
9090
height: 25,
9191
width: 50
92-
},
92+
}
9393
},
9494
lineGraphData: {
9595
chartType: "lineGraph",
9696
selector: "lineGraph",
9797
title: "Line Graph",
9898
width: 200,
99-
subtitle: "Sales by month",
99+
subtitle: "Sales by month",
100100
height: 200,
101101
goal: 500,
102102
metric: ["total", "forecast"],
@@ -106,12 +106,18 @@ export default {
106106
enabled: true,
107107
height: 25,
108108
width: 50
109-
},
109+
},
110+
overrides: {
111+
palette: {
112+
fill: ["#34495E", "#4fc08d"],
113+
stroke: "#41B883"
114+
}
115+
}
110116
},
111117
vBarChartData: {
112-
chartType: "vBarChart",
118+
chartType: "barChart",
113119
selector: "vChart",
114-
title: "Verticle Bar Chart",
120+
title: "Bar Chart",
115121
subtitle: "Sales by month",
116122
width: 300,
117123
height: 300,
@@ -122,7 +128,9 @@ export default {
122128
enabled: true,
123129
height: 25,
124130
width: 50
125-
},
131+
},
132+
overrides: {
133+
}
126134
},
127135
pieChartData: {
128136
chartType: "pieChart",
@@ -133,33 +141,16 @@ export default {
133141
height: 200,
134142
metric: "total",
135143
dim: "month",
136-
data: sales,
144+
data: sales
137145
},
138-
scatterPlotData: {
139-
chartType: "scatterPlot",
140-
selector: "scatterPlot",
141-
title: "Scatter Plot",
142-
subtitle: "Sales by month",
143-
width: 300,
144-
height: 200,
145-
metric: "total",
146-
dim: "month",
147-
data: sales,
148-
legends: {
149-
enabled: true,
150-
height: 25,
151-
width: 50
152-
},
153-
}
154-
155146
};
156147
}
157148
};
158149
</script>
159150

160151
<!-- Add "scoped" attribute to limit CSS to this component only -->
161-
<style>
162-
.logo {
163-
width: 200px
164-
}
152+
<style>
153+
.logo {
154+
width: 200px;
155+
}
165156
</style>

src/import/bubbleChart.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileOverview Line Graph component definition
2+
* @fileOverview Bubble Chart component definition
33
*
44
* @author Brian Greig
55
*
@@ -12,11 +12,11 @@ const d3 = Object.assign({},
1212
require('d3-axis'),
1313
require('d3-shape'));
1414
/**
15-
* Builds a Line Graph.
16-
* @module lineGraph
15+
* Builds a Bubble Chart.
16+
* @module bubbleChart
1717
*/
1818

19-
const lineGraph = function chart(mode) {
19+
const bubbleChart = function chart(mode) {
2020
/**
2121
* The SVG that stores the chart
2222
* @member svgContainer
@@ -92,10 +92,10 @@ const lineGraph = function chart(mode) {
9292
*/
9393
const buildScales = cs => {
9494
cs.y.scale = d3.scaleLinear()
95-
.domain([this.minTriplet.v1, this.maxTriplet.v1])
95+
.domain([this.minTriplet.v2, this.maxTriplet.v2])
9696
.range([this.displayHeight - cs.x.axisHeight, this.header]);
9797
cs.x.scale = d3.scaleLinear()
98-
.domain([this.minTriplet.v2, this.maxTriplet.v2])
98+
.domain([this.minTriplet.v1, this.maxTriplet.v1])
9999
.range([0, this.width]);
100100
cs.r.scale = d3.scaleLinear()
101101
.domain([this.minTriplet.v3, this.maxTriplet.v3])
@@ -132,4 +132,4 @@ const lineGraph = function chart(mode) {
132132
return cs;
133133
};
134134

135-
export default lineGraph;
135+
export default bubbleChart;

src/import/scatterPlot.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const scatterPlot = function chart() {
2828
* @member cs
2929
*/
3030
let cs = {
31+
palette: {
32+
pointFill: '#005792',
33+
pointStroke: '#d1f4fa',
34+
},
3135
x: {
3236
domain: [],
3337
range: [],
@@ -37,83 +41,86 @@ const scatterPlot = function chart() {
3741
axisWidth: 30,
3842
ticks: 5,
3943
},
44+
r: {
45+
width: 5
46+
}
4047
};
41-
const points = svgContainer.selectAll('circle').data(this.ds);
48+
4249
/**
4350
* Runs when a new element is added to the dataset
4451
* @member enter
4552
* @function
46-
* @param {Object} p (svg element)
53+
* @param {Object} points (svg element)
4754
*/
48-
const enter = (p) => {
49-
p.enter()
55+
const enter = (points) => {
56+
points.enter()
5057
.append('circle')
5158
.attr('class', this.selector)
52-
.attr('r', 2)
53-
.on('mouseover', (d) => {
54-
this.addTooltip(d, window.event);
55-
})
56-
.on('mouseout', (d) => {
57-
this.removeTooltip(d);
58-
})
59-
.attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
60-
.attr('cy', d => cs.y.scale(d.metric));
59+
.attr('r', cs.r.width)
60+
.attr('cx', d => cs.x.scale(d.metric[0]) + cs.y.axisWidth + 5)
61+
.attr('cy', d => cs.y.scale(d.metric[1]));
6162
return points;
6263
};
6364
/**
6465
* Runs when a value of an element in dataset is changed
6566
* @member transition
6667
* @function
67-
* @param {Object} p (svg element)
68+
* @param {Object} points (svg element)
6869
*/
69-
const transition = (p) => {
70-
p.transition()
71-
.attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
72-
.attr('cy', d => cs.y.scale(d.metric))
73-
.attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
74-
.attr('cy', d => cs.y.scale(d.metric));
70+
const transition = (points) => {
71+
points.transition()
72+
.attr('r', cs.r.width)
73+
.attr('cx', d => cs.x.scale(d.metric[0]) + cs.y.axisWidth + 5)
74+
.attr('cy', d => cs.y.scale(d.metric[1]));
7575
return points;
7676
};
77+
7778
/**
7879
* Runs when an element is removed from the dataset
7980
* @member exit
8081
* @function
81-
* @param {Object} rect (svg element)
82+
* @param {Object} points (svg element)
8283
*/
83-
const exit = () => {
84+
const exit = (points) => {
8485
points.exit().remove();
8586
return points;
8687
};
88+
8789
/**
8890
* Builds the scales for the x and y axes
8991
* @member buildScales
9092
* @function
9193
*/
92-
const buildScales = () => {
94+
const buildScales = cs => {
9395
cs.y.scale = d3.scaleLinear()
94-
.domain([this.min, this.max])
96+
.domain([this.minTriplet.v2, this.maxTriplet.v2])
9597
.range([this.displayHeight - cs.x.axisHeight, this.header]);
96-
cs.y.axis = d3.axisLeft().ticks(cs.y.ticks, 's').scale(cs.y.scale);
97-
this.ds.forEach(t => cs.x.domain.push(t.dim));
98-
this.ds.forEach((t, i) => cs.x.range.push(((this.width * i) - this.header) / this.ds.length));
99-
cs.x.scale = d3.scaleOrdinal().domain(cs.x.domain).range(cs.x.range);
98+
cs.x.scale = d3.scaleLinear()
99+
.domain([this.minTriplet.v1, this.maxTriplet.v1])
100+
.range([0, this.width]);
100101
};
101102
/**
102103
* Draws the x and y axes on the svg
103104
* @member drawAxis
104105
* @function
105106
*/
106-
const drawAxis = () => {
107+
const drawAxis = cs => {
107108
cs.x.axis = d3.axisBottom().scale(cs.x.scale);
108109
cs.x.xOffset = cs.y.axisWidth + 5;
109-
cs.x.yOffset = this.height - cs.x.axisHeight;
110+
cs.x.yOffset = this.displayHeight - cs.x.axisHeight;
111+
cs.y.axis = d3.axisLeft().ticks(cs.y.ticks, 's').scale(cs.y.scale);
110112
cs.y.xOffset = cs.y.axisWidth;
111113
cs.y.yOffset = 0;
112-
svgContainer.append('g').attr('class', 'axis').attr('transform', `translate(${cs.x.xOffset}, ${cs.x.yOffset})`).call(cs.x.axis);
113-
svgContainer.append('g').attr('class', 'axis').attr('transform', `translate(${cs.y.xOffset},${cs.y.yOffset})`).call(cs.y.axis);
114+
svgContainer.append('g').attr('class', 'axis').attr('transform', `translate(${cs.x.xOffset}, ${cs.x.yOffset})`)
115+
.call(cs.x.axis);
116+
svgContainer.append('g').attr('class', 'axis').attr('transform', `translate(${cs.y.xOffset},${cs.y.yOffset})`)
117+
.call(cs.y.axis);
114118
};
119+
120+
const points = svgContainer.selectAll('circle').data(this.ds);
115121

116122
cs = this.setOverrides(cs, this.chartData.overrides);
123+
117124
buildScales(cs);
118125
drawAxis(cs);
119126
enter(points);

src/v-chart-plugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ const Chart = {
9292
addTooltip(d, e) {
9393
d3.select(`#${this.chartData.selector}`)
9494
.append('rect')
95-
.attr('x', e.layerX - 5 - 50)
96-
.attr('y', e.layerY - 13 - 25)
95+
.attr('x', e.offsetX - 5 - 50)
96+
.attr('y', e.offsetY - 13 - 25)
9797
.attr('height', '16px')
9898
.attr('width', '80px')
9999
.attr('class', 'tt')
100100
.attr('fill', 'white');
101101

102102
d3.select(`#${this.chartData.selector}`)
103103
.append('text')
104-
.attr('x', e.layerX - 50)
105-
.attr('y', e.layerY - 25)
104+
.attr('x', e.offsetX - 50)
105+
.attr('y', e.offsetY - 25)
106106
.attr('class', 'tt')
107107
.attr('font-size', '10px')
108108
.text(`${d.dim}:${d.metric}`);

0 commit comments

Comments
 (0)