Commit c34744fc authored by David Schnur's avatar David Schnur

Merge pull request #1194 from jBouyoud/0.9-patch-707-778

 Patch for Issue #707 and #778 (0.9-work)
parents 6578355d 0706d036
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<link href="../examples.css" rel="stylesheet" type="text/css"> <link href="../examples.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../lib/excanvas.min.js"></script><![endif]--> <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../lib/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../../lib/jquery.js"></script> <script language="javascript" type="text/javascript" src="../../lib/jquery.js"></script>
<script language="javascript" type="text/javascript" src="../../lib/jquery.colorhelpers.js"></script>
<script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script> <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>
<script type="text/javascript"> <script type="text/javascript">
...@@ -56,7 +57,8 @@ ...@@ -56,7 +57,8 @@
points: { show: true } points: { show: true }
}, { }, {
data: d6, data: d6,
lines: { show: true, steps: true } lines: { show: true, steps: true },
points: { show: true }
}]); }]);
// Add the Flot version string to the footer // Add the Flot version string to the footer
......
...@@ -79,7 +79,6 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -79,7 +79,6 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
px, py, intery, qx, qy, bottom, px, py, intery, qx, qy, bottom,
withlines = s.lines.show, withlines = s.lines.show,
withbottom = ps > 2 && datapoints.format[2].y, withbottom = ps > 2 && datapoints.format[2].y,
withsteps = withlines && s.lines.steps,
fromgap = true, fromgap = true,
i = 0, i = 0,
j = 0, j = 0,
...@@ -196,18 +195,6 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -196,18 +195,6 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
newpoints[l + 2] = bottom; newpoints[l + 2] = bottom;
} }
} }
// maintain the line steps invariant
if (withsteps && l !== newpoints.length && l > 0 &&
newpoints[l] !== null &&
newpoints[l] !== newpoints[ l - ps ] &&
newpoints[l + 1] !== newpoints[l - ps + 1] ) {
for (m = 0; m < ps; ++m) {
newpoints[l + ps + m] = newpoints[l + m];
}
newpoints[l + 1] = newpoints[l - ps + 1];
}
} }
datapoints.points = newpoints; datapoints.points = newpoints;
......
...@@ -1271,8 +1271,7 @@ Licensed under the MIT license. ...@@ -1271,8 +1271,7 @@ Licensed under the MIT license.
ps = s.datapoints.pointsize; ps = s.datapoints.pointsize;
points = s.datapoints.points; points = s.datapoints.points;
var insertSteps = s.lines.show && s.lines.steps;
s.xaxis.used = s.yaxis.used = true; s.xaxis.used = s.yaxis.used = true;
for (j = k = 0; j < data.length; ++j, k += ps) { for (j = k = 0; j < data.length; ++j, k += ps) {
...@@ -1328,25 +1327,6 @@ Licensed under the MIT license. ...@@ -1328,25 +1327,6 @@ Licensed under the MIT license.
} }
points[k + m] = null; points[k + m] = null;
} }
} else {
// a little bit of line specific stuff that
// perhaps shouldn't be here, but lacking
// better means...
if (insertSteps && k > 0 &&
points[k - ps] != null &&
points[k - ps] !== points[k] &&
points[k - ps + 1] !== points[k + 1]) {
// copy the point to make room for a middle point
for (m = 0; m < ps; ++m) {
points[k + ps + m] = points[k + m];
}
// middle point has same y
points[k + 1] = points[k - ps + 1];
// we've added a point, better reflect that
k += ps;
}
} }
} }
} }
...@@ -2426,6 +2406,7 @@ Licensed under the MIT license. ...@@ -2426,6 +2406,7 @@ Licensed under the MIT license.
function plotLine(datapoints, xoffset, yoffset, axisx, axisy) { function plotLine(datapoints, xoffset, yoffset, axisx, axisy) {
var points = datapoints.points, var points = datapoints.points,
ps = datapoints.pointsize, ps = datapoints.pointsize,
showSteps = series.lines.steps,
prevx = null, prevy = null; prevx = null, prevy = null;
ctx.beginPath(); ctx.beginPath();
...@@ -2443,13 +2424,13 @@ Licensed under the MIT license. ...@@ -2443,13 +2424,13 @@ Licensed under the MIT license.
continue; // line segment is outside continue; // line segment is outside
} }
// compute new intersection point // compute new intersection point
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.min; y1 = axisy.min;
} else if (y2 <= y1 && y2 < axisy.min) { } else if (y2 <= y1 && y2 < axisy.min) {
if (y1 < axisy.min) { if (y1 < axisy.min) {
continue; continue;
} }
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.min; y2 = axisy.min;
} }
...@@ -2458,13 +2439,13 @@ Licensed under the MIT license. ...@@ -2458,13 +2439,13 @@ Licensed under the MIT license.
if (y2 > axisy.max) { if (y2 > axisy.max) {
continue; continue;
} }
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = showSteps ? x2 : (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.max; y1 = axisy.max;
} else if (y2 >= y1 && y2 > axisy.max) { } else if (y2 >= y1 && y2 > axisy.max) {
if (y1 > axisy.max) { if (y1 > axisy.max) {
continue; continue;
} }
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = showSteps ? x2 : (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.max; y2 = axisy.max;
} }
...@@ -2473,13 +2454,13 @@ Licensed under the MIT license. ...@@ -2473,13 +2454,13 @@ Licensed under the MIT license.
if (x2 < axisx.min) { if (x2 < axisx.min) {
continue; continue;
} }
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = showSteps ? y1 : (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.min; x1 = axisx.min;
} else if (x2 <= x1 && x2 < axisx.min) { } else if (x2 <= x1 && x2 < axisx.min) {
if (x1 < axisx.min) { if (x1 < axisx.min) {
continue; continue;
} }
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = showSteps ? y1 : (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.min; x2 = axisx.min;
} }
...@@ -2488,13 +2469,13 @@ Licensed under the MIT license. ...@@ -2488,13 +2469,13 @@ Licensed under the MIT license.
if (x2 > axisx.max) { if (x2 > axisx.max) {
continue; continue;
} }
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = showSteps ? y1 : (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.max; x1 = axisx.max;
} else if (x2 >= x1 && x2 > axisx.max) { } else if (x2 >= x1 && x2 > axisx.max) {
if (x1 > axisx.max) { if (x1 > axisx.max) {
continue; continue;
} }
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = showSteps ? y1 : (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.max; x2 = axisx.max;
} }
...@@ -2504,6 +2485,14 @@ Licensed under the MIT license. ...@@ -2504,6 +2485,14 @@ Licensed under the MIT license.
prevx = x2; prevx = x2;
prevy = y2; prevy = y2;
// Draw a step
if (showSteps) {
if (x1 < x2) {
ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y1) + yoffset);
} else {
ctx.lineTo(axisx.p2c(x1) + xoffset, axisy.p2c(y2) + yoffset);
}
}
ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset); ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset);
} }
ctx.stroke(); ctx.stroke();
...@@ -2512,6 +2501,7 @@ Licensed under the MIT license. ...@@ -2512,6 +2501,7 @@ Licensed under the MIT license.
function plotLineArea(datapoints, axisx, axisy) { function plotLineArea(datapoints, axisx, axisy) {
var points = datapoints.points, var points = datapoints.points,
ps = datapoints.pointsize, ps = datapoints.pointsize,
showSteps = series.lines.steps,
bottom = Math.min(Math.max(0, axisy.min), axisy.max), bottom = Math.min(Math.max(0, axisy.min), axisy.max),
i = 0, areaOpen = false, i = 0, areaOpen = false,
ypos = 1, segmentStart = 0, segmentEnd = 0; ypos = 1, segmentStart = 0, segmentEnd = 0;
...@@ -2561,13 +2551,13 @@ Licensed under the MIT license. ...@@ -2561,13 +2551,13 @@ Licensed under the MIT license.
if (x2 < axisx.min) { if (x2 < axisx.min) {
continue; continue;
} }
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = showSteps ? y1 : (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.min; x1 = axisx.min;
} else if (x2 <= x1 && x2 < axisx.min) { } else if (x2 <= x1 && x2 < axisx.min) {
if (x1 < axisx.min) { if (x1 < axisx.min) {
continue; continue;
} }
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = showSteps ? y1 : (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.min; x2 = axisx.min;
} }
...@@ -2576,13 +2566,13 @@ Licensed under the MIT license. ...@@ -2576,13 +2566,13 @@ Licensed under the MIT license.
if (x2 > axisx.max) { if (x2 > axisx.max) {
continue; continue;
} }
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = showSteps ? y1 : (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.max; x1 = axisx.max;
} else if (x2 >= x1 && x2 > axisx.max) { } else if (x2 >= x1 && x2 > axisx.max) {
if (x1 > axisx.max) { if (x1 > axisx.max) {
continue; continue;
} }
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = showSteps ? y1 : (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.max; x2 = axisx.max;
} }
...@@ -2615,19 +2605,19 @@ Licensed under the MIT license. ...@@ -2615,19 +2605,19 @@ Licensed under the MIT license.
// clip with ymin // clip with ymin
if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) {
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.min; y1 = axisy.min;
} else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) { } else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) {
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.min; y2 = axisy.min;
} }
// clip with ymax // clip with ymax
if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) { if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) {
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = showSteps ? x2 : (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.max; y1 = axisy.max;
} else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) { } else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) {
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = showSteps ? x2 : (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.max; y2 = axisy.max;
} }
...@@ -2642,6 +2632,14 @@ Licensed under the MIT license. ...@@ -2642,6 +2632,14 @@ Licensed under the MIT license.
// in redundant points if (x1, y1) hasn't changed // in redundant points if (x1, y1) hasn't changed
// from previous line to, but we just ignore that // from previous line to, but we just ignore that
ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1)); ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1));
// Draw a step
if (showSteps) {
if (x1 < x2) {
ctx.lineTo(axisx.p2c(x2), axisy.p2c(y1));
} else {
ctx.lineTo(axisx.p2c(x1), axisy.p2c(y2));
}
}
ctx.lineTo(axisx.p2c(x2), axisy.p2c(y2)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(y2));
// fill the other rectangle if it's there // fill the other rectangle if it's there
......
...@@ -75,7 +75,6 @@ charts or filled areas). ...@@ -75,7 +75,6 @@ charts or filled areas).
withlines = s.lines.show, withlines = s.lines.show,
horizontal = s.bars.horizontal, horizontal = s.bars.horizontal,
withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y), withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y),
withsteps = withlines && s.lines.steps,
fromgap = true, fromgap = true,
keyOffset = horizontal ? 1 : 0, keyOffset = horizontal ? 1 : 0,
accumulateOffset = horizontal ? 0 : 1, accumulateOffset = horizontal ? 0 : 1,
...@@ -169,17 +168,6 @@ charts or filled areas). ...@@ -169,17 +168,6 @@ charts or filled areas).
newpoints[l + 2] += bottom; newpoints[l + 2] += bottom;
} }
} }
// maintain the line steps invariant
if (withsteps && l !== newpoints.length && l > 0 &&
newpoints[l] != null &&
newpoints[l] !== newpoints[l - ps] &&
newpoints[l + 1] !== newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m) {
newpoints[l + ps + m] = newpoints[l + m];
}
newpoints[l + 1] = newpoints[l - ps + 1];
}
} }
datapoints.points = newpoints; datapoints.points = newpoints;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment