Commit 1513877c authored by David Schnur's avatar David Schnur

Merge pull request #1229 from nschonni/add-grunt-jscs-checker

Add grunt jscs checker
parents 2d2efc54 f335b499
/*jshint node: true */ /*jshint node: true */
module.exports = function(grunt) { module.exports = function(grunt) {
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
// Metadata. // Metadata.
pkg: grunt.file.readJSON("package.json"), pkg: grunt.file.readJSON("package.json"),
banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - " + banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - " +
"* Copyright (c) <%= grunt.template.today('yyyy') %> IOLA and <%= pkg.author.name %>;" + "* Copyright (c) <%= grunt.template.today('yyyy') %> IOLA and <%= pkg.author.name %>;" +
" Licensed <%= pkg.license %> */\n", " Licensed <%= pkg.license %> */\n",
// Task configuration. // Task configuration.
uglify: { uglify: {
options: { options: {
banner: "<%= banner %>" banner: "<%= banner %>"
}, },
dist: { dist: {
expand: true, expand: true,
flatten: true, flatten: true,
src: ["jquery.*.js", "!jquery.js"], src: ["jquery.*.js", "!jquery.js"],
dest: "dist/", dest: "dist/",
rename: function(base, path) { rename: function(base, path) {
return base + path.replace(/\.js/, ".min.js"); return base + path.replace(/\.js/, ".min.js");
} }
} }
}, },
jshint: { jshint: {
options: grunt.file.readJSON(".jshintrc"), options: grunt.file.readJSON(".jshintrc"),
gruntfile: { gruntfile: {
src: "Gruntfile.js" src: "Gruntfile.js"
}, },
flot: { flot: {
src: ["jquery.flot*.js"] src: ["jquery.flot*.js"]
} }
}, },
watch: { watch: {
gruntfile: { gruntfile: {
files: "Gruntfile.js", files: "Gruntfile.js",
tasks: ["jshint:gruntfile"] tasks: ["jshint:gruntfile"]
}, },
flot: { flot: {
files: "<%= jshint.flot.src %>", files: "<%= jshint.flot.src %>",
tasks: ["jshint:flot"] tasks: ["jshint:flot"]
} }
} },
}); jscs: {
options: {
"requireCurlyBraces": [ "if", "else", "for", "while", "do" ],
"requireSpaceAfterKeywords": [ "if", "else", "for", "while", "do", "switch", "return" ],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireMultipleVarDecl": true,
"requireSpacesInsideObjectBrackets": "all", // Different from jQuery preset
"disallowSpacesInsideArrayBrackets": true, // Different from jQuery preset
"disallowLeftStickedOperators": [ "?", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<=" ],
"disallowRightStickedOperators": [ "?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireRightStickedOperators": [ "!" ],
"requireLeftStickedOperators": [ "," ],
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": [ "else" ],
"requireLineFeedAtFileEnd": true,
"disallowSpaceAfterObjectKeys": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"validateQuoteMarks": "\"",
reporter: "checkstyle",
reporterOutput: "jscs.xml"
},
flot: {
src: "<%= jshint.flot.src %>"
}
// These plugins provide necessary tasks. }
grunt.loadNpmTasks("grunt-contrib-uglify"); });
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
// Default task. // These plugins provide necessary tasks.
grunt.registerTask("default", ["jshint", "uglify"]); grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-jscs-checker");
// Default task.
grunt.registerTask("default", ["jshint", "uglify"]);
}; };
...@@ -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) {
......
...@@ -43,7 +43,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -43,7 +43,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
*/ */
(function ($) { (function($) {
var options = { var options = {
xaxis: { xaxis: {
categories: null categories: null
...@@ -121,7 +121,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -121,7 +121,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
} }
} }
res.sort(function (a, b) { return a[0] - b[0]; }); res.sort(function(a, b) { return a[0] - b[0]; });
return res; return res;
} }
......
...@@ -40,7 +40,7 @@ The plugin also adds four public methods: ...@@ -40,7 +40,7 @@ The plugin also adds four public methods:
Example usage: Example usage:
var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } }; var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
$("#graph").bind( "plothover", function ( evt, position, item ) { $("#graph").bind( "plothover", function( evt, position, item ) {
if ( item ) { if ( item ) {
// Lock the crosshair to the data point being hovered // Lock the crosshair to the data point being hovered
myFlot.lockCrosshair({ myFlot.lockCrosshair({
...@@ -58,7 +58,7 @@ The plugin also adds four public methods: ...@@ -58,7 +58,7 @@ The plugin also adds four public methods:
Free the crosshair to move again after locking it. Free the crosshair to move again after locking it.
*/ */
(function ($) { (function($) {
var options = { var options = {
crosshair: { crosshair: {
...@@ -124,7 +124,7 @@ The plugin also adds four public methods: ...@@ -124,7 +124,7 @@ The plugin also adds four public methods:
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} }
plot.hooks.bindEvents.push(function (plot, eventHolder) { plot.hooks.bindEvents.push(function(plot, eventHolder) {
if (!plot.getOptions().crosshair.mode) { if (!plot.getOptions().crosshair.mode) {
return; return;
} }
...@@ -133,7 +133,7 @@ The plugin also adds four public methods: ...@@ -133,7 +133,7 @@ The plugin also adds four public methods:
eventHolder.mousemove(onMouseMove); eventHolder.mousemove(onMouseMove);
}); });
plot.hooks.drawOverlay.push(function (plot, ctx) { plot.hooks.drawOverlay.push(function(plot, ctx) {
var c = plot.getOptions().crosshair; var c = plot.getOptions().crosshair;
if (!c.mode) { if (!c.mode) {
return; return;
...@@ -167,7 +167,7 @@ The plugin also adds four public methods: ...@@ -167,7 +167,7 @@ The plugin also adds four public methods:
ctx.restore(); ctx.restore();
}); });
plot.hooks.shutdown.push(function (plot, eventHolder) { plot.hooks.shutdown.push(function(plot, eventHolder) {
eventHolder.unbind("mouseout", onMouseOut); eventHolder.unbind("mouseout", onMouseOut);
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
}); });
......
...@@ -62,18 +62,18 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -62,18 +62,18 @@ shadowSize and lineWidth are derived as well from the points series.
*/ */
(function ($) { (function($) {
var options = { var options = {
series: { series: {
points: { points: {
errorbars: null, //should be 'x', 'y' or 'xy' errorbars: null, //should be 'x', 'y' or 'xy'
xerr: { err: "x", show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null}, xerr: { err: "x", show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null },
yerr: { err: "y", show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null} yerr: { err: "y", show: null, asymmetric: null, upperCap: null, lowerCap: null, color: null, radius: null }
} }
} }
}; };
function processRawData(plot, series, data, datapoints){ function processRawData(plot, series, data, datapoints) {
if (!series.points.errorbars) { if (!series.points.errorbars) {
return; return;
} }
...@@ -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) {
...@@ -107,12 +107,12 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -107,12 +107,12 @@ shadowSize and lineWidth are derived as well from the points series.
datapoints.format = format; datapoints.format = format;
} }
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,
...@@ -175,7 +175,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -175,7 +175,7 @@ shadowSize and lineWidth are derived as well from the points series.
return errRanges; return errRanges;
} }
function drawSeriesErrors(plot, ctx, s){ function drawSeriesErrors(plot, ctx, s) {
var points = s.datapoints.points, var points = s.datapoints.points,
ps = s.datapoints.pointsize, ps = s.datapoints.pointsize,
...@@ -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;
...@@ -278,13 +278,13 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -278,13 +278,13 @@ shadowSize and lineWidth are derived as well from the points series.
var w = sw / 2; var w = sw / 2;
ctx.lineWidth = w; ctx.lineWidth = w;
ctx.strokeStyle = "rgba(0,0,0,0.1)"; ctx.strokeStyle = "rgba(0,0,0,0.1)";
drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w + w/2, minmax); drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w + w / 2, minmax);
ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.strokeStyle = "rgba(0,0,0,0.2)";
drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w/2, minmax); drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, w / 2, minmax);
} }
ctx.strokeStyle = err[e].color? err[e].color: s.color; ctx.strokeStyle = err[e].color ? err[e].color : s.color;
ctx.lineWidth = lw; ctx.lineWidth = lw;
//draw it //draw it
drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, 0, minmax); drawError(ctx, err[e], x, y, upper, lower, drawUpper, drawLower, radius, 0, minmax);
...@@ -293,7 +293,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -293,7 +293,7 @@ shadowSize and lineWidth are derived as well from the points series.
} }
} }
function drawError(ctx,err,x,y,upper,lower,drawUpper,drawLower,radius,offset,minmax){ function drawError(ctx,err,x,y,upper,lower,drawUpper,drawLower,radius,offset,minmax) {
//shadow offset //shadow offset
y += offset; y += offset;
...@@ -327,7 +327,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -327,7 +327,7 @@ shadowSize and lineWidth are derived as well from the points series.
//internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps //internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps
//this is a way to get errorbars on lines without visible connecting dots //this is a way to get errorbars on lines without visible connecting dots
radius = err.radius != null? err.radius: radius; radius = err.radius != null ? err.radius : radius;
// upper cap // upper cap
if (drawUpper) { if (drawUpper) {
...@@ -363,7 +363,7 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -363,7 +363,7 @@ shadowSize and lineWidth are derived as well from the points series.
} }
} }
function drawPath(ctx, pts){ function drawPath(ctx, pts) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(pts[0][0], pts[0][1]); ctx.moveTo(pts[0][0], pts[0][1]);
for (var p = 1; p < pts.length; p++) { for (var p = 1; p < pts.length; p++) {
...@@ -372,12 +372,12 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -372,12 +372,12 @@ shadowSize and lineWidth are derived as well from the points series.
ctx.stroke(); ctx.stroke();
} }
function draw(plot, ctx){ function draw(plot, ctx) {
var plotOffset = plot.getPlotOffset(); var plotOffset = plot.getPlotOffset();
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
$.each(plot.getData(), function (i, s) { $.each(plot.getData(), function(i, s) {
if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) { if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) {
drawSeriesErrors(plot, ctx, s); drawSeriesErrors(plot, ctx, s);
} }
......
...@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
*/ */
(function ($) { (function($) {
var options = { var options = {
series: { series: {
......
...@@ -52,7 +52,7 @@ Google Maps). ...@@ -52,7 +52,7 @@ Google Maps).
*/ */
(function ($) { (function($) {
var options = { var options = {
series: { series: {
images: { images: {
...@@ -65,12 +65,12 @@ Google Maps). ...@@ -65,12 +65,12 @@ 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 = [],
defaultShow = options.series.images.show;
var 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)) {
return; return;
} }
...@@ -79,7 +79,7 @@ Google Maps). ...@@ -79,7 +79,7 @@ Google Maps).
s = s.data; s = s.data;
} }
$.each(s, function (i, p) { $.each(s, function(i, p) {
if (typeof p[0] === "string") { if (typeof p[0] === "string") {
urls.push(p[0]); urls.push(p[0]);
points.push(p); points.push(p);
...@@ -87,8 +87,8 @@ Google Maps). ...@@ -87,8 +87,8 @@ Google Maps).
}); });
}); });
$.plot.image.load(urls, function (loadedImages) { $.plot.image.load(urls, function(loadedImages) {
$.each(points, function (i, p) { $.each(points, function(i, p) {
var url = p[0]; var url = p[0];
if (loadedImages[url]) { if (loadedImages[url]) {
p[0] = loadedImages[url]; p[0] = loadedImages[url];
...@@ -99,14 +99,14 @@ Google Maps). ...@@ -99,14 +99,14 @@ Google Maps).
}); });
}; };
$.plot.image.load = function (urls, callback) { $.plot.image.load = function(urls, callback) {
var missing = urls.length, loaded = {}; var missing = urls.length, loaded = {};
if (missing === 0) { if (missing === 0) {
callback({}); callback({});
} }
$.each(urls, function (i, url) { $.each(urls, function(i, url) {
var handler = function () { var handler = function() {
--missing; --missing;
loaded[url] = this; loaded[url] = this;
...@@ -158,10 +158,10 @@ Google Maps). ...@@ -158,10 +158,10 @@ Google Maps).
// if the anchor is at the center of the pixel, expand the // if the anchor is at the center of the pixel, expand the
// image by 1/2 pixel in each direction // image by 1/2 pixel in each direction
if (series.images.anchor === "center") { if (series.images.anchor === "center") {
tmp = 0.5 * (x2-x1) / (img.width - 1); tmp = 0.5 * (x2 - x1) / (img.width - 1);
x1 -= tmp; x1 -= tmp;
x2 += tmp; x2 += tmp;
tmp = 0.5 * (y2-y1) / (img.height - 1); tmp = 0.5 * (y2 - y1) / (img.height - 1);
y1 -= tmp; y1 -= tmp;
y2 += tmp; y2 += tmp;
} }
......
...@@ -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 ||
...@@ -87,7 +87,7 @@ Licensed under the MIT license. ...@@ -87,7 +87,7 @@ Licensed under the MIT license.
* Resizes the canvas to the given dimensions. * Resizes the canvas to the given dimensions.
* *
* @param {number} width New width of the canvas, in pixels. * @param {number} width New width of the canvas, in pixels.
* @param {number} width New height of the canvas, in pixels. * @param {number} height New height of the canvas, in pixels.
*/ */
Canvas.prototype.resize = function(width, height) { Canvas.prototype.resize = function(width, height) {
...@@ -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);
...@@ -710,7 +711,7 @@ Licensed under the MIT license. ...@@ -710,7 +711,7 @@ Licensed under the MIT license.
mouseActiveRadius: 10 // how far the mouse can be away to activate an item mouseActiveRadius: 10 // how far the mouse can be away to activate an item
}, },
interaction: { interaction: {
redrawOverlayInterval: 1000/60 // time between updates, -1 means in same flow redrawOverlayInterval: 1000 / 60 // time between updates, -1 means in same flow
}, },
hooks: {} hooks: {}
}, },
...@@ -719,7 +720,7 @@ Licensed under the MIT license. ...@@ -719,7 +720,7 @@ Licensed under the MIT license.
eventHolder = null, // jQuery object that events should be bound to eventHolder = null, // jQuery object that events should be bound to
ctx = null, octx = null, ctx = null, octx = null,
xaxes = [], yaxes = [], xaxes = [], yaxes = [],
plotOffset = { left: 0, right: 0, top: 0, bottom: 0}, plotOffset = { left: 0, right: 0, top: 0, bottom: 0 },
plotWidth = 0, plotHeight = 0, plotWidth = 0, plotHeight = 0,
hooks = { hooks = {
processOptions: [], processOptions: [],
...@@ -742,29 +743,29 @@ Licensed under the MIT license. ...@@ -742,29 +743,29 @@ Licensed under the MIT license.
plot.getPlaceholder = function() { return placeholder; }; plot.getPlaceholder = function() { return placeholder; };
plot.getCanvas = function() { return surface.element; }; plot.getCanvas = function() { return surface.element; };
plot.getPlotOffset = function() { return plotOffset; }; plot.getPlotOffset = function() { return plotOffset; };
plot.width = function () { return plotWidth; }; plot.width = function() { return plotWidth; };
plot.height = function () { return plotHeight; }; plot.height = function() { return plotHeight; };
plot.offset = function () { plot.offset = function() {
var o = eventHolder.offset(); var o = eventHolder.offset();
o.left += plotOffset.left; o.left += plotOffset.left;
o.top += plotOffset.top; o.top += plotOffset.top;
return o; return o;
}; };
plot.getData = function () { return series; }; plot.getData = function() { return series; };
plot.getAxes = function () { plot.getAxes = function() {
var res = {}; var res = {};
$.each(xaxes.concat(yaxes), function (_, axis) { $.each(xaxes.concat(yaxes), function(_, axis) {
if (axis) { if (axis) {
res[axis.direction + (axis.n !== 1 ? axis.n : "") + "axis"] = axis; res[axis.direction + (axis.n !== 1 ? axis.n : "") + "axis"] = axis;
} }
}); });
return res; return res;
}; };
plot.getXAxes = function () { return xaxes; }; plot.getXAxes = function() { return xaxes; };
plot.getYAxes = function () { return yaxes; }; plot.getYAxes = function() { return yaxes; };
plot.c2p = canvasToAxisCoords; plot.c2p = canvasToAxisCoords;
plot.p2c = axisToCanvasCoords; plot.p2c = axisToCanvasCoords;
plot.getOptions = function () { return options; }; plot.getOptions = function() { return options; };
plot.highlight = highlight; plot.highlight = highlight;
plot.unhighlight = unhighlight; plot.unhighlight = unhighlight;
plot.triggerRedrawOverlay = triggerRedrawOverlay; plot.triggerRedrawOverlay = triggerRedrawOverlay;
...@@ -775,7 +776,7 @@ Licensed under the MIT license. ...@@ -775,7 +776,7 @@ Licensed under the MIT license.
}; };
}; };
plot.shutdown = shutdown; plot.shutdown = shutdown;
plot.destroy = function () { plot.destroy = function() {
shutdown(); shutdown();
placeholder.removeData("plot").empty(); placeholder.removeData("plot").empty();
...@@ -792,7 +793,7 @@ Licensed under the MIT license. ...@@ -792,7 +793,7 @@ Licensed under the MIT license.
highlights = []; highlights = [];
plot = null; plot = null;
}; };
plot.resize = function (width, height) { plot.resize = function(width, height) {
width = width || placeholder.width(); width = width || placeholder.width();
height = height || placeholder.height(); height = height || placeholder.height();
surface.resize(width, height); surface.resize(width, height);
...@@ -811,7 +812,6 @@ Licensed under the MIT license. ...@@ -811,7 +812,6 @@ Licensed under the MIT license.
draw(); draw();
bindEvents(); bindEvents();
function executeHooks(hook, args) { function executeHooks(hook, args) {
args = [plot].concat(args); args = [plot].concat(args);
for (var i = 0; i < hook.length; ++i) { for (var i = 0; i < hook.length; ++i) {
...@@ -1099,7 +1099,7 @@ Licensed under the MIT license. ...@@ -1099,7 +1099,7 @@ Licensed under the MIT license.
function allAxes() { function allAxes() {
// return flat array without annoying null entries // return flat array without annoying null entries
return $.grep(xaxes.concat(yaxes), function (a) { return a; }); return $.grep(xaxes.concat(yaxes), function(a) { return a; });
} }
function canvasToAxisCoords(pos) { function canvasToAxisCoords(pos) {
...@@ -1291,7 +1291,7 @@ Licensed under the MIT license. ...@@ -1291,7 +1291,7 @@ Licensed under the MIT license.
} }
} }
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function(_, axis) {
// init axis // init axis
axis.datamin = topSentry; axis.datamin = topSentry;
axis.datamax = bottomSentry; axis.datamax = bottomSentry;
...@@ -1301,7 +1301,7 @@ Licensed under the MIT license. ...@@ -1301,7 +1301,7 @@ Licensed under the MIT license.
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
s.datapoints = { points: [] }; s.datapoints = { points: [] };
executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]); executeHooks(hooks.processRawData, [s, s.data, s.datapoints]);
} }
// first pass: clean and copy data // first pass: clean and copy data
...@@ -1337,7 +1337,7 @@ Licensed under the MIT license. ...@@ -1337,7 +1337,7 @@ Licensed under the MIT license.
ps = s.datapoints.pointsize; ps = s.datapoints.pointsize;
points = s.datapoints.points; points = s.datapoints.points;
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) {
...@@ -1401,7 +1401,7 @@ Licensed under the MIT license. ...@@ -1401,7 +1401,7 @@ Licensed under the MIT license.
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
executeHooks(hooks.processDatapoints, [ s, s.datapoints]); executeHooks(hooks.processDatapoints, [s, s.datapoints]);
} }
// second pass: find datamax/datamin for auto-scaling // second pass: find datamax/datamin for auto-scaling
...@@ -1473,7 +1473,7 @@ Licensed under the MIT license. ...@@ -1473,7 +1473,7 @@ Licensed under the MIT license.
updateAxis(s.yaxis, ymin, ymax); updateAxis(s.yaxis, ymin, ymax);
} }
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function(_, axis) {
if (axis.datamin === topSentry) { if (axis.datamin === topSentry) {
axis.datamin = null; axis.datamin = null;
} }
...@@ -1574,15 +1574,15 @@ Licensed under the MIT license. ...@@ -1574,15 +1574,15 @@ Licensed under the MIT license.
// data point to canvas coordinate // data point to canvas coordinate
if (t === identity) { // slight optimization if (t === identity) { // slight optimization
axis.p2c = function (p) { return (p - m) * s; }; axis.p2c = function(p) { return (p - m) * s; };
} else { } else {
axis.p2c = function (p) { return (t(p) - m) * s; }; axis.p2c = function(p) { return (t(p) - m) * s; };
} }
// canvas coordinate to data point // canvas coordinate to data point
if (!it) { if (!it) {
axis.c2p = function (c) { return m + c / s; }; axis.c2p = function(c) { return m + c / s; };
} else { } else {
axis.c2p = function (c) { return it(m + c / s); }; axis.c2p = function(c) { return it(m + c / s); };
} }
} }
...@@ -1756,7 +1756,7 @@ Licensed under the MIT license. ...@@ -1756,7 +1756,7 @@ Licensed under the MIT license.
// check axis labels, note we don't check the actual // check axis labels, note we don't check the actual
// labels but instead use the overall width/height to not // labels but instead use the overall width/height to not
// jump as much around with replots // jump as much around with replots
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function(_, axis) {
if (axis.reserveSpace && axis.ticks && axis.ticks.length) { if (axis.reserveSpace && axis.ticks && axis.ticks.length) {
var lastTick = axis.ticks[axis.ticks.length - 1]; var lastTick = axis.ticks[axis.ticks.length - 1];
if (axis.direction === "x") { if (axis.direction === "x") {
...@@ -1806,7 +1806,7 @@ Licensed under the MIT license. ...@@ -1806,7 +1806,7 @@ Licensed under the MIT license.
} }
// init axes // init axes
$.each(axes, function (_, axis) { $.each(axes, function(_, axis) {
axis.show = axis.options.show; axis.show = axis.options.show;
if (axis.show == null) { if (axis.show == null) {
axis.show = axis.used; // by default an axis is visible if it's got data axis.show = axis.used; // by default an axis is visible if it's got data
...@@ -1819,9 +1819,9 @@ Licensed under the MIT license. ...@@ -1819,9 +1819,9 @@ Licensed under the MIT license.
if (showGrid) { if (showGrid) {
var allocatedAxes = $.grep(axes, function (axis) { return axis.reserveSpace; }); var allocatedAxes = $.grep(axes, function(axis) { return axis.reserveSpace; });
$.each(allocatedAxes, function (_, axis) { $.each(allocatedAxes, function(_, axis) {
// make the ticks // make the ticks
setupTickGeneration(axis); setupTickGeneration(axis);
setTicks(axis); setTicks(axis);
...@@ -1840,7 +1840,7 @@ Licensed under the MIT license. ...@@ -1840,7 +1840,7 @@ Licensed under the MIT license.
// might stick out // might stick out
adjustLayoutForThingsStickingOut(); adjustLayoutForThingsStickingOut();
$.each(allocatedAxes, function (_, axis) { $.each(allocatedAxes, function(_, axis) {
allocateAxisBoxSecondPhase(axis); allocateAxisBoxSecondPhase(axis);
}); });
} }
...@@ -1849,7 +1849,7 @@ Licensed under the MIT license. ...@@ -1849,7 +1849,7 @@ Licensed under the MIT license.
plotHeight = surface.height - plotOffset.bottom - plotOffset.top; plotHeight = surface.height - plotOffset.bottom - plotOffset.top;
// now we got the proper plot dimensions, we can compute the scaling // now we got the proper plot dimensions, we can compute the scaling
$.each(axes, function (_, axis) { $.each(axes, function(_, axis) {
setTransformationHelpers(axis); setTransformationHelpers(axis);
}); });
...@@ -1903,10 +1903,12 @@ Licensed under the MIT license. ...@@ -1903,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 {
...@@ -1964,7 +1966,7 @@ Licensed under the MIT license. ...@@ -1964,7 +1966,7 @@ Licensed under the MIT license.
if (!axis.tickGenerator) { if (!axis.tickGenerator) {
axis.tickGenerator = function (axis) { axis.tickGenerator = function(axis) {
var ticks = [], var ticks = [],
start = floorInBase(axis.min, axis.tickSize), start = floorInBase(axis.min, axis.tickSize),
...@@ -1981,17 +1983,18 @@ Licensed under the MIT license. ...@@ -1981,17 +1983,18 @@ Licensed under the MIT license.
return ticks; return ticks;
}; };
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);
} }
...@@ -2002,7 +2005,7 @@ Licensed under the MIT license. ...@@ -2002,7 +2005,7 @@ Licensed under the MIT license.
} }
if ($.isFunction(opts.tickFormatter)) { if ($.isFunction(opts.tickFormatter)) {
axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); }; axis.tickFormatter = function(v, axis) { return "" + opts.tickFormatter(v, axis); };
} }
if (opts.alignTicksWithAxis != null) { if (opts.alignTicksWithAxis != null) {
...@@ -2019,7 +2022,7 @@ Licensed under the MIT license. ...@@ -2019,7 +2022,7 @@ Licensed under the MIT license.
} }
} }
axis.tickGenerator = function (axis) { axis.tickGenerator = function(axis) {
// copy ticks, scaled to this axis // copy ticks, scaled to this axis
var ticks = [], v, i; var ticks = [], v, i;
for (i = 0; i < otherAxis.ticks.length; ++i) { for (i = 0; i < otherAxis.ticks.length; ++i) {
...@@ -2064,8 +2067,9 @@ Licensed under the MIT license. ...@@ -2064,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) {
...@@ -2185,10 +2189,10 @@ Licensed under the MIT license. ...@@ -2185,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();
...@@ -2204,7 +2208,7 @@ Licensed under the MIT license. ...@@ -2204,7 +2208,7 @@ Licensed under the MIT license.
for (i = 0; i < markings.length; ++i) { for (i = 0; i < markings.length; ++i) {
var m = markings[i]; var m = markings[i];
if (m.aboveGrid) { if (m.aboveGrid) {
markingsAboveGrid.push(m); markingsAboveGrid.push(m);
} else { } else {
...@@ -2212,7 +2216,7 @@ Licensed under the MIT license. ...@@ -2212,7 +2216,7 @@ Licensed under the MIT license.
} }
} }
} }
drawMarkings(markingsUnderGrid, markingLayer); drawMarkings(markingsUnderGrid, markingLayer);
// draw the ticks // draw the ticks
...@@ -2327,10 +2331,10 @@ Licensed under the MIT license. ...@@ -2327,10 +2331,10 @@ Licensed under the MIT license.
bc = options.grid.borderColor; bc = options.grid.borderColor;
if (typeof bw === "object" || typeof bc === "object") { if (typeof bw === "object" || typeof bc === "object") {
if (typeof bw !== "object") { if (typeof bw !== "object") {
bw = {top: bw, right: bw, bottom: bw, left: bw}; bw = { top: bw, right: bw, bottom: bw, left: bw };
} }
if (typeof bc !== "object") { if (typeof bc !== "object") {
bc = {top: bc, right: bc, bottom: bc, left: bc}; bc = { top: bc, right: bc, bottom: bc, left: bc };
} }
if (bw.top > 0) { if (bw.top > 0) {
...@@ -2365,7 +2369,7 @@ Licensed under the MIT license. ...@@ -2365,7 +2369,7 @@ Licensed under the MIT license.
ctx.lineWidth = bw.left; ctx.lineWidth = bw.left;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(0 - bw.left / 2, plotHeight + bw.bottom); ctx.moveTo(0 - bw.left / 2, plotHeight + bw.bottom);
ctx.lineTo(0- bw.left / 2, 0); ctx.lineTo(0 - bw.left / 2, 0);
ctx.stroke(); ctx.stroke();
} }
} else { } else {
...@@ -2377,7 +2381,7 @@ Licensed under the MIT license. ...@@ -2377,7 +2381,7 @@ Licensed under the MIT license.
ctx.restore(); ctx.restore();
} }
function drawMarkings(markings, markingLayer) { function drawMarkings(markings, markingLayer) {
if (!markings) { if (!markings) {
return; return;
...@@ -2387,7 +2391,7 @@ Licensed under the MIT license. ...@@ -2387,7 +2391,7 @@ Licensed under the MIT license.
drawMarking(markings[i], markingLayer); drawMarking(markings[i], markingLayer);
} }
} }
function drawMarking(m, markingLayer) { function drawMarking(m, markingLayer) {
var xrange = extractRange(m, "x"), var xrange = extractRange(m, "x"),
yrange = extractRange(m, "y"); yrange = extractRange(m, "y");
...@@ -2449,9 +2453,12 @@ Licensed under the MIT license. ...@@ -2449,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()) {
...@@ -2481,7 +2488,7 @@ Licensed under the MIT license. ...@@ -2481,7 +2488,7 @@ Licensed under the MIT license.
function drawAxisLabels() { function drawAxisLabels() {
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function(_, axis) {
var box = axis.box, var box = axis.box,
axisOptions = axis.options, axisOptions = axis.options,
...@@ -3050,7 +3057,7 @@ Licensed under the MIT license. ...@@ -3050,7 +3057,7 @@ Licensed under the MIT license.
barLeft = -series.bars.barWidth / 2; barLeft = -series.bars.barWidth / 2;
} }
var fillStyleCallback = series.bars.fill ? function (bottom, top) { return getFillStyle(series.bars, series.color, bottom, top); } : null; var fillStyleCallback = series.bars.fill ? function(bottom, top) { return getFillStyle(series.bars, series.color, bottom, top); } : null;
plotBars(series.datapoints, barLeft, barLeft + series.bars.barWidth, fillStyleCallback, series.xaxis, series.yaxis); plotBars(series.datapoints, barLeft, barLeft + series.bars.barWidth, fillStyleCallback, series.xaxis, series.yaxis);
ctx.restore(); ctx.restore();
} }
...@@ -3164,7 +3171,7 @@ Licensed under the MIT license. ...@@ -3164,7 +3171,7 @@ Licensed under the MIT license.
if (options.legend.container != null) { if (options.legend.container != null) {
$(options.legend.container).html(table); $(options.legend.container).html(table);
} else { } else {
var pos = {"position": "absolute"}, var pos = { "position": "absolute" },
p = options.legend.position, p = options.legend.position,
m = options.legend.margin; m = options.legend.margin;
if (m[0] == null) { if (m[0] == null) {
...@@ -3209,7 +3216,6 @@ Licensed under the MIT license. ...@@ -3209,7 +3216,6 @@ Licensed under the MIT license.
} }
} }
// interactive features // interactive features
var highlights = [], var highlights = [],
...@@ -3332,20 +3338,20 @@ Licensed under the MIT license. ...@@ -3332,20 +3338,20 @@ Licensed under the MIT license.
function onMouseMove(e) { function onMouseMove(e) {
if (options.grid.hoverable) { if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e, triggerClickHoverEvent("plothover", e,
function (s) { return s.hoverable !== false; }); function(s) { return s.hoverable !== false; });
} }
} }
function onMouseLeave(e) { function onMouseLeave(e) {
if (options.grid.hoverable) { if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e, triggerClickHoverEvent("plothover", e,
function () { return false; }); function() { return false; });
} }
} }
function onClick(e) { function onClick(e) {
triggerClickHoverEvent("plotclick", e, triggerClickHoverEvent("plotclick", e,
function (s) { return s.clickable !== false; }); function(s) { return s.clickable !== false; });
} }
// trigger click or hover event (they send the same parameters // trigger click or hover event (they send the same parameters
...@@ -3385,7 +3391,7 @@ Licensed under the MIT license. ...@@ -3385,7 +3391,7 @@ Licensed under the MIT license.
} }
} }
placeholder.trigger(eventname, [ pos, item ]); placeholder.trigger(eventname, [pos, item]);
} }
function triggerRedrawOverlay() { function triggerRedrawOverlay() {
...@@ -3484,8 +3490,8 @@ Licensed under the MIT license. ...@@ -3484,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;
...@@ -3528,7 +3534,7 @@ Licensed under the MIT license. ...@@ -3528,7 +3534,7 @@ Licensed under the MIT license.
octx.strokeStyle = highlightColor; octx.strokeStyle = highlightColor;
drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth, drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth,
function () { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth); function() { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth);
} }
function getColorOrGradient(spec, bottom, top, defaultColor) { function getColorOrGradient(spec, bottom, top, defaultColor) {
...@@ -3589,17 +3595,18 @@ Licensed under the MIT license. ...@@ -3589,17 +3595,18 @@ Licensed under the MIT license.
// Draw a rectangle with rounded corner on the canvas. // Draw a rectangle with rounded corner on the canvas.
// //
// @param {CanvasRenderingContext2D} ctx The canvas 2D context. // @param {CanvasRenderingContext2D} ctx The canvas 2D context.
// @param {number} x The x-axis coordinate of the upper left corner of // @param {number} x The x-axis coordinate of the upper left corner of
// the rectangle to be drawn. // the rectangle to be drawn.
// @param {number} y The y-axis coordinate of the upper left corner of // @param {number} y The y-axis coordinate of the upper left corner of
// the rectangle to be drawn. // the rectangle to be drawn.
// @param {number} width The width of the rectangle to be drawn. // @param {number} width The width of the rectangle to be drawn.
// @param {number} height The height of the rectangle to be drawn. // @param {number} height The height of the rectangle to be drawn.
// @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);
......
...@@ -79,7 +79,7 @@ can set the default in the options. ...@@ -79,7 +79,7 @@ can set the default in the options.
*/ */
(function ($) { (function($) {
var options = { var options = {
xaxis: { xaxis: {
zoomRange: null, // or [number, number] (min range, max range) zoomRange: null, // or [number, number] (min range, max range)
...@@ -137,7 +137,7 @@ can set the default in the options. ...@@ -137,7 +137,7 @@ can set the default in the options.
return; return;
} }
panTimeout = setTimeout(function () { panTimeout = setTimeout(function() {
plot.pan({ left: prevPageX - e.pageX, plot.pan({ left: prevPageX - e.pageX,
top: prevPageY - e.pageY }); top: prevPageY - e.pageY });
prevPageX = e.pageX; prevPageX = e.pageX;
...@@ -172,7 +172,7 @@ can set the default in the options. ...@@ -172,7 +172,7 @@ can set the default in the options.
} }
} }
plot.zoomOut = function (args) { plot.zoomOut = function(args) {
if (!args) { if (!args) {
args = {}; args = {};
} }
...@@ -185,7 +185,7 @@ can set the default in the options. ...@@ -185,7 +185,7 @@ can set the default in the options.
plot.zoom(args); plot.zoom(args);
}; };
plot.zoom = function (args) { plot.zoom = function(args) {
if (!args) { if (!args) {
args = {}; args = {};
} }
...@@ -256,11 +256,11 @@ can set the default in the options. ...@@ -256,11 +256,11 @@ can set the default in the options.
plot.draw(); plot.draw();
if (!args.preventEvent) { if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotzoom", [ plot, args ]); plot.getPlaceholder().trigger("plotzoom", [plot, args]);
} }
}; };
plot.pan = function (args) { plot.pan = function(args) {
var delta = { var delta = {
x: +args.left, x: +args.left,
y: +args.top y: +args.top
...@@ -273,7 +273,7 @@ can set the default in the options. ...@@ -273,7 +273,7 @@ can set the default in the options.
delta.y = 0; delta.y = 0;
} }
$.each(plot.getAxes(), function (_, axis) { $.each(plot.getAxes(), function(_, axis) {
var opts = axis.options, var opts = axis.options,
min = axis.c2p(axis.p2c(axis.min) + d), min = axis.c2p(axis.p2c(axis.min) + d),
...@@ -308,7 +308,7 @@ can set the default in the options. ...@@ -308,7 +308,7 @@ can set the default in the options.
plot.draw(); plot.draw();
if (!args.preventEvent) { if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotpan", [ plot, args ]); plot.getPlaceholder().trigger("plotpan", [plot, args]);
} }
}; };
......
...@@ -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
...@@ -101,7 +101,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -101,7 +101,7 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.radius === "auto") { if (options.series.pie.radius === "auto") {
if (options.series.pie.label.show) { if (options.series.pie.label.show) {
options.series.pie.radius = 3/4; options.series.pie.radius = 3 / 4;
} else { } else {
options.series.pie.radius = 1; options.series.pie.radius = 1;
} }
...@@ -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);
...@@ -565,9 +565,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -565,9 +565,9 @@ More detail and specific examples can be found in the included HTML file.
//-- Additional Interactive related functions -- //-- Additional Interactive related functions --
function isPointInPoly(poly, pt) { function isPointInPoly(poly, pt) {
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) { for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || ((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) ||
(poly[j][1] <= pt[1] && pt[1]< poly[i][1])) && (poly[j][1] <= pt[1] && pt[1] < poly[i][1])) &&
(pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) && (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) &&
(c = !c); (c = !c);
} }
...@@ -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);
...@@ -774,7 +773,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -774,7 +773,7 @@ More detail and specific examples can be found in the included HTML file.
show: false, show: false,
radius: "auto", // actual radius of the visible pie (based on full calculated radius if <=1, or hard pixel value) radius: "auto", // actual radius of the visible pie (based on full calculated radius if <=1, or hard pixel value)
innerRadius: 0, /* for donut */ innerRadius: 0, /* for donut */
startAngle: 3/2, startAngle: 3 / 2,
tilt: 1, tilt: 1,
shadow: { shadow: {
left: 5, // shadow left offset left: 5, // shadow left offset
......
...@@ -11,7 +11,7 @@ can just fix the size of their placeholders. ...@@ -11,7 +11,7 @@ can just fix the size of their placeholders.
*/ */
(function ($) { (function($) {
var options = { }; // no options var options = { }; // no options
function init(plot) { function init(plot) {
......
...@@ -78,30 +78,30 @@ The plugin allso adds the following methods to the plot object: ...@@ -78,30 +78,30 @@ The plugin allso adds the following methods to the plot object:
*/ */
(function ($) { (function($) {
function init(plot) { function init(plot) {
var selection = { var selection = {
first: { x: -1, y: -1}, first: { x: -1, y: -1 },
second: { x: -1, y: -1}, second: { x: -1, y: -1 },
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) {
if (selection.active) { if (selection.active) {
updateSelection(e); updateSelection(e);
plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]); plot.getPlaceholder().trigger("plotselecting", [getSelection()]);
// prevent the default action if it is a 'touch' action // prevent the default action if it is a 'touch' action
if (selection.touch === true) { if (selection.touch === true) {
...@@ -117,18 +117,17 @@ The plugin allso adds the following methods to the plot object: ...@@ -117,18 +117,17 @@ The plugin allso adds the following methods to the plot object:
return; return;
} }
// cancel out any text selections // cancel out any text selections
document.body.focus(); document.body.focus();
// prevent text selection and drag in old-school browsers // prevent text selection and drag in old-school browsers
if (document.onselectstart !== undefined && savedhandlers.onselectstart === null) { if (document.onselectstart !== undefined && savedhandlers.onselectstart === null) {
savedhandlers.onselectstart = document.onselectstart; savedhandlers.onselectstart = document.onselectstart;
document.onselectstart = function () { return false; }; document.onselectstart = function() { return false; };
} }
if (document.ondrag !== undefined && savedhandlers.ondrag === null) { if (document.ondrag !== undefined && savedhandlers.ondrag === null) {
savedhandlers.ondrag = document.ondrag; savedhandlers.ondrag = document.ondrag;
document.ondrag = function () { return false; }; document.ondrag = function() { return false; };
} }
setSelectionPos(selection.first, e); setSelectionPos(selection.first, e);
...@@ -137,7 +136,7 @@ The plugin allso adds the following methods to the plot object: ...@@ -137,7 +136,7 @@ The plugin allso adds the following methods to the plot object:
// this is a bit silly, but we have to use a closure to be // this is a bit silly, but we have to use a closure to be
// able to whack the same handler again // able to whack the same handler again
mouseUpHandler = function (e) { onMouseUp(e); }; mouseUpHandler = function(e) { onMouseUp(e); };
$(document).one(selection.touch ? "touchend" : "mouseup", mouseUpHandler); $(document).one(selection.touch ? "touchend" : "mouseup", mouseUpHandler);
} }
...@@ -161,8 +160,8 @@ The plugin allso adds the following methods to the plot object: ...@@ -161,8 +160,8 @@ The plugin allso adds the following methods to the plot object:
triggerSelectedEvent(); triggerSelectedEvent();
} else { } else {
// this counts as a clear // this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]); plot.getPlaceholder().trigger("plotunselected", []);
plot.getPlaceholder().trigger("plotselecting", [ null ]); plot.getPlaceholder().trigger("plotselecting", [null]);
} }
selection.touch = false; selection.touch = false;
...@@ -179,7 +178,7 @@ The plugin allso adds the following methods to the plot object: ...@@ -179,7 +178,7 @@ The plugin allso adds the following methods to the plot object:
c1 = selection.first, c1 = selection.first,
c2 = selection.second; c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) { $.each(plot.getAxes(), function(name, axis) {
if (axis.used) { if (axis.used) {
var p1 = axis.c2p(c1[axis.direction]), var p1 = axis.c2p(c1[axis.direction]),
p2 = axis.c2p(c2[axis.direction]); p2 = axis.c2p(c2[axis.direction]);
...@@ -192,11 +191,11 @@ The plugin allso adds the following methods to the plot object: ...@@ -192,11 +191,11 @@ The plugin allso adds the following methods to the plot object:
function triggerSelectedEvent() { function triggerSelectedEvent() {
var r = getSelection(); var r = getSelection();
plot.getPlaceholder().trigger("plotselected", [ r ]); plot.getPlaceholder().trigger("plotselected", [r]);
// backwards-compat stuff, to be removed in future // backwards-compat stuff, to be removed in future
if (r.xaxis && r.yaxis) { if (r.xaxis && r.yaxis) {
plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]); plot.getPlaceholder().trigger("selected", [{ x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to }]);
} }
} }
...@@ -207,9 +206,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -207,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());
...@@ -329,7 +328,7 @@ The plugin allso adds the following methods to the plot object: ...@@ -329,7 +328,7 @@ The plugin allso adds the following methods to the plot object:
eventHolder.mousemove(onMouseMove); eventHolder.mousemove(onMouseMove);
eventHolder.mousedown(onMouseDown); eventHolder.mousedown(onMouseDown);
eventHolder.bind("touchstart", function(e) { eventHolder.bind("touchstart", function(e) {
// Using a touch device, disable mouse events to prevent // Using a touch device, disable mouse events to prevent
// event handlers being called twice // event handlers being called twice
eventHolder.unbind("mousedown", onMouseDown); eventHolder.unbind("mousedown", onMouseDown);
onMouseDown(e); onMouseDown(e);
...@@ -338,27 +337,27 @@ The plugin allso adds the following methods to the plot object: ...@@ -338,27 +337,27 @@ 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);
...@@ -367,7 +366,7 @@ The plugin allso adds the following methods to the plot object: ...@@ -367,7 +366,7 @@ The plugin allso adds the following methods to the plot object:
} }
}); });
plot.hooks.shutdown.push(function (plot, eventHolder) { plot.hooks.shutdown.push(function(plot, eventHolder) {
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown); eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler) { if (mouseUpHandler) {
......
...@@ -35,7 +35,7 @@ charts or filled areas). ...@@ -35,7 +35,7 @@ charts or filled areas).
*/ */
(function ($) { (function($) {
var options = { var options = {
series: { stack: null } // or number/string series: { stack: null } // or number/string
}; };
......
...@@ -13,48 +13,48 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -13,48 +13,48 @@ The symbols are accessed as strings through the standard symbol options:
*/ */
(function ($) { (function($) {
function processRawData(plot, series) { function processRawData(plot, series) {
// we normalize the area of each symbol so it is approximately the // we normalize the area of each symbol so it is approximately the
// 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];
} }
......
...@@ -43,7 +43,7 @@ You may need to check for this in hover events. ...@@ -43,7 +43,7 @@ You may need to check for this in hover events.
*/ */
(function ($) { (function($) {
var options = { var options = {
series: { threshold: null } // or { below: number, color: color spec} series: { threshold: null } // or { below: number, color: color spec}
}; };
...@@ -135,7 +135,6 @@ You may need to check for this in hover events. ...@@ -135,7 +135,6 @@ You may need to check for this in hover events.
} }
plot.hooks.processDatapoints.push(processThresholds); plot.hooks.processDatapoints.push(processThresholds);
function processThresholdsLegend(ctx, canvas, s) { function processThresholdsLegend(ctx, canvas, s) {
if (!s.threshold) { if (!s.threshold) {
...@@ -145,11 +144,11 @@ You may need to check for this in hover events. ...@@ -145,11 +144,11 @@ You may need to check for this in hover events.
var color = s.threshold.color ? s.threshold.color : "black"; var color = s.threshold.color ? s.threshold.color : "black";
$(".legendLabel").each(function() { $(".legendLabel").each(function() {
if($(this).text() === s.label) if ($(this).text() === s.label)
{ {
var legend = $(this).prev().find("div > div"); var legend = $(this).prev().find("div > div");
legend.css("border-right-color" , color); legend.css("border-right-color", color);
legend.css("border-bottom-color" , color); legend.css("border-bottom-color", color);
} }
}); });
} }
......
...@@ -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,40 +191,46 @@ API.txt for details. ...@@ -193,40 +191,46 @@ 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) {
$.each(plot.getAxes(), function(axisName, axis) { $.each(plot.getAxes(), function(axisName, axis) {
var opts = axis.options; var opts = axis.options;
...@@ -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;
...@@ -385,7 +389,7 @@ API.txt for details. ...@@ -385,7 +389,7 @@ API.txt for details.
return ticks; return ticks;
}; };
axis.tickFormatter = function (v, axis) { axis.tickFormatter = function(v, axis) {
var d = dateGenerator(v, axis.options); var d = dateGenerator(v, axis.options);
......
...@@ -36,10 +36,11 @@ ...@@ -36,10 +36,11 @@
"url": "https://github.com/flot/flot/issues" "url": "https://github.com/flot/flot/issues"
}, },
"devDependencies": { "devDependencies": {
"grunt": "~0.4.1", "grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.4", "grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-uglify": "~0.2.4", "grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.5.3" "grunt-contrib-watch": "~0.5.3",
"grunt-jscs-checker": "~0.3.2"
}, },
"maintainers": [ "maintainers": [
{ {
......
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