Skip to content

Commit

Permalink
See DmitryBaranovskiy#137: Parameterized the chart layout for line ch…
Browse files Browse the repository at this point in the history
…arts.
  • Loading branch information
bigspotteddog committed Jul 5, 2012
1 parent 7630040 commit 1bc3d4c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
27 changes: 19 additions & 8 deletions g.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@
valuesy = [valuesy];
}

var gutter = opts.gutter || 10,
opts.gutter = opts.gutter || 10;
opts.symbol = opts.symbol || "";
opts.colors = opts.colors || chartinst.colors;
opts.width = opts.width || 2;
opts.dash = opts.dash || "";

var gutter = opts.gutter,
len = Math.max(valuesx[0].length, valuesy[0].length),
symbol = opts.symbol || "",
colors = opts.colors || chartinst.colors,
symbol = opts.symbol,
colors = opts.colors,
columns = null,
dots = null,
chart = paper.set(),
Expand Down Expand Up @@ -115,11 +121,16 @@
}

if (opts.axis) {
var axisLabelsInside = 1;
if (opts.axisLabelsInside) {
axisLabelsInside = -1;
}

var ax = (opts.axis + "").split(/[,\s]+/);
+ax[0] && axis.push(chartinst.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2, paper));
+ax[1] && axis.push(chartinst.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3, paper));
+ax[0] && axis.push(chartinst.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2 * axisLabelsInside, paper));
+ax[1] && axis.push(chartinst.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3 * axisLabelsInside, paper));
+ax[2] && axis.push(chartinst.axis(x + gutter, y + height - gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 0, paper));
+ax[3] && axis.push(chartinst.axis(x + gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1, paper));
+ax[3] && axis.push(chartinst.axis(x + gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1 * axisLabelsInside, paper));
}

var lines = paper.set(),
Expand All @@ -130,10 +141,10 @@
if (!opts.nostroke) {
lines.push(line = paper.path().attr({
stroke: colors[i],
"stroke-width": opts.width || 2,
"stroke-width": opts.width,
"stroke-linejoin": "round",
"stroke-linecap": "round",
"stroke-dasharray": opts.dash || ""
"stroke-dasharray": opts.dash
}));
}

Expand Down
19 changes: 17 additions & 2 deletions g.raphael.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ Raphael.g = {
X += dx;
}
grid = grid.concat(["M", X, y, "l", 0, height]);

}

var grid = paper.path(grid);
Expand Down Expand Up @@ -849,7 +848,23 @@ Raphael.g = {
rnd = i > 0 ? i : 0;
dx = length / steps;

if (+orientation == 1 || +orientation == 3) {
var axisLabelsInside = false;
var orientation = +orientation;
if (orientation < 0) {
orientation = Math.abs(orientation);
axisLabelsInside = true;
}

if (orientation == 1 || orientation == 3) {

if (axisLabelsInside) {
if (orientation === 1) {
orientation = 3;
} else {
orientation = 1;
}
}

var Y = y,
addon = (orientation - 1 ? 1 : -1) * (dashsize + 3 + !!(orientation - 1));

Expand Down

0 comments on commit 1bc3d4c

Please sign in to comment.