Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for multiple series in LinePlot #414

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/js/Rickshaw.Graph.Renderer.Area.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
return Rickshaw.extend( $super(), {
unstack: false,
fill: false,
stroke: false
stroke: false,
opacity : 1.0
} );
},

Expand Down Expand Up @@ -84,7 +85,8 @@ Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
if (!series.path) return;

d3.select(series.path).select('.area')
.attr('fill', series.color);
.attr('fill', series.color)
.attr('opacity', series.opacity);

if (this.stroke) {
d3.select(series.path).select('.line')
Expand Down
6 changes: 4 additions & 2 deletions src/js/Rickshaw.Graph.Renderer.Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {

var defaults = Rickshaw.extend( $super(), {
gapSize: 0.05,
unstack: false
unstack: false,
opacity : 1.0
} );

delete defaults.tension;
Expand Down Expand Up @@ -74,7 +75,8 @@ Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
.attr("y", function(d) { return (graph.y(d.y0 + Math.abs(d.y))) * (d.y < 0 ? -1 : 1 ) })
.attr("width", seriesBarWidth)
.attr("height", function(d) { return graph.y.magnitude(Math.abs(d.y)) })
.attr("transform", transform);
.attr("transform", transform)
.attr("opacity", series.opacity);

Array.prototype.forEach.call(nodes[0], function(n) {
n.setAttribute('fill', series.color);
Expand Down
82 changes: 44 additions & 38 deletions src/js/Rickshaw.Graph.Renderer.LinePlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ Rickshaw.Graph.Renderer.LinePlot = Rickshaw.Class.create( Rickshaw.Graph.Rendere

defaults: function($super) {

return Rickshaw.extend( $super(), {
var defaults = Rickshaw.extend( $super(), {
unstack: true,
fill: false,
stroke: true,
padding:{ top: 0.01, right: 0.01, bottom: 0.01, left: 0.01 },
dotSize: 3,
strokeWidth: 2
strokeWidth: 2,
opacity : 1.0
} );

return defaults;
},

initialize: function($super, args) {
args = args || {};
$super(args);
},

Expand All @@ -32,21 +36,50 @@ Rickshaw.Graph.Renderer.LinePlot = Rickshaw.Class.create( Rickshaw.Graph.Rendere
factory.defined && factory.defined( function(d) { return d.y !== null } );
return factory;
},

_renderDots: function() {
render : function(args){
args = args || {};

var graph = this.graph;
var series = args.series || graph.series;

var vis = args.vis || graph.vis;
vis.selectAll('*').remove();

var data = series
.filter(function(s) { return !s.disabled })
.map(function(s) { return s.stack });

var pathNodes = vis.selectAll("path.path")
.data(data)
.enter().append("svg:path")
.classed('path', true)
.attr("d", this.seriesPathFactory());

graph.series.forEach(function(series) {
if (this.stroke) {
var strokeNodes = vis.selectAll('path.stroke')
.data(data)
.enter().append("svg:path")
.classed('stroke', true)
.attr("d", this.seriesStrokeFactory());
}

if (series.disabled) return;
var dotSize = this.dotSize;
var dotByPoint = dotSize;

var nodes = graph.vis.selectAll("x")
var i = 0;
series.forEach( function(series) {
if (series.disabled) return;
series.path = pathNodes[0][i];
if (this.stroke) series.stroke = strokeNodes[0][i];
this._styleSeries(series);

dotByPoint = series.dotSize || dotSize;
var nodes = vis.selectAll("x")
.data(series.stack.filter( function(d) { return d.y !== null } ))
.enter().append("svg:circle")
.attr("cx", function(d) { return graph.x(d.x) })
.attr("cy", function(d) { return graph.y(d.y) })
.attr("r", function(d) { return ("r" in d) ? d.r : graph.renderer.dotSize});
.attr("r", function(d) { return ("r" in d) ? d.r : dotByPoint});

Array.prototype.forEach.call(nodes[0], function(n) {
if (!n) return;
Expand All @@ -57,34 +90,7 @@ Rickshaw.Graph.Renderer.LinePlot = Rickshaw.Class.create( Rickshaw.Graph.Rendere

}.bind(this));

}, this);
},

_renderLines: function() {

var graph = this.graph;

var nodes = graph.vis.selectAll("path")
.data(this.graph.stackedData)
.enter().append("svg:path")
.attr("d", this.seriesPathFactory());

var i = 0;
graph.series.forEach(function(series) {
if (series.disabled) return;
series.path = nodes[0][i++];
this._styleSeries(series);
}, this);
},

render: function() {

var graph = this.graph;

graph.vis.selectAll('*').remove();

this._renderLines();
this._renderDots();
i++;
},this);
}
} );

} );
6 changes: 4 additions & 2 deletions src/js/Rickshaw.Graph.Renderer.ScatterPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Rend
fill: true,
stroke: false,
padding:{ top: 0.01, right: 0.01, bottom: 0.01, left: 0.01 },
dotSize: 4
dotSize: 4,
opacity : 1.0
} );
},

Expand Down Expand Up @@ -41,7 +42,8 @@ Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Rend
.enter().append("svg:circle")
.attr("cx", function(d) { return graph.x(d.x) })
.attr("cy", function(d) { return graph.y(d.y) })
.attr("r", function(d) { return ("r" in d) ? d.r : dotSize});
.attr("r", function(d) { return ("r" in d) ? d.r : dotSize})
.attr("opacity", series.opacity);
if (series.className) {
nodes.classed(series.className, true);
}
Expand Down
5 changes: 4 additions & 1 deletion src/js/Rickshaw.Graph.Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
unstack: true,
padding: { top: 0.01, right: 0, bottom: 0.01, left: 0 },
stroke: false,
fill: false
fill: false,
opacity : 1.0
};
},

Expand Down Expand Up @@ -120,10 +121,12 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {

var fill = this.fill ? series.color : 'none';
var stroke = this.stroke ? series.color : 'none';
var opacity = this.opacity ? series.opacity : this.opacity;

series.path.setAttribute('fill', fill);
series.path.setAttribute('stroke', stroke);
series.path.setAttribute('stroke-width', this.strokeWidth);
series.path.setAttribute('opacity', opacity);

if (series.className) {
d3.select(series.path).classed(series.className, true);
Expand Down