Skip to content

Commit

Permalink
Merge pull request #9 from suitupalex/master
Browse files Browse the repository at this point in the history
Support for fixed ranges and negative values.
  • Loading branch information
nubs committed Mar 5, 2015
2 parents d26246c + b367bd0 commit 570bed3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
31 changes: 11 additions & 20 deletions ampersand-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
title: 'string',
values: 'array',
label: 'string',
range: 'array',

// Search Settings
searchData: 'object',
Expand Down Expand Up @@ -140,9 +141,9 @@
.attr('height', this.model.drawLegend ? '25em' : '21em');

var y = d3.scale.linear()
.domain([ 0, d3.max(data, function(d) {
.domain(_.result(this.model, 'range', [ 0, d3.max(data, function(d) {
return Math.max.apply(null, _.remove(_.values(_.pick(d.attributes, values)), function(n) { return !isNaN(n); }));
}) ])
}) ]))
.range([ height - 100, 0 ]);

var yAxis = null;
Expand Down Expand Up @@ -307,11 +308,6 @@
yAxisOffset = Math.max(this.getBBox().width, yAxisOffset);
});
yAxis.attr('x', yAxisOffset + 12);
yAxis.selectAll('line').each(function(d) {
if (d === 0) {
d3.select(this).remove();
}
});
ground.attr('x1', yAxisOffset + 12);
}

Expand Down Expand Up @@ -536,11 +532,6 @@
yAxisOffset = Math.max(this.getBBox().width, yAxisOffset);
});
yAxis.attr('x', yAxisOffset + 12);
yAxis.selectAll('line').each(function(d) {
if (d === 0) {
d3.select(this).remove();
}
});
this.svg.select('line.ampersand-graph-ground').attr('x1', yAxisOffset + 12);
}
}.bind(this), 1);
Expand Down Expand Up @@ -637,9 +628,9 @@
var barMargin = barWidth * b;

var y = d3.scale.linear()
.domain([ 0, d3.max(data, function(d) {
.domain(_.result(this.model, 'range', [ 0, d3.max(data, function(d) {
return Math.max.apply(null, _.remove(_.values(_.pick(d.attributes, values)), function(n) { return !isNaN(n); }));
}) ])
}) ]))
.range([ height - 100, 0 ]);

this.renderYAxis(y, graphWidth, yAxisOffset, circleGraphRadius, circleGraphPadding);
Expand Down Expand Up @@ -700,8 +691,8 @@
.transition()
.attr('x', (barWidth + barMargin) * index)
.attr('width', barWidth)
.attr('y', function(d) { return y(d[value]) + 50; })
.attr('height', function(d) { return height - 100 - y(d[value]); });
.attr('y', function(d) { return y(Math.max(d[value], 0)) + 50; })
.attr('height', function(d) { return Math.abs(y(0) - y(d[value])); });

containers.select('text.ampersand-graph-value-' + index)
.transition()
Expand Down Expand Up @@ -747,9 +738,9 @@
var lineGroupMargin = lineWidth * a;

var y = d3.scale.linear()
.domain([ 0, d3.max(data, function(d) {
.domain(_.result(this.model, 'range', [ 0, d3.max(data, function(d) {
return Math.max.apply(null, _.remove(_.values(_.pick(d.attributes, values)), function(n) { return !isNaN(n); }));
}) ])
}) ]))
.range([ height - 100, 0 ]);

this.renderYAxis(y, graphWidth, yAxisOffset, 0, 0);
Expand Down Expand Up @@ -913,9 +904,9 @@
var areaGroupMargin = areaWidth * a;

var y = d3.scale.linear()
.domain([ 0, d3.max(data, function(d) {
.domain(_.result(this.model, 'range', [ 0, d3.max(data, function(d) {
return Math.max.apply(null, _.remove(_.values(_.pick(d.attributes, values)), function(n) { return !isNaN(n); }));
}) ])
}) ]))
.range([ height - 100, 0 ]);

this.renderYAxis(y, graphWidth, yAxisOffset, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ampersand-chart",
"version": "0.1.5",
"version": "0.1.6",
"description": "Ampersand module for drawing a charts.",
"main": "ampersand-chart.js",
"scripts": {
Expand Down

0 comments on commit 570bed3

Please sign in to comment.