diff --git a/css/dangle.css b/css/dangle.css index 5dfd680..0f76086 100644 --- a/css/dangle.css +++ b/css/dangle.css @@ -22,20 +22,43 @@ font-size: 16px; } +.curve0 { + fill: #0000FF; + stroke: #0000FF; +} + +.curve1 { + fill: #000000; + stroke: #000000; +} + +.curve2 { + fill: #FF0000; + stroke: #FF0000; +} + +.curve3 { + fill: #00FF00; + stroke: #00FF00; +} + +.curve4 { + fill: #00FFFF; + stroke: #00FFFF; +} + /* controls the area */ -.area.fill { - fill: #e5f3f9; +.fill { fill-opacity: 0.2; } /* controls the top line in area */ -.area.line { +.line { fill: none; - stroke: #058dc7; stroke-width: 6.0px; } -.area.line.points { +.line.points { fill: #058dc7; stroke: #fff; stroke-width: 3.0px; @@ -53,4 +76,4 @@ fill: #000; stroke: none; font-size: 12px; -} \ No newline at end of file +} diff --git a/src/modules/area/area.js b/src/modules/area/area.js index 568a191..5fe2120 100644 --- a/src/modules/area/area.js +++ b/src/modules/area/area.js @@ -24,7 +24,7 @@ */ angular.module('dangle') - .directive('fsArea', [function() { + .directive('fsArea', ['$compile', function($compile) { 'use strict'; return { @@ -49,7 +49,7 @@ angular.module('dangle') var margin = { top: 20, right: 20, - bottom: 30, + bottom: 80, left: 80 }; @@ -67,7 +67,7 @@ angular.module('dangle') width = width - margin.left - margin.right; height = height - margin.top - margin.bottom; - // create x,y sclaes (x is inferred as time) + // create x,y scales (x is inferred as time) var x = d3.time.scale() .range([0, width]); @@ -108,19 +108,13 @@ angular.module('dangle') .append('g') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); - // generate the area. Data is empty at link time - svg.append('path') - .datum([]) - .attr('class', 'area fill ' + klass) - .attr('d', area); - // insert the x axis (no data yet) svg.append('g') .attr('class', 'area x axis ' + klass) .attr('transform', 'translate(0,' + height + ')') .call(xAxis); - // insert the x axis (no data yet) + // insert the y axis (no data yet) svg.append('g') .attr('class', 'area y axis ' + klass) .call(yAxis) @@ -131,13 +125,6 @@ angular.module('dangle') .style('text-anchor', 'end') .text(label); - // generate the line. Data is empty at link time - svg.append('path') - .datum([]) - .attr('class', 'area line ' + klass) - .attr("d", line); - - // main observer fn called when scope is updated. Data and scope vars are now bound scope.$watch('bind', function(data) { @@ -148,67 +135,126 @@ angular.module('dangle') var pointRadius = scope.pointRadius || 8; var field = scope.field || attrs.bind.split('.').pop().toLowerCase(); + //remove element if they are + svg.selectAll(".curve") + .remove(); + // just because scope is bound doesn't imply we have data. - if (data) { + if (data === undefined) { + } + else if (data.length != 0) { // pull the data array from the facet data = data.entries || []; - // use that data to build valid x,y ranges - x.domain(d3.extent(data, function(d) { return d.time; })); - y.domain([0, d3.max(data, function(d) { return d.count; })]); - - // create the transition - var t = svg.transition().duration(duration); - - // feed the current data to our area/line generators - t.select('.area').attr('d', area(data)); - t.select('.line').attr('d', line(data)); - - // does the user want data points to be plotted - if (dataPoints == 'true') { - - // create svg circle for each data point - // using Math.random as (optional) key fn ensures old - // data values are flushed and all new values inserted - var points = svg.selectAll('circle') - .data(data.filter(function(d) { - return d.count; - }), function(d) { - return Math.random(); - }); + var label_charts = {}; + for (var i=0; i