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 */
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON("package.json"),
banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - " +
"* Copyright (c) <%= grunt.template.today('yyyy') %> IOLA and <%= pkg.author.name %>;" +
" Licensed <%= pkg.license %> */\n",
// Task configuration.
uglify: {
options: {
banner: "<%= banner %>"
},
dist: {
expand: true,
flatten: true,
src: ["jquery.*.js", "!jquery.js"],
dest: "dist/",
rename: function(base, path) {
return base + path.replace(/\.js/, ".min.js");
}
}
},
jshint: {
options: grunt.file.readJSON(".jshintrc"),
gruntfile: {
src: "Gruntfile.js"
},
flot: {
src: ["jquery.flot*.js"]
}
},
watch: {
gruntfile: {
files: "Gruntfile.js",
tasks: ["jshint:gruntfile"]
},
flot: {
files: "<%= jshint.flot.src %>",
tasks: ["jshint:flot"]
}
}
});
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON("package.json"),
banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - " +
"* Copyright (c) <%= grunt.template.today('yyyy') %> IOLA and <%= pkg.author.name %>;" +
" Licensed <%= pkg.license %> */\n",
// Task configuration.
uglify: {
options: {
banner: "<%= banner %>"
},
dist: {
expand: true,
flatten: true,
src: ["jquery.*.js", "!jquery.js"],
dest: "dist/",
rename: function(base, path) {
return base + path.replace(/\.js/, ".min.js");
}
}
},
jshint: {
options: grunt.file.readJSON(".jshintrc"),
gruntfile: {
src: "Gruntfile.js"
},
flot: {
src: ["jquery.flot*.js"]
}
},
watch: {
gruntfile: {
files: "Gruntfile.js",
tasks: ["jshint:gruntfile"]
},
flot: {
files: "<%= jshint.flot.src %>",
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.
grunt.registerTask("default", ["jshint", "uglify"]);
// These plugins provide necessary tasks.
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.
var options = {
canvas: true
};
var render, getTextInfo, addText;
},
render, getTextInfo, addText;
function init(plot, classes) {
......
......@@ -43,7 +43,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
*/
(function ($) {
(function($) {
var options = {
xaxis: {
categories: null
......@@ -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;
}
......
......@@ -40,7 +40,7 @@ The plugin also adds four public methods:
Example usage:
var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
$("#graph").bind( "plothover", function ( evt, position, item ) {
$("#graph").bind( "plothover", function( evt, position, item ) {
if ( item ) {
// Lock the crosshair to the data point being hovered
myFlot.lockCrosshair({
......@@ -58,7 +58,7 @@ The plugin also adds four public methods:
Free the crosshair to move again after locking it.
*/
(function ($) {
(function($) {
var options = {
crosshair: {
......@@ -124,7 +124,7 @@ The plugin also adds four public methods:
plot.triggerRedrawOverlay();
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
plot.hooks.bindEvents.push(function(plot, eventHolder) {
if (!plot.getOptions().crosshair.mode) {
return;
}
......@@ -133,7 +133,7 @@ The plugin also adds four public methods:
eventHolder.mousemove(onMouseMove);
});
plot.hooks.drawOverlay.push(function (plot, ctx) {
plot.hooks.drawOverlay.push(function(plot, ctx) {
var c = plot.getOptions().crosshair;
if (!c.mode) {
return;
......@@ -167,7 +167,7 @@ The plugin also adds four public methods:
ctx.restore();
});
plot.hooks.shutdown.push(function (plot, eventHolder) {
plot.hooks.shutdown.push(function(plot, eventHolder) {
eventHolder.unbind("mouseout", onMouseOut);
eventHolder.unbind("mousemove", onMouseMove);
});
......
......@@ -62,18 +62,18 @@ shadowSize and lineWidth are derived as well from the points series.
*/
(function ($) {
(function($) {
var options = {
series: {
points: {
errorbars: null, //should be 'x', 'y' or 'xy'
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}
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 }
}
}
};
function processRawData(plot, series, data, datapoints){
function processRawData(plot, series, data, datapoints) {
if (!series.points.errorbars) {
return;
}
......@@ -82,9 +82,8 @@ shadowSize and lineWidth are derived as well from the points series.
var format = [
{ x: true, number: true, required: true },
{ y: true, number: true, required: true }
];
var errors = series.points.errorbars;
],
errors = series.points.errorbars;
// error bars - first X then Y
if (errors === "x" || errors === "xy") {
// lower / upper error
......@@ -95,6 +94,7 @@ shadowSize and lineWidth are derived as well from the points series.
format.push({ x: true, number: true, required: true });
}
}
if (errors === "y" || errors === "xy") {
// lower / upper error
if (series.points.yerr.asymmetric) {
......@@ -107,12 +107,12 @@ shadowSize and lineWidth are derived as well from the points series.
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
var exl = null,
// read errors from points array
exl = null,
exu = null,
eyl = null,
eyu = null,
......@@ -175,7 +175,7 @@ shadowSize and lineWidth are derived as well from the points series.
return errRanges;
}
function drawSeriesErrors(plot, ctx, s){
function drawSeriesErrors(plot, ctx, s) {
var points = s.datapoints.points,
ps = s.datapoints.pointsize,
......@@ -184,7 +184,7 @@ shadowSize and lineWidth are derived as well from the points series.
err = [s.points.xerr, s.points.yerr],
invertX = 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
......@@ -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) {
var errRanges = parseErrors(s, i);
errRanges = parseErrors(s, i);
//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?
if (errRanges[e * err.length]){
//data coordinates
var x = points[i],
y = points[i + 1];
x = points[i];
y = points[i + 1];
//errorbar ranges
var upper = [x, y][e] + errRanges[e * err.length + 1],
lower = [x, y][e] - errRanges[e * err.length];
upper = [x, y][e] + errRanges[e * err.length + 1];
lower = [x, y][e] - errRanges[e * err.length];
//points outside of the canvas
if (err[e].err === "x") {
......@@ -235,8 +235,8 @@ shadowSize and lineWidth are derived as well from the points series.
}
// prevent errorbars getting out of the canvas
var drawUpper = true,
drawLower = true;
drawUpper = true,
drawLower = true;
if (upper > minmax[1]) {
drawUpper = false;
......@@ -278,13 +278,13 @@ shadowSize and lineWidth are derived as well from the points series.
var w = sw / 2;
ctx.lineWidth = w;
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)";
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;
//draw it
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.
}
}
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
y += offset;
......@@ -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
//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
if (drawUpper) {
......@@ -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.moveTo(pts[0][0], pts[0][1]);
for (var p = 1; p < pts.length; p++) {
......@@ -372,12 +372,12 @@ shadowSize and lineWidth are derived as well from the points series.
ctx.stroke();
}
function draw(plot, ctx){
function draw(plot, ctx) {
var plotOffset = plot.getPlotOffset();
ctx.save();
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)) {
drawSeriesErrors(plot, ctx, s);
}
......
......@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
*/
(function ($) {
(function($) {
var options = {
series: {
......
......@@ -52,7 +52,7 @@ Google Maps).
*/
(function ($) {
(function($) {
var options = {
series: {
images: {
......@@ -65,12 +65,12 @@ Google Maps).
$.plot.image = {};
$.plot.image.loadDataImages = function (series, options, callback) {
var urls = [], points = [];
$.plot.image.loadDataImages = function(series, options, callback) {
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)) {
return;
}
......@@ -79,7 +79,7 @@ Google Maps).
s = s.data;
}
$.each(s, function (i, p) {
$.each(s, function(i, p) {
if (typeof p[0] === "string") {
urls.push(p[0]);
points.push(p);
......@@ -87,8 +87,8 @@ Google Maps).
});
});
$.plot.image.load(urls, function (loadedImages) {
$.each(points, function (i, p) {
$.plot.image.load(urls, function(loadedImages) {
$.each(points, function(i, p) {
var url = p[0];
if (loadedImages[url]) {
p[0] = loadedImages[url];
......@@ -99,14 +99,14 @@ Google Maps).
});
};
$.plot.image.load = function (urls, callback) {
$.plot.image.load = function(urls, callback) {
var missing = urls.length, loaded = {};
if (missing === 0) {
callback({});
}
$.each(urls, function (i, url) {
var handler = function () {
$.each(urls, function(i, url) {
var handler = function() {
--missing;
loaded[url] = this;
......@@ -158,10 +158,10 @@ Google Maps).
// if the anchor is at the center of the pixel, expand the
// image by 1/2 pixel in each direction
if (series.images.anchor === "center") {
tmp = 0.5 * (x2-x1) / (img.width - 1);
tmp = 0.5 * (x2 - x1) / (img.width - 1);
x1 -= tmp;
x2 += tmp;
tmp = 0.5 * (y2-y1) / (img.height - 1);
tmp = 0.5 * (y2 - y1) / (img.height - 1);
y1 -= tmp;
y2 += tmp;
}
......
......@@ -48,17 +48,17 @@ Licensed under the MIT license.
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
// pixels. This is the ratio between the canvas width that the browser
// advertises and the number of pixels actually present in that space.
// Determine the screen's ratio of physical to device-independent
// pixels. This is the ratio between the canvas width that the browser
// advertises and the number of pixels actually present in that space.
// The iPhone 4, for example, has a device-independent width of 320px,
// but its screen is actually 640px wide. It therefore has a pixel
// ratio of 2, while most normal devices have a ratio of 1.
// The iPhone 4, for example, has a device-independent width of 320px,
// but its screen is actually 640px wide. It therefore has a pixel
// ratio of 2, while most normal devices have a ratio of 1.
var devicePixelRatio = window.devicePixelRatio || 1,
devicePixelRatio = window.devicePixelRatio || 1,
backingStoreRatio =
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
......@@ -87,7 +87,7 @@ Licensed under the MIT license.
* Resizes the canvas to the given dimensions.
*
* @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) {
......@@ -370,22 +370,23 @@ Licensed under the MIT license.
var cx = textWidth / 2,
cy = textHeight / 2,
transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px";
// Transforms alter the div's appearance without changing
// its origin. This will make it difficult to position it
// later, since we'll be positioning the new bounding box
// with respect to the old origin. We can work around this
// by adding a translation to align the new bounding box's
// top-left corner with the origin, using the same matrix.
// Rather than examining all four points, we can use the
// angle to figure out in advance which two points are in
// the top-left quadrant; we can then use the x-coordinate
// of the first (left-most) point and the y-coordinate of
// the second (top-most) point as the bounding box corner.
var x, y;
transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px",
// Transforms alter the div's appearance without changing
// its origin. This will make it difficult to position it
// later, since we'll be positioning the new bounding box
// with respect to the old origin. We can work around this
// by adding a translation to align the new bounding box's
// top-left corner with the origin, using the same matrix.
// Rather than examining all four points, we can use the
// angle to figure out in advance which two points are in
// the top-left quadrant; we can then use the x-coordinate
// of the first (left-most) point and the y-coordinate of
// the second (top-most) point as the bounding box corner.
x, y;
if (angle < 90) {
x = Math.floor(cx * cos + cy * sin - cx);
y = Math.floor(cx * sin + cy * cos - cy);
......@@ -710,7 +711,7 @@ Licensed under the MIT license.
mouseActiveRadius: 10 // how far the mouse can be away to activate an item
},
interaction: {
redrawOverlayInterval: 1000/60 // time between updates, -1 means in same flow
redrawOverlayInterval: 1000 / 60 // time between updates, -1 means in same flow
},
hooks: {}
},
......@@ -719,7 +720,7 @@ Licensed under the MIT license.
eventHolder = null, // jQuery object that events should be bound to
ctx = null, octx = null,
xaxes = [], yaxes = [],
plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
plotOffset = { left: 0, right: 0, top: 0, bottom: 0 },
plotWidth = 0, plotHeight = 0,
hooks = {
processOptions: [],
......@@ -742,29 +743,29 @@ Licensed under the MIT license.
plot.getPlaceholder = function() { return placeholder; };
plot.getCanvas = function() { return surface.element; };
plot.getPlotOffset = function() { return plotOffset; };
plot.width = function () { return plotWidth; };
plot.height = function () { return plotHeight; };
plot.offset = function () {
plot.width = function() { return plotWidth; };
plot.height = function() { return plotHeight; };
plot.offset = function() {
var o = eventHolder.offset();
o.left += plotOffset.left;
o.top += plotOffset.top;
return o;
};
plot.getData = function () { return series; };
plot.getAxes = function () {
plot.getData = function() { return series; };
plot.getAxes = function() {
var res = {};
$.each(xaxes.concat(yaxes), function (_, axis) {
$.each(xaxes.concat(yaxes), function(_, axis) {
if (axis) {
res[axis.direction + (axis.n !== 1 ? axis.n : "") + "axis"] = axis;
}
});
return res;
};
plot.getXAxes = function () { return xaxes; };
plot.getYAxes = function () { return yaxes; };
plot.getXAxes = function() { return xaxes; };
plot.getYAxes = function() { return yaxes; };
plot.c2p = canvasToAxisCoords;
plot.p2c = axisToCanvasCoords;
plot.getOptions = function () { return options; };
plot.getOptions = function() { return options; };
plot.highlight = highlight;
plot.unhighlight = unhighlight;
plot.triggerRedrawOverlay = triggerRedrawOverlay;
......@@ -775,7 +776,7 @@ Licensed under the MIT license.
};
};
plot.shutdown = shutdown;
plot.destroy = function () {
plot.destroy = function() {
shutdown();
placeholder.removeData("plot").empty();
......@@ -792,7 +793,7 @@ Licensed under the MIT license.
highlights = [];
plot = null;
};
plot.resize = function (width, height) {
plot.resize = function(width, height) {
width = width || placeholder.width();
height = height || placeholder.height();
surface.resize(width, height);
......@@ -811,7 +812,6 @@ Licensed under the MIT license.
draw();
bindEvents();
function executeHooks(hook, args) {
args = [plot].concat(args);
for (var i = 0; i < hook.length; ++i) {
......@@ -1099,7 +1099,7 @@ Licensed under the MIT license.
function allAxes() {
// 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) {
......@@ -1291,7 +1291,7 @@ Licensed under the MIT license.
}
}
$.each(allAxes(), function (_, axis) {
$.each(allAxes(), function(_, axis) {
// init axis
axis.datamin = topSentry;
axis.datamax = bottomSentry;
......@@ -1301,7 +1301,7 @@ Licensed under the MIT license.
for (i = 0; i < series.length; ++i) {
s = series[i];
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
......@@ -1337,7 +1337,7 @@ Licensed under the MIT license.
ps = s.datapoints.pointsize;
points = s.datapoints.points;
s.xaxis.used = s.yaxis.used = true;
for (j = k = 0; j < data.length; ++j, k += ps) {
......@@ -1401,7 +1401,7 @@ Licensed under the MIT license.
for (i = 0; i < series.length; ++i) {
s = series[i];
executeHooks(hooks.processDatapoints, [ s, s.datapoints]);
executeHooks(hooks.processDatapoints, [s, s.datapoints]);
}
// second pass: find datamax/datamin for auto-scaling
......@@ -1473,7 +1473,7 @@ Licensed under the MIT license.
updateAxis(s.yaxis, ymin, ymax);
}
$.each(allAxes(), function (_, axis) {
$.each(allAxes(), function(_, axis) {
if (axis.datamin === topSentry) {
axis.datamin = null;
}
......@@ -1574,15 +1574,15 @@ Licensed under the MIT license.
// data point to canvas coordinate
if (t === identity) { // slight optimization
axis.p2c = function (p) { return (p - m) * s; };
axis.p2c = function(p) { return (p - m) * s; };
} else {
axis.p2c = function (p) { return (t(p) - m) * s; };
axis.p2c = function(p) { return (t(p) - m) * s; };
}
// canvas coordinate to data point
if (!it) {
axis.c2p = function (c) { return m + c / s; };
axis.c2p = function(c) { return m + c / s; };
} 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.
// check axis labels, note we don't check the actual
// labels but instead use the overall width/height to not
// jump as much around with replots
$.each(allAxes(), function (_, axis) {
$.each(allAxes(), function(_, axis) {
if (axis.reserveSpace && axis.ticks && axis.ticks.length) {
var lastTick = axis.ticks[axis.ticks.length - 1];
if (axis.direction === "x") {
......@@ -1806,7 +1806,7 @@ Licensed under the MIT license.
}
// init axes
$.each(axes, function (_, axis) {
$.each(axes, function(_, axis) {
axis.show = axis.options.show;
if (axis.show == null) {
axis.show = axis.used; // by default an axis is visible if it's got data
......@@ -1819,9 +1819,9 @@ Licensed under the MIT license.
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
setupTickGeneration(axis);
setTicks(axis);
......@@ -1840,7 +1840,7 @@ Licensed under the MIT license.
// might stick out
adjustLayoutForThingsStickingOut();
$.each(allocatedAxes, function (_, axis) {
$.each(allocatedAxes, function(_, axis) {
allocateAxisBoxSecondPhase(axis);
});
}
......@@ -1849,7 +1849,7 @@ Licensed under the MIT license.
plotHeight = surface.height - plotOffset.bottom - plotOffset.top;
// now we got the proper plot dimensions, we can compute the scaling
$.each(axes, function (_, axis) {
$.each(axes, function(_, axis) {
setTransformationHelpers(axis);
});
......@@ -1903,10 +1903,12 @@ Licensed under the MIT license.
}
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) {
noTicks = opts.ticks;
} else {
......@@ -1964,7 +1966,7 @@ Licensed under the MIT license.
if (!axis.tickGenerator) {
axis.tickGenerator = function (axis) {
axis.tickGenerator = function(axis) {
var ticks = [],
start = floorInBase(axis.min, axis.tickSize),
......@@ -1981,17 +1983,18 @@ Licensed under the MIT license.
return ticks;
};
axis.tickFormatter = function (value, axis) {
axis.tickFormatter = function(value, axis) {
var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1;
var formatted = "" + Math.round(value * factor) / factor;
var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1,
formatted = "" + Math.round(value * factor) / factor;
// If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision.
if (axis.tickDecimals != null) {
var decimal = formatted.indexOf(".");
var precision = decimal === -1 ? 0 : formatted.length - decimal - 1;
var decimal = formatted.indexOf("."),
precision = decimal === -1 ? 0 : formatted.length - decimal - 1;
if (precision < axis.tickDecimals) {
return (precision ? formatted : formatted + ".") + ("" + factor).substr(1, axis.tickDecimals - precision);
}
......@@ -2002,7 +2005,7 @@ Licensed under the MIT license.
}
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) {
......@@ -2019,7 +2022,7 @@ Licensed under the MIT license.
}
}
axis.tickGenerator = function (axis) {
axis.tickGenerator = function(axis) {
// copy ticks, scaled to this axis
var ticks = [], v, i;
for (i = 0; i < otherAxis.ticks.length; ++i) {
......@@ -2064,8 +2067,9 @@ Licensed under the MIT license.
var i, v;
axis.ticks = [];
for (i = 0; i < ticks.length; ++i) {
var label = null;
var t = ticks[i];
var label = null,
t = ticks[i];
if (typeof t === "object") {
v = +t[0];
if (t.length > 1) {
......@@ -2185,10 +2189,10 @@ Licensed under the MIT license.
surface.removeText(markingLayer);
// process markings
var markingsUnderGrid = [];
var markingsAboveGrid = [];
var markings = options.grid.markings;
var markingsUnderGrid = [],
markingsAboveGrid = [],
markings = options.grid.markings;
if (markings) {
if ($.isFunction(markings)) {
axes = plot.getAxes();
......@@ -2204,7 +2208,7 @@ Licensed under the MIT license.
for (i = 0; i < markings.length; ++i) {
var m = markings[i];
if (m.aboveGrid) {
markingsAboveGrid.push(m);
} else {
......@@ -2212,7 +2216,7 @@ Licensed under the MIT license.
}
}
}
drawMarkings(markingsUnderGrid, markingLayer);
// draw the ticks
......@@ -2327,10 +2331,10 @@ Licensed under the MIT license.
bc = options.grid.borderColor;
if (typeof bw === "object" || typeof bc === "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") {
bc = {top: bc, right: bc, bottom: bc, left: bc};
bc = { top: bc, right: bc, bottom: bc, left: bc };
}
if (bw.top > 0) {
......@@ -2365,7 +2369,7 @@ Licensed under the MIT license.
ctx.lineWidth = bw.left;
ctx.beginPath();
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();
}
} else {
......@@ -2377,7 +2381,7 @@ Licensed under the MIT license.
ctx.restore();
}
function drawMarkings(markings, markingLayer) {
if (!markings) {
return;
......@@ -2387,7 +2391,7 @@ Licensed under the MIT license.
drawMarking(markings[i], markingLayer);
}
}
function drawMarking(m, markingLayer) {
var xrange = extractRange(m, "x"),
yrange = extractRange(m, "y");
......@@ -2449,9 +2453,12 @@ Licensed under the MIT license.
if (m.text) {
// left aligned horizontal position:
var xPos = xrange.from + plotOffset.left;
// top baselined vertical position:
var yPos = (yrange.to + plotOffset.top);
var xPos = xrange.from + plotOffset.left,
// top baselined vertical position:
yPos = (yrange.to + plotOffset.top);
if (!!m.textAlign) {
switch (m.textAlign.toLowerCase()) {
......@@ -2481,7 +2488,7 @@ Licensed under the MIT license.
function drawAxisLabels() {
$.each(allAxes(), function (_, axis) {
$.each(allAxes(), function(_, axis) {
var box = axis.box,
axisOptions = axis.options,
......@@ -3050,7 +3057,7 @@ Licensed under the MIT license.
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);
ctx.restore();
}
......@@ -3164,7 +3171,7 @@ Licensed under the MIT license.
if (options.legend.container != null) {
$(options.legend.container).html(table);
} else {
var pos = {"position": "absolute"},
var pos = { "position": "absolute" },
p = options.legend.position,
m = options.legend.margin;
if (m[0] == null) {
......@@ -3209,7 +3216,6 @@ Licensed under the MIT license.
}
}
// interactive features
var highlights = [],
......@@ -3332,20 +3338,20 @@ Licensed under the MIT license.
function onMouseMove(e) {
if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e,
function (s) { return s.hoverable !== false; });
function(s) { return s.hoverable !== false; });
}
}
function onMouseLeave(e) {
if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e,
function () { return false; });
function() { return false; });
}
}
function onClick(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
......@@ -3385,7 +3391,7 @@ Licensed under the MIT license.
}
}
placeholder.trigger(eventname, [ pos, item ]);
placeholder.trigger(eventname, [pos, item]);
}
function triggerRedrawOverlay() {
......@@ -3484,8 +3490,8 @@ Licensed under the MIT license.
return;
}
var pointRadius;
var radius;
var pointRadius, radius;
if (series.points.show) {
pointRadius = series.points.radius + series.points.lineWidth / 2;
radius = 1.5 * pointRadius;
......@@ -3528,7 +3534,7 @@ Licensed under the MIT license.
octx.strokeStyle = highlightColor;
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) {
......@@ -3589,17 +3595,18 @@ Licensed under the MIT license.
// Draw a rectangle with rounded corner on the canvas.
//
// @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.
// @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.
// @param {number} width The width 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
// to be drawn.
function roundRect(ctx, x, y, width, height, radius) {
var r = x + width;
var b = y + height;
var r = x + width,
b = y + height;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(r - radius, y);
......
......@@ -79,7 +79,7 @@ can set the default in the options.
*/
(function ($) {
(function($) {
var options = {
xaxis: {
zoomRange: null, // or [number, number] (min range, max range)
......@@ -137,7 +137,7 @@ can set the default in the options.
return;
}
panTimeout = setTimeout(function () {
panTimeout = setTimeout(function() {
plot.pan({ left: prevPageX - e.pageX,
top: prevPageY - e.pageY });
prevPageX = e.pageX;
......@@ -172,7 +172,7 @@ can set the default in the options.
}
}
plot.zoomOut = function (args) {
plot.zoomOut = function(args) {
if (!args) {
args = {};
}
......@@ -185,7 +185,7 @@ can set the default in the options.
plot.zoom(args);
};
plot.zoom = function (args) {
plot.zoom = function(args) {
if (!args) {
args = {};
}
......@@ -256,11 +256,11 @@ can set the default in the options.
plot.draw();
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 = {
x: +args.left,
y: +args.top
......@@ -273,7 +273,7 @@ can set the default in the options.
delta.y = 0;
}
$.each(plot.getAxes(), function (_, axis) {
$.each(plot.getAxes(), function(_, axis) {
var opts = axis.options,
min = axis.c2p(axis.p2c(axis.min) + d),
......@@ -308,7 +308,7 @@ can set the default in the options.
plot.draw();
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.
// 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) {
......@@ -74,11 +74,11 @@ More detail and specific examples can be found in the included HTML file.
centerLeft = null,
centerTop = null,
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
......@@ -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.label.show) {
options.series.pie.radius = 3/4;
options.series.pie.radius = 3 / 4;
} else {
options.series.pie.radius = 1;
}
......@@ -340,11 +340,11 @@ More detail and specific examples can be found in the included HTML file.
function drawShadow() {
var shadowLeft = options.series.pie.shadow.left;
var shadowTop = options.series.pie.shadow.top;
var edge = 10;
var alpha = options.series.pie.shadow.alpha;
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
var shadowLeft = options.series.pie.shadow.left,
shadowTop = options.series.pie.shadow.top,
edge = 10,
alpha = options.series.pie.shadow.alpha,
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) {
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.
function drawLabels() {
var currentAngle = startAngle;
var radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius;
var currentAngle = startAngle,
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) {
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.
text = plf(text, slice);
}
var halfAngle = ((startAngle + slice.angle) + startAngle) / 2;
var x = centerLeft + Math.round(Math.cos(halfAngle) * radius);
var y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt;
var halfAngle = ((startAngle + slice.angle) + startAngle) / 2,
x = centerLeft + Math.round(Math.cos(halfAngle) * radius),
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);
var label = target.children("#pieLabel" + index);
var labelTop = (y - label.height() / 2);
var labelLeft = (x - label.width() / 2);
var label = target.children("#pieLabel" + index),
labelTop = (y - label.height() / 2),
labelLeft = (x - label.width() / 2);
label.css("top", labelTop);
label.css("left", labelLeft);
......@@ -565,9 +565,9 @@ More detail and specific examples can be found in the included HTML file.
//-- Additional Interactive related functions --
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[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]) &&
(c = !c);
}
......@@ -656,10 +656,10 @@ More detail and specific examples can be found in the included HTML file.
function triggerClickHoverEvent(eventname, e) {
var offset = plot.offset();
var canvasX = parseInt(e.pageX - offset.left, 10);
var canvasY = parseInt(e.pageY - offset.top, 10);
var item = findNearbySlice(canvasX, canvasY);
var offset = plot.offset(),
canvasX = parseInt(e.pageX - offset.left, 10),
canvasY = parseInt(e.pageY - offset.top, 10),
item = findNearbySlice(canvasX, canvasY);
if (options.grid.autoHighlight) {
......@@ -730,9 +730,8 @@ More detail and specific examples can be found in the included HTML file.
function drawOverlay(plot, octx) {
var options = plot.getOptions();
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
var options = plot.getOptions(),
radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
octx.save();
octx.translate(centerLeft, centerTop);
......@@ -774,7 +773,7 @@ More detail and specific examples can be found in the included HTML file.
show: false,
radius: "auto", // actual radius of the visible pie (based on full calculated radius if <=1, or hard pixel value)
innerRadius: 0, /* for donut */
startAngle: 3/2,
startAngle: 3 / 2,
tilt: 1,
shadow: {
left: 5, // shadow left offset
......
......@@ -11,7 +11,7 @@ can just fix the size of their placeholders.
*/
(function ($) {
(function($) {
var options = { }; // no options
function init(plot) {
......
......@@ -78,30 +78,30 @@ The plugin allso adds the following methods to the plot object:
*/
(function ($) {
(function($) {
function init(plot) {
var selection = {
first: { x: -1, y: -1},
second: { x: -1, y: -1},
first: { x: -1, y: -1 },
second: { x: -1, y: -1 },
show: false,
active: false,
touch: false
};
},
// FIXME: The drag handling implemented here should be
// abstracted out, there's some similar code from a library in
// the navigation plugin, this should be massaged a bit to fit
// the Flot cases here better and reused. Doing this would
// make this plugin much slimmer.
// FIXME: The drag handling implemented here should be
// abstracted out, there's some similar code from a library in
// the navigation plugin, this should be massaged a bit to fit
// the Flot cases here better and reused. Doing this would
// make this plugin much slimmer.
var savedhandlers = {},
savedhandlers = {},
mouseUpHandler = null;
function onMouseMove(e) {
if (selection.active) {
updateSelection(e);
plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]);
plot.getPlaceholder().trigger("plotselecting", [getSelection()]);
// prevent the default action if it is a 'touch' action
if (selection.touch === true) {
......@@ -117,18 +117,17 @@ The plugin allso adds the following methods to the plot object:
return;
}
// cancel out any text selections
document.body.focus();
// prevent text selection and drag in old-school browsers
if (document.onselectstart !== undefined && savedhandlers.onselectstart === null) {
savedhandlers.onselectstart = document.onselectstart;
document.onselectstart = function () { return false; };
document.onselectstart = function() { return false; };
}
if (document.ondrag !== undefined && savedhandlers.ondrag === null) {
savedhandlers.ondrag = document.ondrag;
document.ondrag = function () { return false; };
document.ondrag = function() { return false; };
}
setSelectionPos(selection.first, e);
......@@ -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
// able to whack the same handler again
mouseUpHandler = function (e) { onMouseUp(e); };
mouseUpHandler = function(e) { onMouseUp(e); };
$(document).one(selection.touch ? "touchend" : "mouseup", mouseUpHandler);
}
......@@ -161,8 +160,8 @@ The plugin allso adds the following methods to the plot object:
triggerSelectedEvent();
} else {
// this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotselecting", [ null ]);
plot.getPlaceholder().trigger("plotunselected", []);
plot.getPlaceholder().trigger("plotselecting", [null]);
}
selection.touch = false;
......@@ -179,7 +178,7 @@ The plugin allso adds the following methods to the plot object:
c1 = selection.first,
c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) {
$.each(plot.getAxes(), function(name, axis) {
if (axis.used) {
var p1 = axis.c2p(c1[axis.direction]),
p2 = axis.c2p(c2[axis.direction]);
......@@ -192,11 +191,11 @@ The plugin allso adds the following methods to the plot object:
function triggerSelectedEvent() {
var r = getSelection();
plot.getPlaceholder().trigger("plotselected", [ r ]);
plot.getPlaceholder().trigger("plotselected", [r]);
// backwards-compat stuff, to be removed in future
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:
function setSelectionPos(pos, e) {
var o = plot.getOptions(),
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.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:
eventHolder.mousemove(onMouseMove);
eventHolder.mousedown(onMouseDown);
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
eventHolder.unbind("mousedown", onMouseDown);
onMouseDown(e);
......@@ -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
if (selection.show && selectionIsSane()) {
var plotOffset = plot.getPlotOffset();
var o = plot.getOptions();
var plotOffset = plot.getPlotOffset(),
o = plot.getOptions(),
c, x, y, w, h;
ctx.save();
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.lineWidth = 1;
ctx.lineJoin = o.selection.shape;
ctx.fillStyle = c.scale("a", 0.4).toString();
var x = Math.min(selection.first.x, selection.second.x) + 0.5,
y = Math.min(selection.first.y, selection.second.y) + 0.5,
w = Math.abs(selection.second.x - selection.first.x) - 1,
h = Math.abs(selection.second.y - selection.first.y) - 1;
x = Math.min(selection.first.x, selection.second.x) + 0.5;
y = Math.min(selection.first.y, selection.second.y) + 0.5;
w = Math.abs(selection.second.x - selection.first.x) - 1;
h = Math.abs(selection.second.y - selection.first.y) - 1;
ctx.fillRect(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:
}
});
plot.hooks.shutdown.push(function (plot, eventHolder) {
plot.hooks.shutdown.push(function(plot, eventHolder) {
eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler) {
......
......@@ -35,7 +35,7 @@ charts or filled areas).
*/
(function ($) {
(function($) {
var options = {
series: { stack: null } // or number/string
};
......
......@@ -13,48 +13,48 @@ The symbols are accessed as strings through the standard symbol options:
*/
(function ($) {
(function($) {
function processRawData(plot, series) {
// we normalize the area of each symbol so it is approximately the
// same as a circle of the given radius
var handlers = {
square: function (ctx, x, y, radius) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.rect(x - size, y - size, size + size, size + size);
},
diamond: 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);
ctx.lineTo(x, y - size);
ctx.lineTo(x + size, y);
ctx.lineTo(x, y + size);
ctx.lineTo(x - size, y);
},
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))
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3));
var height = size * Math.sin(Math.PI / 3);
ctx.moveTo(x - size/2, y + height/2);
ctx.lineTo(x + size/2, y + height/2);
if (!shadow) {
ctx.lineTo(x, y - height/2);
ctx.lineTo(x - size/2, y + height/2);
square: function(ctx, x, y, radius) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.rect(x - size, y - size, size + size, size + size);
},
diamond: 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);
ctx.lineTo(x, y - size);
ctx.lineTo(x + size, y);
ctx.lineTo(x, y + size);
ctx.lineTo(x - size, y);
},
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))
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)),
height = size * Math.sin(Math.PI / 3);
ctx.moveTo(x - size / 2, y + height / 2);
ctx.lineTo(x + size / 2, y + height / 2);
if (!shadow) {
ctx.lineTo(x, 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) {
// 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);
}
};
s = series.points.symbol;
var s = series.points.symbol;
if (handlers[s]) {
series.points.symbol = handlers[s];
}
......
......@@ -43,7 +43,7 @@ You may need to check for this in hover events.
*/
(function ($) {
(function($) {
var options = {
series: { threshold: null } // or { below: number, color: color spec}
};
......@@ -135,7 +135,6 @@ You may need to check for this in hover events.
}
plot.hooks.processDatapoints.push(processThresholds);
function processThresholdsLegend(ctx, canvas, s) {
if (!s.threshold) {
......@@ -145,11 +144,11 @@ You may need to check for this in hover events.
var color = s.threshold.color ? s.threshold.color : "black";
$(".legendLabel").each(function() {
if($(this).text() === s.label)
if ($(this).text() === s.label)
{
var legend = $(this).prev().find("div > div");
legend.css("border-right-color" , color);
legend.css("border-bottom-color" , color);
legend.css("border-right-color", color);
legend.css("border-bottom-color", color);
}
});
}
......
......@@ -35,15 +35,15 @@ API.txt for details.
}
var leftPad = function(n, pad) {
n = "" + n;
pad = "" + (pad == null ? "0" : pad);
return n.length === 1 ? pad + n : n;
};
var r = [],
n = "" + n;
pad = "" + (pad == null ? "0" : pad);
return n.length === 1 ? pad + n : n;
},
r = [],
escape = false,
hours = d.getHours(),
isAM = hours < 12;
isAM = hours < 12,
c, hours12;
if (monthNames == null) {
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
......@@ -53,8 +53,6 @@ API.txt for details.
dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
}
var hours12;
if (hours > 12) {
hours12 = hours - 12;
} else if (hours === 0) {
......@@ -65,7 +63,7 @@ API.txt for details.
for (var i = 0; i < fmt.length; ++i) {
var c = fmt.charAt(i);
c = fmt.charAt(i);
if (escape) {
switch (c) {
......@@ -81,7 +79,7 @@ API.txt for details.
case "e":
c = leftPad(d.getDate(), " ");
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":
c = leftPad(hours);
break;
......@@ -193,40 +191,46 @@ API.txt for details.
// map of app. size of time units in milliseconds
var timeUnitSize = {
"second": 1000,
"minute": 60 * 1000,
"hour": 60 * 60 * 1000,
"day": 24 * 60 * 60 * 1000,
"month": 30 * 24 * 60 * 60 * 1000,
"quarter": 3 * 30 * 24 * 60 * 60 * 1000,
"year": 365.2425 * 24 * 60 * 60 * 1000
};
// the allowed tick sizes, after 1 year we use
// an integer algorithm
var baseSpec = [
[1, "second"], [2, "second"], [5, "second"], [10, "second"],
[30, "second"],
[1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
[30, "minute"],
[1, "hour"], [2, "hour"], [4, "hour"],
[8, "hour"], [12, "hour"],
[1, "day"], [2, "day"], [3, "day"],
[0.25, "month"], [0.5, "month"], [1, "month"],
[2, "month"]
];
// we don't know which variant(s) we'll need yet, but generating both is
// cheap
var specMonths = baseSpec.concat([[3, "month"], [6, "month"],
[1, "year"]]);
var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"],
[1, "year"]]);
"second": 1000,
"minute": 60 * 1000,
"hour": 60 * 60 * 1000,
"day": 24 * 60 * 60 * 1000,
"month": 30 * 24 * 60 * 60 * 1000,
"quarter": 3 * 30 * 24 * 60 * 60 * 1000,
"year": 365.2425 * 24 * 60 * 60 * 1000
},
// the allowed tick sizes, after 1 year we use
// an integer algorithm
baseSpec = [
[1, "second"], [2, "second"], [5, "second"], [10, "second"],
[30, "second"],
[1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
[30, "minute"],
[1, "hour"], [2, "hour"], [4, "hour"],
[8, "hour"], [12, "hour"],
[1, "day"], [2, "day"], [3, "day"],
[0.25, "month"], [0.5, "month"], [1, "month"],
[2, "month"]
],
// we don't know which variant(s) we'll need yet, but generating both is
// cheap
specMonths = baseSpec.concat([
[3, "month"],
[6, "month"],
[1, "year"]
]),
specQuarters = baseSpec.concat([
[1, "quarter"],
[2, "quarter"],
[1, "year"]
]);
function init(plot) {
plot.hooks.processOptions.push(function (plot) {
plot.hooks.processOptions.push(function(plot) {
$.each(plot.getAxes(), function(axisName, axis) {
var opts = axis.options;
......@@ -236,12 +240,12 @@ API.txt for details.
var ticks = [],
d = dateGenerator(axis.min, opts),
minSize = 0;
minSize = 0,
// make quarter use a possibility if quarters are
// mentioned in either of these options
// make quarter use a possibility if quarters are
// mentioned in either of these options
var spec = (opts.tickSize && opts.tickSize[1] ===
spec = (opts.tickSize && opts.tickSize[1] ===
"quarter") ||
(opts.minTickSize && opts.minTickSize[1] ===
"quarter") ? specQuarters : specMonths;
......@@ -385,7 +389,7 @@ API.txt for details.
return ticks;
};
axis.tickFormatter = function (v, axis) {
axis.tickFormatter = function(v, axis) {
var d = dateGenerator(v, axis.options);
......
......@@ -36,10 +36,11 @@
"url": "https://github.com/flot/flot/issues"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.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": [
{
......
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