Skip to content

Commit

Permalink
Merge pull request #141 from ignoreintuition/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ignoreintuition authored Nov 20, 2018
2 parents 608a57c + 7b97972 commit 6bb71c4
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 95 deletions.
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css integrity=sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm crossorigin=anonymous><title>v-chart-plugin</title><link href=/v-chart-plugin-demo/static/css/app.f304e2ab4d8ba945cb52a7708d244e45.css rel=stylesheet></head><body bgcolor=yellow><div id=app></div><script type=text/javascript src=/v-chart-plugin-demo/static/js/manifest.c423efaf7696a83d1404.js></script><script type=text/javascript src=/v-chart-plugin-demo/static/js/vendor.204a476a59e23f5db787.js></script><script type=text/javascript src=/v-chart-plugin-demo/static/js/app.d0cfa1f5b8fb363d2216.js></script></body><script src=https://code.jquery.com/jquery-3.2.1.slim.min.js integrity=sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js integrity=sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q crossorigin=anonymous></script><script src=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js integrity=sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl crossorigin=anonymous></script></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css integrity=sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm crossorigin=anonymous><title>v-chart-plugin</title><link href=/v-chart-plugin-demo/static/css/app.f304e2ab4d8ba945cb52a7708d244e45.css rel=stylesheet></head><body bgcolor=yellow><div id=app></div><script type=text/javascript src=/v-chart-plugin-demo/static/js/manifest.c423efaf7696a83d1404.js></script><script type=text/javascript src=/v-chart-plugin-demo/static/js/vendor.ea0c2a26400e96edf6cc.js></script><script type=text/javascript src=/v-chart-plugin-demo/static/js/app.de77d3a1edc539760483.js></script></body><script src=https://code.jquery.com/jquery-3.2.1.slim.min.js integrity=sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js integrity=sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q crossorigin=anonymous></script><script src=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js integrity=sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl crossorigin=anonymous></script></html>
37 changes: 29 additions & 8 deletions dist/module/import/barChart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _Object$assign from 'babel-runtime/core-js/object/assign';
import { globalAgent } from 'http';

/**
* @fileOverview Bar chart component definition
*
Expand Down Expand Up @@ -29,7 +31,7 @@ var barChart = function chart() {
*/
var cs = {
palette: {
fill: '#005792',
fill: ['#005792', '#ffcdcd'],
stroke: '#d1f4fa'
},
bar: {
Expand Down Expand Up @@ -63,7 +65,7 @@ var barChart = function chart() {
* @function
*/
var getHeight = function getHeight() {
return (_this.displayHeight - cs.x.axisHeight - _this.header - cs.bar.vPadding) / _this.ds.length - 1;
return ((_this.displayHeight - cs.x.axisHeight - _this.header - cs.bar.vPadding) / _this.ds.length - 1) / _this.metric.length;
};

/**
Expand All @@ -74,7 +76,7 @@ var barChart = function chart() {
* @param {Object} i (svg element)
*/
var getYCoord = function getYCoord(d, i) {
return i * (_this.displayHeight - cs.x.axisHeight - _this.header) / _this.ds.length + 1 + _this.header;
return i * (_this.displayHeight - cs.x.axisHeight - _this.header) / _this.ds.length + 1 + _this.header + cs.bar.offset * getHeight();
};

/**
Expand Down Expand Up @@ -103,7 +105,11 @@ var barChart = function chart() {
* @param {Object} rects (svg element)
*/
var enter = function enter(rects) {
rects.enter().append('rect').attr('fill', cs.palette.fill).attr('stroke', cs.palette.stroke).attr('class', _this.selector).attr('width', getWidth).attr('height', getHeight).attr('y', getYCoord).attr('x', cs.y.axisWidth + cs.bar.hPadding).on('mouseover', mouseOver).on('mouseout', mouseOut);
_this.metric.forEach(function (e, i) {
cs.bar.offset = i;
rects[i].enter().append('rect').attr('fill', cs.palette.fill[i]).attr('stroke', cs.palette.stroke).attr('class', _this.selector).attr('class', 'r' + i).attr('width', getWidth).attr('height', getHeight).attr('y', getYCoord).attr('x', cs.y.axisWidth + cs.bar.hPadding).on('mouseover', mouseOver).on('mouseout', mouseOut);
});
if (_this.goal) _this.generateGoal(cs, svgContainer, false, cs.y.axisWidth + cs.bar.hPadding);
return rects;
};
/**
Expand All @@ -113,7 +119,11 @@ var barChart = function chart() {
* @param {Object} rects (svg element)
*/
var transition = function transition(rects) {
rects.transition().attr('width', getWidth).attr('height', getHeight).attr('y', getYCoord).attr('x', cs.y.axisWidth + cs.bar.hPadding);
_this.metric.forEach(function (e, i) {
cs.bar.offset = i;
rects[i].transition().attr('width', getWidth).attr('height', getHeight).attr('y', getYCoord).attr('x', cs.y.axisWidth + cs.bar.hPadding);
});
if (_this.goal) _this.generateGoal(cs, svgContainer, false, cs.y.axisWidth + cs.bar.hPadding);
return rects;
};
/**
Expand All @@ -123,7 +133,9 @@ var barChart = function chart() {
* @param {Object} rect (svg element)
*/
var exit = function exit(rects) {
rects.exit().remove();
_this.metric.forEach(function (e, i) {
rects[i].exit().remove();
});
return rects;
};
/**
Expand Down Expand Up @@ -164,13 +176,22 @@ var barChart = function chart() {
* @param {number} currentValue
*/
var getMaxDimLength = function getMaxDimLength(accumulator, currentValue) {
if (!currentValue.dim) return accumulator;
return currentValue.dim.length > accumulator ? currentValue.dim.length : accumulator;
};

var rects = svgContainer.selectAll('rect').data(this.ds);
var rects = [];
this.metric.forEach(function (e, i) {
rects.push(svgContainer.selectAll('rect.r' + i).data(_this.ds.map(function (d) {
return {
metric: d.metric[i],
dim: d.dim
};
})));
});

cs = this.setOverrides(cs, this.chartData.overrides);
if (this.ds[0].dim) cs.y.axisWidth = cs.y.axisWidth || this.ds.reduce(getMaxDimLength, 0) * 10;
if (this.ds[0] && this.ds[0].dim) cs.y.axisWidth = cs.y.axisWidth || this.ds.reduce(getMaxDimLength, 0) * 10;

buildScales(cs);
drawAxis(cs);
Expand Down
128 changes: 128 additions & 0 deletions dist/module/import/bubbleChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import _Object$assign from 'babel-runtime/core-js/object/assign';
/**
* @fileOverview Line Graph component definition
*
* @author Brian Greig
*
* @requires NPM:d3:Vue
* @requires src/v-chart-plugin.js
*/
var d3 = _Object$assign({}, require('d3-selection'), require('d3-scale'), require('d3-axis'), require('d3-shape'));
/**
* Builds a Line Graph.
* @module lineGraph
*/

var lineGraph = function chart(mode) {
var _this = this;

/**
* The SVG that stores the chart
* @member svgContainer
*/
var svgContainer = d3.select('#' + this.chartData.selector);
/**
* The configuration of the coordinate system
* @member cs
*/
var cs = {
palette: {
pointFill: '#005792',
pointStroke: '#d1f4fa'
},
x: {
domain: [],
range: [],
axisHeight: 20
},
y: {
axisWidth: 30,
ticks: 5
},
r: {}
};

/**
* Runs when a new element is added to the dataset
* @member enter
* @function
* @param {Object} points (svg element)
*/
var enter = function enter(points) {
points.enter().append('circle').attr('class', _this.selector).attr('r', function (d) {
return cs.r.scale(d.metric[2]);
}).attr('cx', function (d) {
return cs.x.scale(d.metric[0]) + cs.y.axisWidth + 5;
}).attr('cy', function (d) {
return cs.y.scale(d.metric[1]);
});
return points;
};
/**
* Runs when a value of an element in dataset is changed
* @member transition
* @function
* @param {Object} points (svg element)
*/
var transition = function transition(points) {
points.transition().attr('r', function (d) {
return cs.r.scale(d.metric[2]);
}).attr('cx', function (d) {
return cs.x.scale(d.metric[0]) + cs.y.axisWidth + 5;
}).attr('cy', function (d) {
return cs.y.scale(d.metric[1]);
});
return points;
};

/**
* Runs when an element is removed from the dataset
* @member exit
* @function
* @param {Object} points (svg element)
*/
var exit = function exit(points) {
points.exit().remove();
return points;
};

/**
* Builds the scales for the x and y axes
* @member buildScales
* @function
*/
var buildScales = function buildScales(cs) {
cs.y.scale = d3.scaleLinear().domain([_this.minTriplet.v1, _this.maxTriplet.v1]).range([_this.displayHeight - cs.x.axisHeight, _this.header]);
cs.x.scale = d3.scaleLinear().domain([_this.minTriplet.v2, _this.maxTriplet.v2]).range([0, _this.width]);
cs.r.scale = d3.scaleLinear().domain([_this.minTriplet.v3, _this.maxTriplet.v3]).range([0, 20]);
};
/**
* Draws the x and y axes on the svg
* @member drawAxis
* @function
*/
var drawAxis = function drawAxis(cs) {
cs.x.axis = d3.axisBottom().scale(cs.x.scale);
cs.x.xOffset = cs.y.axisWidth + 5;
cs.x.yOffset = _this.displayHeight - cs.x.axisHeight;
cs.y.axis = d3.axisLeft().ticks(cs.y.ticks, 's').scale(cs.y.scale);
cs.y.xOffset = cs.y.axisWidth;
cs.y.yOffset = 0;
svgContainer.append('g').attr('class', 'axis').attr('transform', 'translate(' + cs.x.xOffset + ', ' + cs.x.yOffset + ')').call(cs.x.axis);
svgContainer.append('g').attr('class', 'axis').attr('transform', 'translate(' + cs.y.xOffset + ',' + cs.y.yOffset + ')').call(cs.y.axis);
};

var points = svgContainer.selectAll('circle').data(this.ds);

cs = this.setOverrides(cs, this.chartData.overrides);

buildScales(cs);
drawAxis(cs);
enter(points);
transition(points);
exit(points);

return cs;
};

export default lineGraph;
63 changes: 41 additions & 22 deletions dist/module/import/lineGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ var lineGraph = function chart(mode) {
_this.metric.forEach(function (e, i) {
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);
});

// points.enter()
// .append('circle')
// .attr('class', this.selector)
// .attr('r', 2)
// .on('mouseover', (d) => {
// this.addTooltip(d, window.event);
// })
// .on('mouseout', (d) => {
// this.removeTooltip(d);
// })
// .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
// .attr('cy', d => cs.y.scale(d.metric[0]));
// return points;
_this.metric.forEach(function (e, i) {
cs.offset = i;
points[i].enter().append('circle').attr('class', _this.selector).attr('class', "r" + i).attr('r', 2).on('mouseover', function (d) {
_this.addTooltip(d, window.event);
}).on('mouseout', function (d) {
_this.removeTooltip(d);
}).attr('cx', function (d) {
return cs.x.scale(d.dim) + cs.y.axisWidth + 5;
}).attr('cy', function (d) {
return cs.y.scale(d.metric);
});
});
if (_this.goal) _this.generateGoal(cs, svgContainer, true, 0);
return points;
};
/**
* Runs when a value of an element in dataset is changed
Expand All @@ -78,12 +78,20 @@ var lineGraph = function chart(mode) {
path[i].transition().attr('d', cs.lineFunction[i](_this.ds));
});

// points.transition()
// .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
// .attr('cy', d => cs.y.scale(d.metric[0]))
// .attr('cx', d => cs.x.scale(d.dim) + cs.y.axisWidth + 5)
// .attr('cy', d => cs.y.scale(d.metric[0]));
// return points;
_this.metric.forEach(function (e, i) {
cs.offset = i;
points[i].transition().attr('cx', function (d) {
return cs.x.scale(d.dim) + cs.y.axisWidth + 5;
}).attr('cy', function (d) {
return cs.y.scale(d.metric);
}).attr('cx', function (d) {
return cs.x.scale(d.dim) + cs.y.axisWidth + 5;
}).attr('cy', function (d) {
return cs.y.scale(d.metric);
});
});
if (_this.goal) _this.generateGoal(cs, svgContainer, true, 0);
return points;
};

/**
Expand All @@ -93,7 +101,9 @@ var lineGraph = function chart(mode) {
* @param {Object} points (svg element)
*/
var exit = function exit(points, path) {
points.exit().remove();
_this.metric.forEach(function (e, i) {
points[i].exit().remove();
});
_this.metric.forEach(function (e, i) {
path[i].exit().remove();
});
Expand Down Expand Up @@ -140,7 +150,16 @@ var lineGraph = function chart(mode) {
}));
});

var points = svgContainer.selectAll('circle').data(this.ds);
var points = [];
this.metric.forEach(function (e, i) {
points.push(svgContainer.selectAll('circle.r' + i).data(_this.ds.map(function (d) {
return {
metric: d.metric[i],
dim: d.dim
};
})));
});

var path = [];
this.metric.forEach(function (e, i) {
path.push(svgContainer.selectAll('path#p' + i).data(_this.ds));
Expand Down
Loading

0 comments on commit 6bb71c4

Please sign in to comment.