Commit f335b499 authored by Nick Schonning's avatar Nick Schonning

JSCS: Combine variable declarations

This only covers declarations that are consecutive
parent e1cd9760
...@@ -31,9 +31,8 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -31,9 +31,8 @@ browser, but needs to redraw with canvas text when exporting as an image.
var options = { var options = {
canvas: true canvas: true
}; },
render, getTextInfo, addText;
var render, getTextInfo, addText;
function init(plot, classes) { function init(plot, classes) {
......
...@@ -82,9 +82,8 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -82,9 +82,8 @@ shadowSize and lineWidth are derived as well from the points series.
var format = [ var format = [
{ x: true, number: true, required: true }, { x: true, number: true, required: true },
{ y: true, number: true, required: true } { y: true, number: true, required: true }
]; ],
errors = series.points.errorbars;
var errors = series.points.errorbars;
// error bars - first X then Y // error bars - first X then Y
if (errors === "x" || errors === "xy") { if (errors === "x" || errors === "xy") {
// lower / upper error // lower / upper error
...@@ -95,6 +94,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -95,6 +94,7 @@ shadowSize and lineWidth are derived as well from the points series.
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
} }
} }
if (errors === "y" || errors === "xy") { if (errors === "y" || errors === "xy") {
// lower / upper error // lower / upper error
if (series.points.yerr.asymmetric) { if (series.points.yerr.asymmetric) {
...@@ -109,10 +109,10 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -109,10 +109,10 @@ shadowSize and lineWidth are derived as well from the points series.
function parseErrors(series, i) { function parseErrors(series, i) {
var points = series.datapoints.points; var points = series.datapoints.points,
// read errors from points array // read errors from points array
var exl = null, exl = null,
exu = null, exu = null,
eyl = null, eyl = null,
eyu = null, eyu = null,
...@@ -184,7 +184,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -184,7 +184,7 @@ shadowSize and lineWidth are derived as well from the points series.
err = [s.points.xerr, s.points.yerr], err = [s.points.xerr, s.points.yerr],
invertX = false, invertX = false,
invertY = false, invertY = false,
tmp; tmp, errRanges, minmax, e, x, y, upper, lower, drawLower, drawUpper;
//sanity check, in case some inverted axis hack is applied to flot //sanity check, in case some inverted axis hack is applied to flot
...@@ -204,23 +204,23 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -204,23 +204,23 @@ shadowSize and lineWidth are derived as well from the points series.
for (var i = 0; i < s.datapoints.points.length; i += ps) { for (var i = 0; i < s.datapoints.points.length; i += ps) {
var errRanges = parseErrors(s, i); errRanges = parseErrors(s, i);
//cycle xerr & yerr //cycle xerr & yerr
for (var e = 0; e < err.length; e++){ for (e = 0; e < err.length; e++){
var minmax = [ax[e].min, ax[e].max]; minmax = [ax[e].min, ax[e].max];
//draw this error? //draw this error?
if (errRanges[e * err.length]){ if (errRanges[e * err.length]){
//data coordinates //data coordinates
var x = points[i], x = points[i];
y = points[i + 1]; y = points[i + 1];
//errorbar ranges //errorbar ranges
var upper = [x, y][e] + errRanges[e * err.length + 1], upper = [x, y][e] + errRanges[e * err.length + 1];
lower = [x, y][e] - errRanges[e * err.length]; lower = [x, y][e] - errRanges[e * err.length];
//points outside of the canvas //points outside of the canvas
if (err[e].err === "x") { if (err[e].err === "x") {
...@@ -235,8 +235,8 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -235,8 +235,8 @@ shadowSize and lineWidth are derived as well from the points series.
} }
// prevent errorbars getting out of the canvas // prevent errorbars getting out of the canvas
var drawUpper = true, drawUpper = true,
drawLower = true; drawLower = true;
if (upper > minmax[1]) { if (upper > minmax[1]) {
drawUpper = false; drawUpper = false;
......
...@@ -66,9 +66,9 @@ Google Maps). ...@@ -66,9 +66,9 @@ Google Maps).
$.plot.image = {}; $.plot.image = {};
$.plot.image.loadDataImages = function(series, options, callback) { $.plot.image.loadDataImages = function(series, options, callback) {
var urls = [], points = []; var urls = [],
points = [],
var defaultShow = options.series.images.show; defaultShow = options.series.images.show;
$.each(series, function(i, s) { $.each(series, function(i, s) {
if (!(defaultShow || s.images.show)) { if (!(defaultShow || s.images.show)) {
......
...@@ -48,17 +48,17 @@ Licensed under the MIT license. ...@@ -48,17 +48,17 @@ Licensed under the MIT license.
this.element = element; this.element = element;
var context = this.context = element.getContext("2d"); var context = this.context = element.getContext("2d"),
// Determine the screen's ratio of physical to device-independent // Determine the screen's ratio of physical to device-independent
// pixels. This is the ratio between the canvas width that the browser // pixels. This is the ratio between the canvas width that the browser
// advertises and the number of pixels actually present in that space. // advertises and the number of pixels actually present in that space.
// The iPhone 4, for example, has a device-independent width of 320px, // The iPhone 4, for example, has a device-independent width of 320px,
// but its screen is actually 640px wide. It therefore has a pixel // but its screen is actually 640px wide. It therefore has a pixel
// ratio of 2, while most normal devices have a ratio of 1. // ratio of 2, while most normal devices have a ratio of 1.
var devicePixelRatio = window.devicePixelRatio || 1, devicePixelRatio = window.devicePixelRatio || 1,
backingStoreRatio = backingStoreRatio =
context.webkitBackingStorePixelRatio || context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio || context.mozBackingStorePixelRatio ||
...@@ -370,22 +370,23 @@ Licensed under the MIT license. ...@@ -370,22 +370,23 @@ Licensed under the MIT license.
var cx = textWidth / 2, var cx = textWidth / 2,
cy = textHeight / 2, cy = textHeight / 2,
transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px"; transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px",
// Transforms alter the div's appearance without changing // Transforms alter the div's appearance without changing
// its origin. This will make it difficult to position it // its origin. This will make it difficult to position it
// later, since we'll be positioning the new bounding box // later, since we'll be positioning the new bounding box
// with respect to the old origin. We can work around this // with respect to the old origin. We can work around this
// by adding a translation to align the new bounding box's // by adding a translation to align the new bounding box's
// top-left corner with the origin, using the same matrix. // top-left corner with the origin, using the same matrix.
// Rather than examining all four points, we can use the // Rather than examining all four points, we can use the
// angle to figure out in advance which two points are in // angle to figure out in advance which two points are in
// the top-left quadrant; we can then use the x-coordinate // the top-left quadrant; we can then use the x-coordinate
// of the first (left-most) point and the y-coordinate of // of the first (left-most) point and the y-coordinate of
// the second (top-most) point as the bounding box corner. // the second (top-most) point as the bounding box corner.
var x, y; x, y;
if (angle < 90) { if (angle < 90) {
x = Math.floor(cx * cos + cy * sin - cx); x = Math.floor(cx * cos + cy * sin - cx);
y = Math.floor(cx * sin + cy * cos - cy); y = Math.floor(cx * sin + cy * cos - cy);
...@@ -1902,10 +1903,12 @@ Licensed under the MIT license. ...@@ -1902,10 +1903,12 @@ Licensed under the MIT license.
} }
function setupTickGeneration(axis) { function setupTickGeneration(axis) {
var opts = axis.options; var opts = axis.options,
// estimate number of ticks
noTicks;
// estimate number of ticks
var noTicks;
if (isNumeric(opts.ticks) && opts.ticks > 0) { if (isNumeric(opts.ticks) && opts.ticks > 0) {
noTicks = opts.ticks; noTicks = opts.ticks;
} else { } else {
...@@ -1982,15 +1985,16 @@ Licensed under the MIT license. ...@@ -1982,15 +1985,16 @@ Licensed under the MIT license.
axis.tickFormatter = function(value, axis) { axis.tickFormatter = function(value, axis) {
var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1; var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1,
var formatted = "" + Math.round(value * factor) / factor; formatted = "" + Math.round(value * factor) / factor;
// If tickDecimals was specified, ensure that we have exactly that // If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision. // much precision; otherwise default to the value's own precision.
if (axis.tickDecimals != null) { if (axis.tickDecimals != null) {
var decimal = formatted.indexOf("."); var decimal = formatted.indexOf("."),
var precision = decimal === -1 ? 0 : formatted.length - decimal - 1; precision = decimal === -1 ? 0 : formatted.length - decimal - 1;
if (precision < axis.tickDecimals) { if (precision < axis.tickDecimals) {
return (precision ? formatted : formatted + ".") + ("" + factor).substr(1, axis.tickDecimals - precision); return (precision ? formatted : formatted + ".") + ("" + factor).substr(1, axis.tickDecimals - precision);
} }
...@@ -2063,8 +2067,9 @@ Licensed under the MIT license. ...@@ -2063,8 +2067,9 @@ Licensed under the MIT license.
var i, v; var i, v;
axis.ticks = []; axis.ticks = [];
for (i = 0; i < ticks.length; ++i) { for (i = 0; i < ticks.length; ++i) {
var label = null; var label = null,
var t = ticks[i]; t = ticks[i];
if (typeof t === "object") { if (typeof t === "object") {
v = +t[0]; v = +t[0];
if (t.length > 1) { if (t.length > 1) {
...@@ -2184,10 +2189,10 @@ Licensed under the MIT license. ...@@ -2184,10 +2189,10 @@ Licensed under the MIT license.
surface.removeText(markingLayer); surface.removeText(markingLayer);
// process markings // process markings
var markingsUnderGrid = []; var markingsUnderGrid = [],
var markingsAboveGrid = []; markingsAboveGrid = [],
markings = options.grid.markings;
var markings = options.grid.markings;
if (markings) { if (markings) {
if ($.isFunction(markings)) { if ($.isFunction(markings)) {
axes = plot.getAxes(); axes = plot.getAxes();
...@@ -2448,9 +2453,12 @@ Licensed under the MIT license. ...@@ -2448,9 +2453,12 @@ Licensed under the MIT license.
if (m.text) { if (m.text) {
// left aligned horizontal position: // left aligned horizontal position:
var xPos = xrange.from + plotOffset.left;
// top baselined vertical position: var xPos = xrange.from + plotOffset.left,
var yPos = (yrange.to + plotOffset.top);
// top baselined vertical position:
yPos = (yrange.to + plotOffset.top);
if (!!m.textAlign) { if (!!m.textAlign) {
switch (m.textAlign.toLowerCase()) { switch (m.textAlign.toLowerCase()) {
...@@ -3482,8 +3490,8 @@ Licensed under the MIT license. ...@@ -3482,8 +3490,8 @@ Licensed under the MIT license.
return; return;
} }
var pointRadius; var pointRadius, radius;
var radius;
if (series.points.show) { if (series.points.show) {
pointRadius = series.points.radius + series.points.lineWidth / 2; pointRadius = series.points.radius + series.points.lineWidth / 2;
radius = 1.5 * pointRadius; radius = 1.5 * pointRadius;
...@@ -3596,8 +3604,9 @@ Licensed under the MIT license. ...@@ -3596,8 +3604,9 @@ Licensed under the MIT license.
// @param {number} radius The radius of the corner of the rectangle // @param {number} radius The radius of the corner of the rectangle
// to be drawn. // to be drawn.
function roundRect(ctx, x, y, width, height, radius) { function roundRect(ctx, x, y, width, height, radius) {
var r = x + width; var r = x + width,
var b = y + height; b = y + height;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(x + radius, y); ctx.moveTo(x + radius, y);
ctx.lineTo(r - radius, y); ctx.lineTo(r - radius, y);
......
...@@ -59,11 +59,11 @@ More detail and specific examples can be found in the included HTML file. ...@@ -59,11 +59,11 @@ More detail and specific examples can be found in the included HTML file.
// Maximum redraw attempts when fitting labels within the plot // Maximum redraw attempts when fitting labels within the plot
var REDRAW_ATTEMPTS = 10; var REDRAW_ATTEMPTS = 10,
// Factor by which to shrink the pie when fitting labels within the plot // Factor by which to shrink the pie when fitting labels within the plot
var REDRAW_SHRINK = 0.95; REDRAW_SHRINK = 0.95;
function init(plot) { function init(plot) {
...@@ -74,11 +74,11 @@ More detail and specific examples can be found in the included HTML file. ...@@ -74,11 +74,11 @@ More detail and specific examples can be found in the included HTML file.
centerLeft = null, centerLeft = null,
centerTop = null, centerTop = null,
processed = false, processed = false,
ctx = null; ctx = null,
// interactive variables // interactive variables
var highlights = []; highlights = [];
// add hook to determine if pie plugin in enabled, and then perform necessary operations // add hook to determine if pie plugin in enabled, and then perform necessary operations
...@@ -340,11 +340,11 @@ More detail and specific examples can be found in the included HTML file. ...@@ -340,11 +340,11 @@ More detail and specific examples can be found in the included HTML file.
function drawShadow() { function drawShadow() {
var shadowLeft = options.series.pie.shadow.left; var shadowLeft = options.series.pie.shadow.left,
var shadowTop = options.series.pie.shadow.top; shadowTop = options.series.pie.shadow.top,
var edge = 10; edge = 10,
var alpha = options.series.pie.shadow.alpha; alpha = options.series.pie.shadow.alpha,
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;
if (radius >= canvasWidth / 2 - shadowLeft || radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop || radius <= edge) { if (radius >= canvasWidth / 2 - shadowLeft || radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop || radius <= edge) {
return; // shadow would be outside canvas, so don't draw it return; // shadow would be outside canvas, so don't draw it
...@@ -455,8 +455,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -455,8 +455,8 @@ More detail and specific examples can be found in the included HTML file.
function drawLabels() { function drawLabels() {
var currentAngle = startAngle; var currentAngle = startAngle,
var radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius; radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius;
for (var i = 0; i < slices.length; ++i) { for (var i = 0; i < slices.length; ++i) {
if (slices[i].percent >= options.series.pie.label.threshold * 100) { if (slices[i].percent >= options.series.pie.label.threshold * 100) {
...@@ -489,16 +489,16 @@ More detail and specific examples can be found in the included HTML file. ...@@ -489,16 +489,16 @@ More detail and specific examples can be found in the included HTML file.
text = plf(text, slice); text = plf(text, slice);
} }
var halfAngle = ((startAngle + slice.angle) + startAngle) / 2; var halfAngle = ((startAngle + slice.angle) + startAngle) / 2,
var x = centerLeft + Math.round(Math.cos(halfAngle) * radius); x = centerLeft + Math.round(Math.cos(halfAngle) * radius),
var y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt; y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt,
html = "<span class='pieLabel' id='pieLabel" + index + "' style='position:absolute;top:" + y + "px;left:" + x + "px;'>" + text + "</span>";
var html = "<span class='pieLabel' id='pieLabel" + index + "' style='position:absolute;top:" + y + "px;left:" + x + "px;'>" + text + "</span>";
target.append(html); target.append(html);
var label = target.children("#pieLabel" + index); var label = target.children("#pieLabel" + index),
var labelTop = (y - label.height() / 2); labelTop = (y - label.height() / 2),
var labelLeft = (x - label.width() / 2); labelLeft = (x - label.width() / 2);
label.css("top", labelTop); label.css("top", labelTop);
label.css("left", labelLeft); label.css("left", labelLeft);
...@@ -656,10 +656,10 @@ More detail and specific examples can be found in the included HTML file. ...@@ -656,10 +656,10 @@ More detail and specific examples can be found in the included HTML file.
function triggerClickHoverEvent(eventname, e) { function triggerClickHoverEvent(eventname, e) {
var offset = plot.offset(); var offset = plot.offset(),
var canvasX = parseInt(e.pageX - offset.left, 10); canvasX = parseInt(e.pageX - offset.left, 10),
var canvasY = parseInt(e.pageY - offset.top, 10); canvasY = parseInt(e.pageY - offset.top, 10),
var item = findNearbySlice(canvasX, canvasY); item = findNearbySlice(canvasX, canvasY);
if (options.grid.autoHighlight) { if (options.grid.autoHighlight) {
...@@ -730,9 +730,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -730,9 +730,8 @@ More detail and specific examples can be found in the included HTML file.
function drawOverlay(plot, octx) { function drawOverlay(plot, octx) {
var options = plot.getOptions(); var options = plot.getOptions(),
radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
octx.save(); octx.save();
octx.translate(centerLeft, centerTop); octx.translate(centerLeft, centerTop);
......
...@@ -87,15 +87,15 @@ The plugin allso adds the following methods to the plot object: ...@@ -87,15 +87,15 @@ The plugin allso adds the following methods to the plot object:
show: false, show: false,
active: false, active: false,
touch: false touch: false
}; },
// FIXME: The drag handling implemented here should be // FIXME: The drag handling implemented here should be
// abstracted out, there's some similar code from a library in // abstracted out, there's some similar code from a library in
// the navigation plugin, this should be massaged a bit to fit // the navigation plugin, this should be massaged a bit to fit
// the Flot cases here better and reused. Doing this would // the Flot cases here better and reused. Doing this would
// make this plugin much slimmer. // make this plugin much slimmer.
var savedhandlers = {}, savedhandlers = {},
mouseUpHandler = null; mouseUpHandler = null;
function onMouseMove(e) { function onMouseMove(e) {
...@@ -206,9 +206,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -206,9 +206,9 @@ The plugin allso adds the following methods to the plot object:
function setSelectionPos(pos, e) { function setSelectionPos(pos, e) {
var o = plot.getOptions(), var o = plot.getOptions(),
offset = plot.getPlaceholder().offset(), offset = plot.getPlaceholder().offset(),
plotOffset = plot.getPlotOffset(); plotOffset = plot.getPlotOffset(),
coordHolder = selection.touch ? e.originalEvent.changedTouches[0] : e;
var coordHolder = selection.touch ? e.originalEvent.changedTouches[0] : e;
pos.x = clamp(0, coordHolder.pageX - offset.left - plotOffset.left, plot.width()); pos.x = clamp(0, coordHolder.pageX - offset.left - plotOffset.left, plot.width());
pos.y = clamp(0, coordHolder.pageY - offset.top - plotOffset.top, plot.height()); pos.y = clamp(0, coordHolder.pageY - offset.top - plotOffset.top, plot.height());
...@@ -340,23 +340,24 @@ The plugin allso adds the following methods to the plot object: ...@@ -340,23 +340,24 @@ The plugin allso adds the following methods to the plot object:
plot.hooks.drawOverlay.push(function(plot, ctx) { plot.hooks.drawOverlay.push(function(plot, ctx) {
// draw selection // draw selection
if (selection.show && selectionIsSane()) { if (selection.show && selectionIsSane()) {
var plotOffset = plot.getPlotOffset(); var plotOffset = plot.getPlotOffset(),
var o = plot.getOptions(); o = plot.getOptions(),
c, x, y, w, h;
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
var c = $.color.parse(o.selection.color); c = $.color.parse(o.selection.color);
ctx.strokeStyle = c.scale("a", 0.8).toString(); ctx.strokeStyle = c.scale("a", 0.8).toString();
ctx.lineWidth = 1; ctx.lineWidth = 1;
ctx.lineJoin = o.selection.shape; ctx.lineJoin = o.selection.shape;
ctx.fillStyle = c.scale("a", 0.4).toString(); ctx.fillStyle = c.scale("a", 0.4).toString();
var x = Math.min(selection.first.x, selection.second.x) + 0.5, x = Math.min(selection.first.x, selection.second.x) + 0.5;
y = Math.min(selection.first.y, selection.second.y) + 0.5, y = Math.min(selection.first.y, selection.second.y) + 0.5;
w = Math.abs(selection.second.x - selection.first.x) - 1, w = Math.abs(selection.second.x - selection.first.x) - 1;
h = Math.abs(selection.second.y - selection.first.y) - 1; h = Math.abs(selection.second.y - selection.first.y) - 1;
ctx.fillRect(x, y, w, h); ctx.fillRect(x, y, w, h);
ctx.strokeRect(x, y, w, h); ctx.strokeRect(x, y, w, h);
......
...@@ -19,42 +19,42 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -19,42 +19,42 @@ The symbols are accessed as strings through the standard symbol options:
// same as a circle of the given radius // same as a circle of the given radius
var handlers = { var handlers = {
square: function(ctx, x, y, radius) { square: function(ctx, x, y, radius) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2; var size = radius * Math.sqrt(Math.PI) / 2;
ctx.rect(x - size, y - size, size + size, size + size); ctx.rect(x - size, y - size, size + size, size + size);
}, },
diamond: function(ctx, x, y, radius) { diamond: function(ctx, x, y, radius) {
// pi * r^2 = 2s^2 => s = r * sqrt(pi/2) // pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
var size = radius * Math.sqrt(Math.PI / 2); var size = radius * Math.sqrt(Math.PI / 2);
ctx.moveTo(x - size, y); ctx.moveTo(x - size, y);
ctx.lineTo(x, y - size); ctx.lineTo(x, y - size);
ctx.lineTo(x + size, y); ctx.lineTo(x + size, y);
ctx.lineTo(x, y + size); ctx.lineTo(x, y + size);
ctx.lineTo(x - size, y); ctx.lineTo(x - size, y);
}, },
triangle: function(ctx, x, y, radius, shadow) { triangle: function(ctx, x, y, radius, shadow) {
// pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3)) // pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3))
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)); var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)),
var height = size * Math.sin(Math.PI / 3); height = size * Math.sin(Math.PI / 3);
ctx.moveTo(x - size / 2, y + height / 2); ctx.moveTo(x - size / 2, y + height / 2);
ctx.lineTo(x + size / 2, y + height / 2); ctx.lineTo(x + size / 2, y + height / 2);
if (!shadow) { if (!shadow) {
ctx.lineTo(x, y - height / 2); ctx.lineTo(x, y - height / 2);
ctx.lineTo(x - size / 2, y + height / 2); ctx.lineTo(x - size / 2, y + height / 2);
}
},
cross: function(ctx, x, y, radius) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.moveTo(x - size, y - size);
ctx.lineTo(x + size, y + size);
ctx.moveTo(x - size, y + size);
ctx.lineTo(x + size, y - size);
} }
}, },
cross: function(ctx, x, y, radius) { s = series.points.symbol;
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.moveTo(x - size, y - size);
ctx.lineTo(x + size, y + size);
ctx.moveTo(x - size, y + size);
ctx.lineTo(x + size, y - size);
}
};
var s = series.points.symbol;
if (handlers[s]) { if (handlers[s]) {
series.points.symbol = handlers[s]; series.points.symbol = handlers[s];
} }
......
...@@ -35,15 +35,15 @@ API.txt for details. ...@@ -35,15 +35,15 @@ API.txt for details.
} }
var leftPad = function(n, pad) { var leftPad = function(n, pad) {
n = "" + n; n = "" + n;
pad = "" + (pad == null ? "0" : pad); pad = "" + (pad == null ? "0" : pad);
return n.length === 1 ? pad + n : n; return n.length === 1 ? pad + n : n;
}; },
r = [],
var r = [],
escape = false, escape = false,
hours = d.getHours(), hours = d.getHours(),
isAM = hours < 12; isAM = hours < 12,
c, hours12;
if (monthNames == null) { if (monthNames == null) {
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
...@@ -53,8 +53,6 @@ API.txt for details. ...@@ -53,8 +53,6 @@ API.txt for details.
dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
} }
var hours12;
if (hours > 12) { if (hours > 12) {
hours12 = hours - 12; hours12 = hours - 12;
} else if (hours === 0) { } else if (hours === 0) {
...@@ -65,7 +63,7 @@ API.txt for details. ...@@ -65,7 +63,7 @@ API.txt for details.
for (var i = 0; i < fmt.length; ++i) { for (var i = 0; i < fmt.length; ++i) {
var c = fmt.charAt(i); c = fmt.charAt(i);
if (escape) { if (escape) {
switch (c) { switch (c) {
...@@ -81,7 +79,7 @@ API.txt for details. ...@@ -81,7 +79,7 @@ API.txt for details.
case "e": case "e":
c = leftPad(d.getDate(), " "); c = leftPad(d.getDate(), " ");
break; break;
case "h": // For back-compat with 0.7; remove in 1.0 case "h": // For back-compat with 0.7; remove in 1.0
case "H": case "H":
c = leftPad(hours); c = leftPad(hours);
break; break;
...@@ -193,37 +191,43 @@ API.txt for details. ...@@ -193,37 +191,43 @@ API.txt for details.
// map of app. size of time units in milliseconds // map of app. size of time units in milliseconds
var timeUnitSize = { var timeUnitSize = {
"second": 1000, "second": 1000,
"minute": 60 * 1000, "minute": 60 * 1000,
"hour": 60 * 60 * 1000, "hour": 60 * 60 * 1000,
"day": 24 * 60 * 60 * 1000, "day": 24 * 60 * 60 * 1000,
"month": 30 * 24 * 60 * 60 * 1000, "month": 30 * 24 * 60 * 60 * 1000,
"quarter": 3 * 30 * 24 * 60 * 60 * 1000, "quarter": 3 * 30 * 24 * 60 * 60 * 1000,
"year": 365.2425 * 24 * 60 * 60 * 1000 "year": 365.2425 * 24 * 60 * 60 * 1000
}; },
// the allowed tick sizes, after 1 year we use // the allowed tick sizes, after 1 year we use
// an integer algorithm // an integer algorithm
var baseSpec = [ baseSpec = [
[1, "second"], [2, "second"], [5, "second"], [10, "second"], [1, "second"], [2, "second"], [5, "second"], [10, "second"],
[30, "second"], [30, "second"],
[1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
[30, "minute"], [30, "minute"],
[1, "hour"], [2, "hour"], [4, "hour"], [1, "hour"], [2, "hour"], [4, "hour"],
[8, "hour"], [12, "hour"], [8, "hour"], [12, "hour"],
[1, "day"], [2, "day"], [3, "day"], [1, "day"], [2, "day"], [3, "day"],
[0.25, "month"], [0.5, "month"], [1, "month"], [0.25, "month"], [0.5, "month"], [1, "month"],
[2, "month"] [2, "month"]
]; ],
// we don't know which variant(s) we'll need yet, but generating both is // we don't know which variant(s) we'll need yet, but generating both is
// cheap // cheap
var specMonths = baseSpec.concat([[3, "month"], [6, "month"], specMonths = baseSpec.concat([
[1, "year"]]); [3, "month"],
var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"], [6, "month"],
[1, "year"]]); [1, "year"]
]),
specQuarters = baseSpec.concat([
[1, "quarter"],
[2, "quarter"],
[1, "year"]
]);
function init(plot) { function init(plot) {
plot.hooks.processOptions.push(function(plot) { plot.hooks.processOptions.push(function(plot) {
...@@ -236,12 +240,12 @@ API.txt for details. ...@@ -236,12 +240,12 @@ API.txt for details.
var ticks = [], var ticks = [],
d = dateGenerator(axis.min, opts), d = dateGenerator(axis.min, opts),
minSize = 0; minSize = 0,
// make quarter use a possibility if quarters are // make quarter use a possibility if quarters are
// mentioned in either of these options // mentioned in either of these options
var spec = (opts.tickSize && opts.tickSize[1] === spec = (opts.tickSize && opts.tickSize[1] ===
"quarter") || "quarter") ||
(opts.minTickSize && opts.minTickSize[1] === (opts.minTickSize && opts.minTickSize[1] ===
"quarter") ? specQuarters : specMonths; "quarter") ? specQuarters : specMonths;
......
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