Commit e0413b93 authored by David Schnur's avatar David Schnur

Factor out duplicate variable definitions.

parent f39c71fb
...@@ -322,7 +322,7 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -322,7 +322,7 @@ browser, but needs to redraw with canvas text when exporting as an image.
// Fill in the x & y positions of each line, adjusting them // Fill in the x & y positions of each line, adjusting them
// individually for horizontal alignment. // individually for horizontal alignment.
for (var i = 0, line; line = lines[i]; i++) { for (var j = 0, line; line = lines[j]; j++) {
if (halign === "center") { if (halign === "center") {
position.lines.push([Math.round(x - line.width / 2), y]); position.lines.push([Math.round(x - line.width / 2), y]);
} else if (halign === "right") { } else if (halign === "right") {
......
...@@ -181,21 +181,23 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -181,21 +181,23 @@ shadowSize and lineWidth are derived as well from the points series.
ps = s.datapoints.pointsize, ps = s.datapoints.pointsize,
ax = [s.xaxis, s.yaxis], ax = [s.xaxis, s.yaxis],
radius = s.points.radius, radius = s.points.radius,
err = [s.points.xerr, s.points.yerr]; err = [s.points.xerr, s.points.yerr],
invertX = false,
invertY = false,
tmp;
//sanity check, in case some inverted axis hack is applied to flot //sanity check, in case some inverted axis hack is applied to flot
var invertX = false;
if (ax[0].p2c(ax[0].max) < ax[0].p2c(ax[0].min)) { if (ax[0].p2c(ax[0].max) < ax[0].p2c(ax[0].min)) {
invertX = true; invertX = true;
var tmp = err[0].lowerCap; tmp = err[0].lowerCap;
err[0].lowerCap = err[0].upperCap; err[0].lowerCap = err[0].upperCap;
err[0].upperCap = tmp; err[0].upperCap = tmp;
} }
var invertY = false;
if (ax[1].p2c(ax[1].min) < ax[1].p2c(ax[1].max)) { if (ax[1].p2c(ax[1].min) < ax[1].p2c(ax[1].max)) {
invertY = true; invertY = true;
var tmp = err[1].lowerCap; tmp = err[1].lowerCap;
err[1].lowerCap = err[1].upperCap; err[1].lowerCap = err[1].upperCap;
err[1].upperCap = tmp; err[1].upperCap = tmp;
} }
...@@ -249,7 +251,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -249,7 +251,7 @@ shadowSize and lineWidth are derived as well from the points series.
//sanity check, in case some inverted axis hack is applied to flot //sanity check, in case some inverted axis hack is applied to flot
if ((err[e].err === "x" && invertX) || (err[e].err === "y" && invertY)) { if ((err[e].err === "x" && invertX) || (err[e].err === "y" && invertY)) {
//swap coordinates //swap coordinates
var tmp = lower; tmp = lower;
lower = upper; lower = upper;
upper = tmp; upper = tmp;
tmp = drawLower; tmp = drawLower;
......
...@@ -459,6 +459,7 @@ Licensed under the MIT license. ...@@ -459,6 +459,7 @@ Licensed under the MIT license.
// Angle is currently unused, it will be implemented in the future. // Angle is currently unused, it will be implemented in the future.
Canvas.prototype.removeText = function(layer, x, y, text, font, angle) { Canvas.prototype.removeText = function(layer, x, y, text, font, angle) {
var i, positions, position;
if (text == null) { if (text == null) {
var layerCache = this._textCache[layer]; var layerCache = this._textCache[layer];
if (layerCache != null) { if (layerCache != null) {
...@@ -467,8 +468,8 @@ Licensed under the MIT license. ...@@ -467,8 +468,8 @@ Licensed under the MIT license.
var styleCache = layerCache[styleKey]; var styleCache = layerCache[styleKey];
for (var key in styleCache) { for (var key in styleCache) {
if (hasOwnProperty.call(styleCache, key)) { if (hasOwnProperty.call(styleCache, key)) {
var positions = styleCache[key].positions; positions = styleCache[key].positions;
for (var i = 0, position; position = positions[i]; i++) { for (i = 0; position = positions[i]; i++) {
position.active = false; position.active = false;
} }
} }
...@@ -477,8 +478,8 @@ Licensed under the MIT license. ...@@ -477,8 +478,8 @@ Licensed under the MIT license.
} }
} }
} else { } else {
var positions = this.getTextInfo(layer, text, font, angle).positions; positions = this.getTextInfo(layer, text, font, angle).positions;
for (var i = 0, position; position = positions[i]; i++) { for (i = 0; position = positions[i]; i++) {
if (position.x === x && position.y === y) { if (position.x === x && position.y === y) {
position.active = false; position.active = false;
} }
...@@ -1549,11 +1550,13 @@ Licensed under the MIT license. ...@@ -1549,11 +1550,13 @@ Licensed under the MIT license.
} }
function setupGrid() { function setupGrid() {
var i, axes = allAxes(), showGrid = options.grid.show; var axes = allAxes(),
showGrid = options.grid.show,
i, a;
// Initialize the plot's offset from the edge of the canvas // Initialize the plot's offset from the edge of the canvas
for (var a in plotOffset) { for (a in plotOffset) {
var margin = options.grid.margin || 0; var margin = options.grid.margin || 0;
plotOffset[a] = typeof margin === "number" ? margin : margin[a] || 0; plotOffset[a] = typeof margin === "number" ? margin : margin[a] || 0;
} }
...@@ -1562,7 +1565,7 @@ Licensed under the MIT license. ...@@ -1562,7 +1565,7 @@ Licensed under the MIT license.
// If the grid is visible, add its border width to the offset // If the grid is visible, add its border width to the offset
for (var a in plotOffset) { for (a in plotOffset) {
if(typeof(options.grid.borderWidth) === "object") { if(typeof(options.grid.borderWidth) === "object") {
plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0; plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0;
} else { } else {
...@@ -2750,11 +2753,11 @@ Licensed under the MIT license. ...@@ -2750,11 +2753,11 @@ Licensed under the MIT license.
} }
var fragments = [], entries = [], rowStarted = false, var fragments = [], entries = [], rowStarted = false,
lf = options.legend.labelFormatter, s, label; lf = options.legend.labelFormatter, s, label, i;
// Build a list of legend entries, with each having a label and a color // Build a list of legend entries, with each having a label and a color
for (var i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
if (s.label) { if (s.label) {
label = lf ? lf(s.label, s) : s.label; label = lf ? lf(s.label, s) : s.label;
...@@ -2786,7 +2789,7 @@ Licensed under the MIT license. ...@@ -2786,7 +2789,7 @@ Licensed under the MIT license.
// Generate markup for the list of entries, in their final order // Generate markup for the list of entries, in their final order
for (var i = 0; i < entries.length; ++i) { for (i = 0; i < entries.length; ++i) {
var entry = entries[i]; var entry = entries[i];
...@@ -2878,7 +2881,8 @@ Licensed under the MIT license. ...@@ -2878,7 +2881,8 @@ Licensed under the MIT license.
mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster
my = axisy.c2p(mouseY), my = axisy.c2p(mouseY),
maxx = maxDistance / axisx.scale, maxx = maxDistance / axisx.scale,
maxy = maxDistance / axisy.scale; maxy = maxDistance / axisy.scale,
x, y;
ps = s.datapoints.pointsize; ps = s.datapoints.pointsize;
// with inverse transforms, we can't use the maxx/maxy // with inverse transforms, we can't use the maxx/maxy
...@@ -2892,7 +2896,10 @@ Licensed under the MIT license. ...@@ -2892,7 +2896,10 @@ Licensed under the MIT license.
if (s.lines.show || s.points.show) { if (s.lines.show || s.points.show) {
for (j = 0; j < points.length; j += ps) { for (j = 0; j < points.length; j += ps) {
var x = points[j], y = points[j + 1];
x = points[j];
y = points[j + 1];
if (x == null) { if (x == null) {
continue; continue;
} }
...@@ -2924,7 +2931,9 @@ Licensed under the MIT license. ...@@ -2924,7 +2931,9 @@ Licensed under the MIT license.
barRight = barLeft + s.bars.barWidth; barRight = barLeft + s.bars.barWidth;
for (j = 0; j < points.length; j += ps) { for (j = 0; j < points.length; j += ps) {
var x = points[j], y = points[j + 1], b = points[j + 2]; x = points[j];
y = points[j + 1];
var b = points[j + 2];
if (x == null) { if (x == null) {
continue; continue;
} }
......
...@@ -165,13 +165,14 @@ More detail and specific examples can be found in the included HTML file. ...@@ -165,13 +165,14 @@ More detail and specific examples can be found in the included HTML file.
combined = 0, combined = 0,
numCombined = 0, numCombined = 0,
color = options.series.pie.combine.color, color = options.series.pie.combine.color,
newdata = []; newdata = [],
i, value;
// Fix up the raw data from Flot, ensuring the data is numeric // Fix up the raw data from Flot, ensuring the data is numeric
for (var i = 0; i < data.length; ++i) { for (i = 0; i < data.length; ++i) {
var value = data[i].data; value = data[i].data;
// If the data is an array, we'll assume that it's a standard // If the data is an array, we'll assume that it's a standard
// Flot x-y pair, and are concerned only with the second value. // Flot x-y pair, and are concerned only with the second value.
...@@ -202,15 +203,15 @@ More detail and specific examples can be found in the included HTML file. ...@@ -202,15 +203,15 @@ More detail and specific examples can be found in the included HTML file.
// Sum up all the slices, so we can calculate percentages for each // Sum up all the slices, so we can calculate percentages for each
for (var i = 0; i < data.length; ++i) { for (i = 0; i < data.length; ++i) {
total += data[i].data[0][1]; total += data[i].data[0][1];
} }
// Count the number of slices with percentages below the combine // Count the number of slices with percentages below the combine
// threshold; if it turns out to be just one, we won't combine. // threshold; if it turns out to be just one, we won't combine.
for (var i = 0; i < data.length; ++i) { for (i = 0; i < data.length; ++i) {
var value = data[i].data[0][1]; value = data[i].data[0][1];
if (value / total <= options.series.pie.combine.threshold) { if (value / total <= options.series.pie.combine.threshold) {
combined += value; combined += value;
numCombined++; numCombined++;
...@@ -220,8 +221,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -220,8 +221,8 @@ More detail and specific examples can be found in the included HTML file.
} }
} }
for (var i = 0; i < data.length; ++i) { for (i = 0; i < data.length; ++i) {
var value = data[i].data[0][1]; value = data[i].data[0][1];
if (numCombined < 2 || value / total > options.series.pie.combine.threshold) { if (numCombined < 2 || value / total > options.series.pie.combine.threshold) {
newdata.push({ newdata.push({
data: [[1, value]], data: [[1, value]],
...@@ -373,8 +374,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -373,8 +374,9 @@ More detail and specific examples can be found in the included HTML file.
function drawPie() { function drawPie() {
var startAngle = Math.PI * options.series.pie.startAngle; var startAngle = Math.PI * options.series.pie.startAngle,
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius,
i;
// center and rotate to starting position // center and rotate to starting position
...@@ -387,7 +389,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -387,7 +389,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save(); ctx.save();
var currentAngle = startAngle; var currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i) { for (i = 0; i < slices.length; ++i) {
slices[i].startAngle = currentAngle; slices[i].startAngle = currentAngle;
drawSlice(slices[i].angle, slices[i].color, true); drawSlice(slices[i].angle, slices[i].color, true);
} }
...@@ -399,7 +401,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -399,7 +401,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save(); ctx.save();
ctx.lineWidth = options.series.pie.stroke.width; ctx.lineWidth = options.series.pie.stroke.width;
currentAngle = startAngle; currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i) { for (i = 0; i < slices.length; ++i) {
drawSlice(slices[i].angle, options.series.pie.stroke.color, false); drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
} }
ctx.restore(); ctx.restore();
......
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