diff --git a/src/js/Rickshaw.Graph.Renderer.Area.js b/src/js/Rickshaw.Graph.Renderer.Area.js index 04ed173e..9335cb2f 100644 --- a/src/js/Rickshaw.Graph.Renderer.Area.js +++ b/src/js/Rickshaw.Graph.Renderer.Area.js @@ -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 } ); }, @@ -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') diff --git a/src/js/Rickshaw.Graph.Renderer.Bar.js b/src/js/Rickshaw.Graph.Renderer.Bar.js index 1fb2f344..48fe351f 100644 --- a/src/js/Rickshaw.Graph.Renderer.Bar.js +++ b/src/js/Rickshaw.Graph.Renderer.Bar.js @@ -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; @@ -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); diff --git a/src/js/Rickshaw.Graph.Renderer.LinePlot.js b/src/js/Rickshaw.Graph.Renderer.LinePlot.js index a84c7d38..d76e3167 100644 --- a/src/js/Rickshaw.Graph.Renderer.LinePlot.js +++ b/src/js/Rickshaw.Graph.Renderer.LinePlot.js @@ -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); }, @@ -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; @@ -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); } -} ); - +} ); \ No newline at end of file diff --git a/src/js/Rickshaw.Graph.Renderer.ScatterPlot.js b/src/js/Rickshaw.Graph.Renderer.ScatterPlot.js index 423a0739..3c75fe34 100644 --- a/src/js/Rickshaw.Graph.Renderer.ScatterPlot.js +++ b/src/js/Rickshaw.Graph.Renderer.ScatterPlot.js @@ -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 } ); }, @@ -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); } diff --git a/src/js/Rickshaw.Graph.Renderer.js b/src/js/Rickshaw.Graph.Renderer.js index fc34edaf..c1146305 100644 --- a/src/js/Rickshaw.Graph.Renderer.js +++ b/src/js/Rickshaw.Graph.Renderer.js @@ -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 }; }, @@ -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);