Skip to content

Commit

Permalink
Merge pull request jcarver989#7 from tonyhb/develop
Browse files Browse the repository at this point in the history
Adds label_color as an option to line charts.
  • Loading branch information
jcarver989 committed Mar 22, 2013
2 parents 366e2ba + 0f3d496 commit d4b4820
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 91 deletions.
42 changes: 35 additions & 7 deletions compiled/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit d4b4820

Please sign in to comment.