Permalink
Browse files

Merge pull request #7 from tonyhb/develop

Adds label_color as an option to line charts.
  • Loading branch information...
2 parents 366e2ba + 0f3d496 commit d4b48203882620576e1cf7d66bb3ac58b6c8085b @jcarver989 committed Mar 22, 2013
View
@@ -37,6 +37,7 @@ LineChartOptions = (function() {
x_label_size: 14,
y_label_size: 14,
label_format: "%m/%d",
+ label_color: "#333",
show_grid: false,
x_padding: 45,
y_padding: 40,
@@ -203,7 +204,6 @@ LabelSet = (function() {
this.format = format != null ? format : "";
this.num = 0;
this.font_family = "Helvetica, Arial, sans-serif";
- this.color = "#333";
}
LabelSet.prototype.x = function(x_func) {
@@ -226,8 +226,16 @@ LabelSet = (function() {
return this;
};
+ LabelSet.prototype.color = function(color) {
+ this.color = color;
+ return this;
+ };
+
LabelSet.prototype.draw = function(text) {
var label;
+ if (!this.color) {
+ this.color = "#333";
+ }
label = new Label(this.r, this.x_func(this.num), this.y_func(this.num), text, this.format, this.size, this.font_family, this.color, this.options);
this.num += 1;
return label.draw();
@@ -1761,15 +1769,24 @@ LineChart = (function(_super) {
};
LineChart.prototype._draw_y_labels = function(labels, x_offset) {
- var axis, fmt, font_family, label, label_coordinates, offset, padding, size, x, y, _i, _len, _ref, _ref1;
+ var axis, color, fmt, font_family, label, label_color, label_coordinates, label_size, offset, padding, size, x, y, _i, _len, _ref, _ref1;
if (x_offset == null) {
x_offset = 0;
}
fmt = this.options.label_format;
size = this.options.y_label_size;
font_family = this.options.font_family;
+ color = this.options.label_color || '#333';
padding = size + 5;
offset = this.options.multi_axis && x_offset > 0 ? x_offset : x_offset + padding;
+ if (this.options.y_axis_name) {
+ offset += size * 1.75;
+ label_color = this.options.axis_name_color || '#333';
+ label_size = this.options.axis_name_size || size;
+ label = new Label(this.r, 5, this.height / 2, this.options.y_axis_name, fmt, label_size, font_family, label_color).draw();
+ label.transform("T0,0R270S1");
+ label.transform("...t0," + (label.getBBox()['x'] * -1));
+ }
if (labels.length === 1) {
_ref = this.create_scalers_for_single_point(), x = _ref[0], y = _ref[1];
} else {
@@ -1780,7 +1797,7 @@ LineChart = (function(_super) {
return offset;
}).y(function(i) {
return y(labels[i].y);
- }).size(size);
+ }).size(size).color(color);
for (_i = 0, _len = labels.length; _i < _len; _i++) {
label = labels[_i];
axis.draw(label.y);
@@ -1844,18 +1861,29 @@ LineChart = (function(_super) {
};
LineChart.prototype.draw_x_label = function(raw_point, point) {
- var fmt, font_family, label, size;
+ var color, fmt, font_family, label, size, y;
fmt = this.options.label_format;
size = this.options.x_label_size;
font_family = this.options.font_family;
+ color = this.options.label_color || '#333';
+ if (this.options.x_axis_name) {
+ y = this.height - (size * 2);
+ } else {
+ y = this.height - size;
+ }
label = raw_point.is_date_type === true ? new Date(raw_point.x) : Math.round(raw_point.x);
- return new Label(this.r, point.x, this.height - size, label, fmt, size, font_family).draw();
+ return new Label(this.r, point.x, y, label, fmt, size, font_family, color).draw();
};
LineChart.prototype.draw_x_labels = function(raw_points, points) {
- var i, label_coordinates, last, len, max_labels, point, raw_point, rounded_step_size, step_size;
+ var color, i, label, label_coordinates, label_size, last, len, max_labels, point, raw_point, rounded_step_size, step_size;
label_coordinates = [];
max_labels = this.options.max_x_labels;
+ if (this.options.x_axis_name) {
+ color = this.options.axis_name_color || '#333';
+ label_size = this.options.axis_name_size || this.options.x_label_size;
+ label = new Label(this.r, this.width / 2, this.height - (this.options.x_label_size / 2), this.options.x_axis_name, this.options.label_format, label_size, this.options.font_family, color).draw();
+ }
this.draw_x_label(raw_points[0], points[0]);
label_coordinates.push(points[0].x);
if (max_labels < 2) {
@@ -1910,7 +1938,7 @@ LineChart = (function(_super) {
for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) {
line_indices = _ref1[i];
begin = line_indices[0], end = line_indices[1];
- raw_points = this.all_points.slice(begin, end + 1 || 9e9);
+ raw_points = this.all_points.slice(begin, +end + 1 || 9e9);
if (this.options.multi_axis) {
_ref2 = this.all_points.length > 2 ? this.create_scalers(raw_points) : this.create_scalers_for_single_point(), line_x = _ref2[0], line_y = _ref2[1];
} else {
Oops, something went wrong.

0 comments on commit d4b4820

Please sign in to comment.