coconut-graph
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "coconut-graph", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Graph lib using d3 ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,9 +6,6 @@ var d3 = require('d3'); | ||
module.exports = function (x, y, plot, graph) { | ||
var line = d3.svg.line() | ||
.x(function(d) { return x(d[0]); }) | ||
.y(function(d) { return y(d[plot.data_key]); }); | ||
var line_plot = function (sel) { | ||
sel.attr('d', line); | ||
var line = function (sel) { | ||
sel.attr('d', d3.svg.line() | ||
.x(function(d) { return x(d[0]); }) | ||
.y(function(d) { return y(d[plot.data_key]); })); | ||
}; | ||
@@ -20,12 +17,13 @@ | ||
selection.enter().append('path') | ||
selection.enter() | ||
.append('path') | ||
.attr({ | ||
class: 'plot plot-line series-' + plot.key, | ||
'data-legend': plot.label || 'series ' + unnamed_series++ | ||
}) | ||
.call(line_plot); | ||
}); | ||
selection.exit().remove(); | ||
return line_plot; | ||
selection.call(line); | ||
return line; | ||
}; |
@@ -6,29 +6,6 @@ /* globals | ||
d3: true | ||
Graph:true | ||
Graph:true, | ||
data:true | ||
*/ | ||
var data = { | ||
'meta': { | ||
'period': 'day', | ||
'urls': { | ||
'next': '<url to get json for the next day>', | ||
'previous': '<url to get json for previous day>' | ||
}, | ||
'readable_interval': '15 minuten' | ||
}, | ||
'data': { | ||
'keys': ['timestamp', 'amount', 'test', 'foo'], | ||
'extents': ['2015-05-29T00:00:00', '2015-05-29T23:59:59'], | ||
'values': [ | ||
['2015-05-29T00:00:00', 0, 1, 7], | ||
['2015-05-29T14:00:00', 10, 2, 5], | ||
['2015-05-29T14:15:00', 0, 3, 7], | ||
['2015-05-29T14:30:00', 5, 4, 7], | ||
['2015-05-29T14:45:00', 4, 5, 7], | ||
['2015-05-29T15:00:00', 6, 5, 7] | ||
], | ||
'slices': 96 | ||
} | ||
}; | ||
(function disableD3animations() { | ||
@@ -47,17 +24,17 @@ // add a duration function to the selection prototype | ||
describe('Graph loader', function () { | ||
var spy = chai.spy(); | ||
var spy = chai.spy(); | ||
var loader = new Graph.Loader(Graph.util.extend({}, data), { | ||
graphs: [ | ||
{ | ||
container: container, | ||
className: 'extra', | ||
axes: {y: {includeZero: true}}, | ||
plot: {key: 'amount', axis: 'y', label: 'verbruik [l]', type: 'bar'} | ||
} | ||
], | ||
callback: spy | ||
}); | ||
var loader = new Graph.Loader(Graph.util.extend({}, data[0]), { | ||
graphs: [ | ||
{ | ||
container: container, | ||
className: 'extra', | ||
axes: {y: {includeZero: true}}, | ||
plot: {key: 'amount', axis: 'y', label: 'verbruik [l]', type: 'bar'} | ||
} | ||
], | ||
callback: spy | ||
}); | ||
describe('Graph loader', function () { | ||
it('adds classnames to graph container', function () { | ||
@@ -84,4 +61,4 @@ c.className.should.contain('chart'); | ||
it('should create multiple plots in one chart', function () { | ||
loader = new Graph.Loader(Graph.util.extend({}, data), { | ||
it('Update graph', function () { | ||
loader = new Graph.Loader(Graph.util.extend({}, data[0]), { | ||
graphs: [ | ||
@@ -106,3 +83,5 @@ { | ||
// var graph = loader.graphs[container]; | ||
// graph.plots.should.have.keys('amount', 'test', 'foo'); | ||
loader.graphs[container].options.plots.forEach(function (plot) { | ||
plot.should.contain.key('fn'); | ||
}); | ||
}); | ||
@@ -125,2 +104,10 @@ }); | ||
}); | ||
describe('updating graph', function () { | ||
it('Updates line graphs', function () { | ||
var path = d3.select('.series-test').attr('d'); | ||
loader.load_json(data[1]); | ||
path.should.not.equal(d3.select('.series-test').attr('d')); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
27158
20
750