Commit f2b3b266 authored by Nick Schonning's avatar Nick Schonning

Merge pull request #1241 from nschonni/jsdoc-cleanup

Add spacing to comments in jquery.flot.js
parents 14cc92f7 4f293593
...@@ -36,7 +36,6 @@ Licensed under the MIT license. ...@@ -36,7 +36,6 @@ Licensed under the MIT license.
.appendTo(container); .appendTo(container);
// If HTML5 Canvas isn't available, fall back to [Ex|Flash]canvas // If HTML5 Canvas isn't available, fall back to [Ex|Flash]canvas
if (!element.getContext) { if (!element.getContext) {
if (window.G_vmlCanvasManager) { if (window.G_vmlCanvasManager) {
element = window.G_vmlCanvasManager.initElement(element); element = window.G_vmlCanvasManager.initElement(element);
...@@ -57,7 +56,6 @@ Licensed under the MIT license. ...@@ -57,7 +56,6 @@ Licensed under the MIT license.
// 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.
devicePixelRatio = window.devicePixelRatio || 1, devicePixelRatio = window.devicePixelRatio || 1,
backingStoreRatio = backingStoreRatio =
context.webkitBackingStorePixelRatio || context.webkitBackingStorePixelRatio ||
...@@ -69,17 +67,14 @@ Licensed under the MIT license. ...@@ -69,17 +67,14 @@ Licensed under the MIT license.
this.pixelRatio = devicePixelRatio / backingStoreRatio; this.pixelRatio = devicePixelRatio / backingStoreRatio;
// Size the canvas to match the internal dimensions of its container // Size the canvas to match the internal dimensions of its container
this.resize(container.width(), container.height()); this.resize(container.width(), container.height());
// Collection of HTML div layers for text overlaid onto the canvas // Collection of HTML div layers for text overlaid onto the canvas
this.textContainer = null; this.textContainer = null;
this.text = {}; this.text = {};
// Cache of text fragments and metrics, so we can avoid expensively // Cache of text fragments and metrics, so we can avoid expensively
// re-calculating them when the plot is re-rendered in a loop. // re-calculating them when the plot is re-rendered in a loop.
this._textCache = {}; this._textCache = {};
} }
...@@ -105,7 +100,6 @@ Licensed under the MIT license. ...@@ -105,7 +100,6 @@ Licensed under the MIT license.
// displays have that many more pixels in the same advertised space. // displays have that many more pixels in the same advertised space.
// Resizing should reset the state (excanvas seems to be buggy though) // Resizing should reset the state (excanvas seems to be buggy though)
if (this.width !== width) { if (this.width !== width) {
element.width = width * pixelRatio; element.width = width * pixelRatio;
element.style.width = width + "px"; element.style.width = width + "px";
...@@ -121,7 +115,6 @@ Licensed under the MIT license. ...@@ -121,7 +115,6 @@ Licensed under the MIT license.
// Save the context, so we can reset in case we get replotted. The // Save the context, so we can reset in case we get replotted. The
// restore ensure that we're really back at the initial state, and // restore ensure that we're really back at the initial state, and
// should be safe even if we haven't saved the initial state yet. // should be safe even if we haven't saved the initial state yet.
context.restore(); context.restore();
context.save(); context.save();
...@@ -148,7 +141,6 @@ Licensed under the MIT license. ...@@ -148,7 +141,6 @@ Licensed under the MIT license.
// For each text layer, add elements marked as active that haven't // For each text layer, add elements marked as active that haven't
// already been rendered, and remove those that are no longer active. // already been rendered, and remove those that are no longer active.
for (var layerKey in cache) { for (var layerKey in cache) {
if (Object.prototype.hasOwnProperty.call(cache, layerKey)) { if (Object.prototype.hasOwnProperty.call(cache, layerKey)) {
...@@ -209,11 +201,9 @@ Licensed under the MIT license. ...@@ -209,11 +201,9 @@ Licensed under the MIT license.
var layer = this.text[classes]; var layer = this.text[classes];
// Create the text layer if it doesn't exist // Create the text layer if it doesn't exist
if (layer == null) { if (layer == null) {
// Create the text layer container, if it doesn't exist // Create the text layer container, if it doesn't exist
if (this.textContainer == null) { if (this.textContainer == null) {
this.textContainer = $("<div class='flot-text'></div>") this.textContainer = $("<div class='flot-text'></div>")
.css({ .css({
...@@ -287,11 +277,13 @@ Licensed under the MIT license. ...@@ -287,11 +277,13 @@ Licensed under the MIT license.
var textStyle, layerCache, styleCache, angleCache, info; var textStyle, layerCache, styleCache, angleCache, info;
text = "" + text; // Cast to string in case we have a number or such // Cast to string in case we have a number or such
angle = (360 + (angle || 0)) % 360; // Normalize the angle to 0...359 text = "" + text;
// If the font is a font-spec object, generate a CSS font definition // Normalize the angle to 0...359
angle = (360 + (angle || 0)) % 360;
// If the font is a font-spec object, generate a CSS font definition
if (typeof font === "object") { if (typeof font === "object") {
textStyle = font.style + " " + font.variant + " " + font.weight + " " + font.size + "px/" + font.lineHeight + "px " + font.family; textStyle = font.style + " " + font.variant + " " + font.weight + " " + font.size + "px/" + font.lineHeight + "px " + font.family;
} else { } else {
...@@ -299,7 +291,6 @@ Licensed under the MIT license. ...@@ -299,7 +291,6 @@ Licensed under the MIT license.
} }
// Retrieve or create the caches for the text's layer, style, and angle // Retrieve or create the caches for the text's layer, style, and angle
layerCache = this._textCache[layer]; layerCache = this._textCache[layer];
if (layerCache == null) { if (layerCache == null) {
layerCache = this._textCache[layer] = {}; layerCache = this._textCache[layer] = {};
...@@ -318,7 +309,6 @@ Licensed under the MIT license. ...@@ -318,7 +309,6 @@ Licensed under the MIT license.
info = angleCache[text]; info = angleCache[text];
// If we can't find a matching element in our cache, create a new one // If we can't find a matching element in our cache, create a new one
if (info == null) { if (info == null) {
var element = $("<div></div>").html(text) var element = $("<div></div>").html(text)
...@@ -340,7 +330,6 @@ Licensed under the MIT license. ...@@ -340,7 +330,6 @@ Licensed under the MIT license.
// Save the original dimensions of the text; we'll modify these // Save the original dimensions of the text; we'll modify these
// later to take into account rotation, if there is any. // later to take into account rotation, if there is any.
var textWidth = element.outerWidth(true), var textWidth = element.outerWidth(true),
textHeight = element.outerHeight(true); textHeight = element.outerHeight(true);
...@@ -350,15 +339,18 @@ Licensed under the MIT license. ...@@ -350,15 +339,18 @@ Licensed under the MIT license.
// the way most browsers resize the div on rotate, which may cause // the way most browsers resize the div on rotate, which may cause
// the contents to wrap differently. The extra +1 is because IE // the contents to wrap differently. The extra +1 is because IE
// rounds the width differently and needs a little extra help. // rounds the width differently and needs a little extra help.
if (angle) { if (angle) {
var radians = angle * Math.PI / 180, var radians = angle * Math.PI / 180,
sin = Math.sin(radians), sin = Math.sin(radians),
cos = Math.cos(radians), cos = Math.cos(radians),
a = cos.toFixed(6), // Use fixed-point so these don't
b = (-sin).toFixed(6), // show up in scientific notation // Use fixed-point so these don't show up in scientific
c = sin.toFixed(6), // when we add them to the string // notation when we add them to the string
a = cos.toFixed(6),
b = (-sin).toFixed(6),
c = sin.toFixed(6),
transformRule; transformRule;
// Detect IE7/8 to use microsofts proprietary matrix filter // Detect IE7/8 to use microsofts proprietary matrix filter
...@@ -370,7 +362,6 @@ Licensed under the MIT license. ...@@ -370,7 +362,6 @@ Licensed under the MIT license.
// blurry text on some browsers (Chrome) when the width or // blurry text on some browsers (Chrome) when the width or
// height happens to be odd, making 50% fractional. Avoid // height happens to be odd, making 50% fractional. Avoid
// this by setting the origin to rounded values. // this by setting the origin to rounded values.
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",
...@@ -387,7 +378,6 @@ Licensed under the MIT license. ...@@ -387,7 +378,6 @@ Licensed under the MIT license.
// 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.
x, y; x, y;
if (angle < 90) { if (angle < 90) {
...@@ -430,7 +420,6 @@ Licensed under the MIT license. ...@@ -430,7 +420,6 @@ Licensed under the MIT license.
// TODO: Instead of white use the actual background color? // TODO: Instead of white use the actual background color?
// This still wouldn't solve the problem when the plot has // This still wouldn't solve the problem when the plot has
// a gradient background, but it would at least help. // a gradient background, but it would at least help.
transformRule = "progid:DXImageTransform.Microsoft.Matrix(M11=" + a + ", M12=" + b + ", M21=" + c + ", M22=" + a + ",sizingMethod='auto expand')"; transformRule = "progid:DXImageTransform.Microsoft.Matrix(M11=" + a + ", M12=" + b + ", M21=" + c + ", M22=" + a + ",sizingMethod='auto expand')";
element.css({ element.css({
...@@ -442,7 +431,6 @@ Licensed under the MIT license. ...@@ -442,7 +431,6 @@ Licensed under the MIT license.
} }
// Compute the final dimensions of the text's bounding box // Compute the final dimensions of the text's bounding box
var ac = Math.abs(cos), var ac = Math.abs(cos),
as = Math.abs(sin), as = Math.abs(sin),
originalWidth = textWidth; originalWidth = textWidth;
...@@ -489,7 +477,6 @@ Licensed under the MIT license. ...@@ -489,7 +477,6 @@ Licensed under the MIT license.
positions = info.positions; positions = info.positions;
// Tweak the div's position to match the text's alignment // Tweak the div's position to match the text's alignment
if (halign === "center") { if (halign === "center") {
x -= info.width / 2; x -= info.width / 2;
} else if (halign === "right") { } else if (halign === "right") {
...@@ -504,7 +491,6 @@ Licensed under the MIT license. ...@@ -504,7 +491,6 @@ Licensed under the MIT license.
// Determine whether this text already exists at this position. // Determine whether this text already exists at this position.
// If so, mark it for inclusion in the next render pass. // If so, mark it for inclusion in the next render pass.
for (var i = 0, position; position = positions[i]; i++) { for (var i = 0, position; position = positions[i]; i++) {
if (position.x === x && position.y === y) { if (position.x === x && position.y === y) {
position.active = true; position.active = true;
...@@ -516,7 +502,6 @@ Licensed under the MIT license. ...@@ -516,7 +502,6 @@ Licensed under the MIT license.
// For the very first position we'll re-use the original element, // For the very first position we'll re-use the original element,
// while for subsequent ones we'll clone it. // while for subsequent ones we'll clone it.
position = { position = {
active: true, active: true,
rendered: false, rendered: false,
...@@ -528,11 +513,13 @@ Licensed under the MIT license. ...@@ -528,11 +513,13 @@ Licensed under the MIT license.
positions.push(position); positions.push(position);
// Move the element to its final position within the container // Move the element to its final position within the container
position.element.css({ position.element.css({
top: Math.round(y), top: Math.round(y),
left: Math.round(x), left: Math.round(x),
"text-align": halign // In case the text wraps
// In case the text wraps
"text-align": halign
}); });
}; };
...@@ -595,65 +582,129 @@ Licensed under the MIT license. ...@@ -595,65 +582,129 @@ Licensed under the MIT license.
* The top-level container for the entire plot. * The top-level container for the entire plot.
*/ */
function Plot(placeholder, data_, options_, plugins) { function Plot(placeholder, data_, options_, plugins) {
// data is on the form: // data is on the form:
// [ series1, series2 ... ] // [ series1, series2 ... ]
// where series is either just the data as [ [x1, y1], [x2, y2], ... ] // where series is either just the data as [ [x1, y1], [x2, y2], ... ]
// or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... } // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... }
var series = [], var series = [],
options = { options = {
// the color theme used for graphs // the color theme used for graphs
colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"], colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
legend: { legend: {
show: true, show: true,
noColumns: 1, // number of colums in legend table
labelFormatter: null, // fn: string -> string // number of colums in legend table
labelBoxBorderColor: "#ccc", // border color for the little label boxes noColumns: 1,
container: null, // container (as jQuery object) to put legend in, null means default on top of graph
position: "ne", // position of default legend container within plot // fn: string -> string
margin: 5, // distance from grid edge to default legend container within plot labelFormatter: null,
backgroundColor: null, // null means auto-detect
backgroundOpacity: 0.85, // set to 0 to avoid background // border color for the little label boxes
sorted: null // default to no legend sorting labelBoxBorderColor: "#ccc",
// container (as jQuery object) to put legend in, null means default on top of graph
container: null,
// position of default legend container within plot
position: "ne",
// distance from grid edge to default legend container within plot
margin: 5,
// null means auto-detect
backgroundColor: null,
// set to 0 to avoid background
backgroundOpacity: 0.85,
// default to no legend sorting
sorted: null
}, },
xaxis: { xaxis: {
show: null, // null = auto-detect, true = always, false = never // null = auto-detect, true = always, false = never
position: "bottom", // or "top"
mode: null, // null or "time" show: null,
// or "top"
position: "bottom",
// null or "time"
mode: null,
// base color, labels, ticks
color: null,
// null (derived from CSS in placeholder) or
// object like { size: 11, lineHeight: 13, style: "italic", weight: "bold", family: "sans-serif", variant: "small-caps" }
font: null,
// min. value to show, null means set automatically
min: null,
// max. value to show, null means set automatically
max: null,
// margin in % to add if auto-setting min/max
autoscaleMargin: null,
// null or f: number -> number to transform axis
transform: null,
// if transform is set, this should be the inverse function
inverseTransform: null,
// either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks
ticks: null,
// number or [number, "unit"]
tickSize: null,
color: null, // base color, labels, ticks // number or [number, "unit"]
font: null, // null (derived from CSS in placeholder) or object like { size: 11, lineHeight: 13, style: "italic", weight: "bold", family: "sans-serif", variant: "small-caps" } minTickSize: null,
min: null, // min. value to show, null means set automatically // fn: number -> string
max: null, // max. value to show, null means set automatically tickFormatter: null,
autoscaleMargin: null, // margin in % to add if auto-setting min/max
transform: null, // null or f: number -> number to transform axis // no. of decimals, null means auto
inverseTransform: null, // if transform is set, this should be the inverse function tickDecimals: null,
ticks: null, // either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks // possibly different color of ticks, e.g. "rgba(0,0,0,0.15)"
tickSize: null, // number or [number, "unit"] tickColor: null,
minTickSize: null, // number or [number, "unit"]
tickFormatter: null, // fn: number -> string
tickDecimals: null, // no. of decimals, null means auto
tickColor: null, // possibly different color of ticks, e.g. "rgba(0,0,0,0.15)" // size in pixels of ticks, or "full" for whole line
tickLength: null, // size in pixels of ticks, or "full" for whole line tickLength: null,
tickWidth: null, // width of tick labels in pixels // width of tick labels in pixels
tickHeight: null, // height of tick labels in pixels tickWidth: null,
tickFont: null, // null or font-spec object (see font, above)
label: null, // null or an axis label string // height of tick labels in pixels
labelFont: null, // null or font-spec object (see font, above) tickHeight: null,
labelPadding: 2, // spacing between the axis and its label
reserveSpace: null, // whether to reserve space even if axis isn't shown // null or font-spec object (see font, above)
alignTicksWithAxis: null // axis number or null for no sync tickFont: null,
// null or an axis label string
label: null,
// null or font-spec object (see font, above)
labelFont: null,
// spacing between the axis and its label
labelPadding: 2,
// whether to reserve space even if axis isn't shown
reserveSpace: null,
// axis number or null for no sync
alignTicksWithAxis: null
}, },
yaxis: { yaxis: {
position: "left", // or "right"
// also accepts "right"
position: "left",
autoscaleMargin: 0.02, autoscaleMargin: 0.02,
labelPadding: 2 labelPadding: 2
}, },
...@@ -663,29 +714,46 @@ Licensed under the MIT license. ...@@ -663,29 +714,46 @@ Licensed under the MIT license.
points: { points: {
show: false, show: false,
radius: 3, radius: 3,
lineWidth: 2, // in pixels
// value in pixels
lineWidth: 2,
fill: true, fill: true,
fillColor: "#ffffff", fillColor: "#ffffff",
strokeColor: null, strokeColor: null,
symbol: "circle" // or callback
// type or callback
symbol: "circle"
}, },
lines: { lines: {
// we don't put in show: false so we can see // we don't put in show: false so we can see
// whether lines were actively disabled // whether lines were actively disabled
lineWidth: 2, // in pixels
// value in pixels
lineWidth: 2,
fill: false, fill: false,
fillColor: null, fillColor: null,
steps: false steps: false
// Omit 'zero', so we can later default its value to // Omit 'zero', so we can later default its value to
// match that of the 'fill' option. // match that of the 'fill' option.
}, },
bars: { bars: {
show: false, show: false,
lineWidth: 2, // in pixels
barWidth: 1, // in units of the x axis // in pixels
lineWidth: 2,
// in units of the x axis
barWidth: 1,
fill: true, fill: true,
fillColor: null, fillColor: null,
align: "left", // "left", "right", or "center"
// "left", "right", or "center"
align: "left",
horizontal: false, horizontal: false,
zero: true zero: true
}, },
...@@ -695,36 +763,77 @@ Licensed under the MIT license. ...@@ -695,36 +763,77 @@ Licensed under the MIT license.
grid: { grid: {
show: true, show: true,
aboveData: false, aboveData: false,
color: "#545454", // primary color used for outline and labels
backgroundColor: null, // null for transparent, else color // primary color used for outline and labels
borderColor: null, // set if different from the grid color color: "#545454",
tickColor: null, // color for the ticks, e.g. "rgba(0,0,0,0.15)"
margin: 0, // distance from the canvas edge to the grid // null for transparent, else color
labelMargin: 5, // in pixels backgroundColor: null,
axisMargin: 8, // in pixels
borderWidth: 2, // in pixels // set if different from the grid color
minBorderMargin: null, // in pixels, null means taken from points radius borderColor: null,
markings: null, // array of ranges or fn: axes -> array of ranges
// color for the ticks, e.g. "rgba(0,0,0,0.15)"
tickColor: null,
// distance from the canvas edge to the grid
margin: 0,
// value in pixels
labelMargin: 5,
// value in pixels
axisMargin: 8,
// value in pixels
borderWidth: 2,
// value in pixels, null means taken from points radius
minBorderMargin: null,
// array of ranges or fn: axes -> array of ranges
markings: null,
markingsColor: "#f4f4f4", markingsColor: "#f4f4f4",
markingsLineWidth: 2, markingsLineWidth: 2,
// interactive stuff // interactive stuff
clickable: false, clickable: false,
hoverable: false, hoverable: false,
autoHighlight: true, // highlight in case mouse is near
mouseActiveRadius: 10 // how far the mouse can be away to activate an item // highlight in case mouse is near
autoHighlight: true,
// how far the mouse can be away to activate an item
mouseActiveRadius: 10
}, },
interaction: { interaction: {
redrawOverlayInterval: 1000 / 60 // time between updates, -1 means in same flow
// time between updates, -1 means in same flow
redrawOverlayInterval: 1000 / 60
}, },
hooks: {} hooks: {}
}, },
surface = null, // the canvas for the plot itself
overlay = null, // canvas for interactive stuff on top of plot // the canvas for the plot itself
eventHolder = null, // jQuery object that events should be bound to surface = null,
ctx = null, octx = null,
xaxes = [], yaxes = [], // canvas for interactive stuff on top of plot
plotOffset = { left: 0, right: 0, top: 0, bottom: 0 }, overlay = null,
plotWidth = 0, plotHeight = 0,
// jQuery object that events should be bound to
eventHolder = null,
ctx = null,
octx = null,
xaxes = [],
yaxes = [],
plotOffset = {
left: 0,
right: 0,
top: 0,
bottom: 0
},
plotWidth = 0,
plotHeight = 0,
hooks = { hooks = {
processOptions: [], processOptions: [],
processRawData: [], processRawData: [],
...@@ -825,7 +934,6 @@ Licensed under the MIT license. ...@@ -825,7 +934,6 @@ Licensed under the MIT license.
function initPlugins() { function initPlugins() {
// References to key classes, allowing plugins to modify them // References to key classes, allowing plugins to modify them
var classes = { var classes = {
Canvas: Canvas Canvas: Canvas
}; };
...@@ -847,7 +955,6 @@ Licensed under the MIT license. ...@@ -847,7 +955,6 @@ Licensed under the MIT license.
// colors are provided than the size of the default palette, we // colors are provided than the size of the default palette, we
// end up with those colors plus the remaining defaults, which is // end up with those colors plus the remaining defaults, which is
// not expected behavior; avoid it by replacing them here. // not expected behavior; avoid it by replacing them here.
if (opts && opts.colors) { if (opts && opts.colors) {
options.colors = opts.colors; options.colors = opts.colors;
} }
...@@ -859,10 +966,14 @@ Licensed under the MIT license. ...@@ -859,10 +966,14 @@ Licensed under the MIT license.
options.yaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString(); options.yaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString();
} }
if (options.xaxis.tickColor == null) { // grid.tickColor for back-compatibility if (options.xaxis.tickColor == null) {
// grid.tickColor for back-compatibility
options.xaxis.tickColor = options.grid.tickColor || options.xaxis.color; options.xaxis.tickColor = options.grid.tickColor || options.xaxis.color;
} }
if (options.yaxis.tickColor == null) { // grid.tickColor for back-compatibility if (options.yaxis.tickColor == null) {
// grid.tickColor for back-compatibility
options.yaxis.tickColor = options.grid.tickColor || options.yaxis.color; options.yaxis.tickColor = options.grid.tickColor || options.yaxis.color;
} }
...@@ -878,7 +989,6 @@ Licensed under the MIT license. ...@@ -878,7 +989,6 @@ Licensed under the MIT license.
// If no x/y axis options were provided, create one of each anyway, // If no x/y axis options were provided, create one of each anyway,
// since the rest of the code assumes that they exist. // since the rest of the code assumes that they exist.
var i, axisOptions, axisCount, var i, axisOptions, axisCount,
fontSize = placeholder.css("font-size"), fontSize = placeholder.css("font-size"),
fontSizeDefault = fontSize ? +fontSize.replace("px", "") : 13, fontSizeDefault = fontSize ? +fontSize.replace("px", "") : 13,
...@@ -900,7 +1010,6 @@ Licensed under the MIT license. ...@@ -900,7 +1010,6 @@ Licensed under the MIT license.
} }
// Compatibility with markrcote/flot-axislabels // Compatibility with markrcote/flot-axislabels
if (axisOptions) { if (axisOptions) {
if (!axisOptions.label && axisOptions.axisLabel) { if (!axisOptions.label && axisOptions.axisLabel) {
axisOptions.label = axisOptions.axisLabel; axisOptions.label = axisOptions.axisLabel;
...@@ -953,7 +1062,6 @@ Licensed under the MIT license. ...@@ -953,7 +1062,6 @@ Licensed under the MIT license.
} }
// Compatibility with markrcote/flot-axislabels // Compatibility with markrcote/flot-axislabels
if (axisOptions) { if (axisOptions) {
if (!axisOptions.label && axisOptions.axisLabel) { if (!axisOptions.label && axisOptions.axisLabel) {
axisOptions.label = axisOptions.axisLabel; axisOptions.label = axisOptions.axisLabel;
...@@ -1074,7 +1182,9 @@ Licensed under the MIT license. ...@@ -1074,7 +1182,9 @@ Licensed under the MIT license.
var s = $.extend(true, {}, options.series); var s = $.extend(true, {}, options.series);
if (d[i].data != null) { if (d[i].data != null) {
s.data = d[i].data; // move the data instead of deep-copy
// move the data instead of deep-copy
s.data = d[i].data;
delete d[i].data; delete d[i].data;
$.extend(true, s, d[i]); $.extend(true, s, d[i]);
...@@ -1091,21 +1201,28 @@ Licensed under the MIT license. ...@@ -1091,21 +1201,28 @@ Licensed under the MIT license.
function axisNumber(obj, coord) { function axisNumber(obj, coord) {
var a = obj[coord + "axis"]; var a = obj[coord + "axis"];
if (typeof a === "object") { // if we got a real axis, extract number
if (typeof a === "object") {
// if we got a real axis, extract number
a = a.n; a = a.n;
} }
if (!isNumeric(a)) { if (!isNumeric(a)) {
a = 1; // default to first axis
// default to first axis
a = 1;
} }
return a; return a;
} }
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) {
// return an object with x/y corresponding to all used axes // return an object with x/y corresponding to all used axes
var res = {}, i, axis; var res = {}, i, axis;
for (i = 0; i < xaxes.length; ++i) { for (i = 0; i < xaxes.length; ++i) {
...@@ -1133,6 +1250,7 @@ Licensed under the MIT license. ...@@ -1133,6 +1250,7 @@ Licensed under the MIT license.
} }
function axisToCanvasCoords(pos) { function axisToCanvasCoords(pos) {
// get canvas coords from the first pair of x/y found in pos // get canvas coords from the first pair of x/y found in pos
var res = {}, i, axis, key; var res = {}, i, axis, key;
...@@ -1172,7 +1290,9 @@ Licensed under the MIT license. ...@@ -1172,7 +1290,9 @@ Licensed under the MIT license.
function getOrCreateAxis(axes, number) { function getOrCreateAxis(axes, number) {
if (!axes[number - 1]) { if (!axes[number - 1]) {
axes[number - 1] = { axes[number - 1] = {
n: number, // save the number for future reference
// save the number for future reference
n: number,
direction: axes === xaxes ? "x" : "y", direction: axes === xaxes ? "x" : "y",
options: $.extend(true, {}, axes === xaxes ? options.xaxis : options.yaxis) options: $.extend(true, {}, axes === xaxes ? options.xaxis : options.yaxis)
}; };
...@@ -1187,7 +1307,6 @@ Licensed under the MIT license. ...@@ -1187,7 +1307,6 @@ Licensed under the MIT license.
// Subtract the number of series that already have fixed colors or // Subtract the number of series that already have fixed colors or
// color indexes from the number that we still need to generate. // color indexes from the number that we still need to generate.
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
var sc = series[i].color; var sc = series[i].color;
if (sc != null) { if (sc != null) {
...@@ -1200,14 +1319,12 @@ Licensed under the MIT license. ...@@ -1200,14 +1319,12 @@ Licensed under the MIT license.
// If any of the series have fixed color indexes, then we need to // If any of the series have fixed color indexes, then we need to
// generate at least as many colors as the highest index. // generate at least as many colors as the highest index.
if (neededColors <= maxIndex) { if (neededColors <= maxIndex) {
neededColors = maxIndex + 1; neededColors = maxIndex + 1;
} }
// Generate all the colors, using first the option colors and then // Generate all the colors, using first the option colors and then
// variations on those colors once they're exhausted. // variations on those colors once they're exhausted.
var c, colors = [], colorPool = options.colors, var c, colors = [], colorPool = options.colors,
colorPoolSize = colorPool.length, variation = 0; colorPoolSize = colorPool.length, variation = 0;
...@@ -1222,7 +1339,6 @@ Licensed under the MIT license. ...@@ -1222,7 +1339,6 @@ Licensed under the MIT license.
// Reset the variation after every few cycles, or else // Reset the variation after every few cycles, or else
// it will end up producing only white or black colors. // it will end up producing only white or black colors.
if (i % colorPoolSize === 0 && i) { if (i % colorPoolSize === 0 && i) {
if (variation >= 0) { if (variation >= 0) {
if (variation < 0.5) { if (variation < 0.5) {
...@@ -1239,7 +1355,6 @@ Licensed under the MIT license. ...@@ -1239,7 +1355,6 @@ Licensed under the MIT license.
} }
// Finalize the series options, filling in their colors // Finalize the series options, filling in their colors
var colori = 0, s; var colori = 0, s;
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
...@@ -1268,7 +1383,6 @@ Licensed under the MIT license. ...@@ -1268,7 +1383,6 @@ Licensed under the MIT license.
// If nothing was provided for lines.zero, default it to match // If nothing was provided for lines.zero, default it to match
// lines.fill, since areas by default should extend to zero. // lines.fill, since areas by default should extend to zero.
if (s.lines.zero == null) { if (s.lines.zero == null) {
s.lines.zero = !!s.lines.fill; s.lines.zero = !!s.lines.fill;
} }
...@@ -1295,6 +1409,7 @@ Licensed under the MIT license. ...@@ -1295,6 +1409,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;
...@@ -1316,6 +1431,7 @@ Licensed under the MIT license. ...@@ -1316,6 +1431,7 @@ Licensed under the MIT license.
if (!format) { if (!format) {
format = []; format = [];
// find out how to copy // find out how to copy
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
format.push({ y: true, number: true, required: true }); format.push({ y: true, number: true, required: true });
...@@ -1333,7 +1449,9 @@ Licensed under the MIT license. ...@@ -1333,7 +1449,9 @@ Licensed under the MIT license.
} }
if (s.datapoints.pointsize != null) { if (s.datapoints.pointsize != null) {
continue; // already filled in
// already filled in
continue;
} }
s.datapoints.pointsize = format.length; s.datapoints.pointsize = format.length;
...@@ -1354,7 +1472,9 @@ Licensed under the MIT license. ...@@ -1354,7 +1472,9 @@ Licensed under the MIT license.
if (f) { if (f) {
if (f.number && val != null) { if (f.number && val != null) {
val = +val; // convert to number
// convert to number
val = +val;
if (isNaN(val)) { if (isNaN(val)) {
val = null; val = null;
} else if (val === Infinity) { } else if (val === Infinity) {
...@@ -1384,6 +1504,7 @@ Licensed under the MIT license. ...@@ -1384,6 +1504,7 @@ Licensed under the MIT license.
val = points[k + m]; val = points[k + m];
if (val != null) { if (val != null) {
f = format[m]; f = format[m];
// extract min/max info // extract min/max info
if (f.autoscale !== false) { if (f.autoscale !== false) {
if (f.x) { if (f.x) {
...@@ -1449,6 +1570,7 @@ Licensed under the MIT license. ...@@ -1449,6 +1570,7 @@ Licensed under the MIT license.
} }
if (s.bars.show) { if (s.bars.show) {
// make sure we got room for the bar on the dancing floor // make sure we got room for the bar on the dancing floor
var delta; var delta;
...@@ -1491,17 +1613,22 @@ Licensed under the MIT license. ...@@ -1491,17 +1613,22 @@ Licensed under the MIT license.
// Make sure the placeholder is clear of everything except canvases // Make sure the placeholder is clear of everything except canvases
// from a previous plot in this container that we'll try to re-use. // from a previous plot in this container that we'll try to re-use.
placeholder.css("padding", 0) // padding messes up the positioning // padding messes up the positioning
placeholder.css("padding", 0)
.children().filter(function() { .children().filter(function() {
return !$(this).hasClass("flot-overlay") && !$(this).hasClass("flot-base"); return !$(this).hasClass("flot-overlay") && !$(this).hasClass("flot-base");
}).remove(); }).remove();
if (placeholder.css("position") === "static") { if (placeholder.css("position") === "static") {
placeholder.css("position", "relative"); // for positioning labels and overlay
// for positioning labels and overlay
placeholder.css("position", "relative");
} }
surface = new Canvas("flot-base", placeholder); surface = new Canvas("flot-base", placeholder);
overlay = new Canvas("flot-overlay", placeholder); // overlay canvas for interactive features
// overlay canvas for interactive features
overlay = new Canvas("flot-overlay", placeholder);
ctx = surface.context; ctx = surface.context;
octx = overlay.context; octx = overlay.context;
...@@ -1510,7 +1637,6 @@ Licensed under the MIT license. ...@@ -1510,7 +1637,6 @@ Licensed under the MIT license.
eventHolder = $(overlay.element).unbind(); eventHolder = $(overlay.element).unbind();
// If we're re-using a plot object, shut down the old one // If we're re-using a plot object, shut down the old one
var existing = placeholder.data("plot"); var existing = placeholder.data("plot");
if (existing) { if (existing) {
...@@ -1523,6 +1649,7 @@ Licensed under the MIT license. ...@@ -1523,6 +1649,7 @@ Licensed under the MIT license.
} }
function bindEvents() { function bindEvents() {
// bind events // bind events
if (options.grid.hoverable) { if (options.grid.hoverable) {
eventHolder.mousemove(onMouseMove); eventHolder.mousemove(onMouseMove);
...@@ -1532,7 +1659,6 @@ Licensed under the MIT license. ...@@ -1532,7 +1659,6 @@ Licensed under the MIT license.
// for mouseenter or mouseleave. This was a bug/oversight that // for mouseenter or mouseleave. This was a bug/oversight that
// was fixed somewhere around 1.3.x. We can return to using // was fixed somewhere around 1.3.x. We can return to using
// .mouseleave when we drop support for 1.2.6. // .mouseleave when we drop support for 1.2.6.
eventHolder.bind("mouseleave", onMouseLeave); eventHolder.bind("mouseleave", onMouseLeave);
} }
...@@ -1556,9 +1682,9 @@ Licensed under the MIT license. ...@@ -1556,9 +1682,9 @@ Licensed under the MIT license.
} }
function setTransformationHelpers(axis) { function setTransformationHelpers(axis) {
// set helper functions on the axis, assumes plot area // set helper functions on the axis, assumes plot area
// has been computed already // has been computed already
function identity(x) { return x; } function identity(x) { return x; }
var s, m, t = axis.options.transform || identity, var s, m, t = axis.options.transform || identity,
...@@ -1576,11 +1702,14 @@ Licensed under the MIT license. ...@@ -1576,11 +1702,14 @@ 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; };
...@@ -1593,6 +1722,7 @@ Licensed under the MIT license. ...@@ -1593,6 +1722,7 @@ Licensed under the MIT license.
var opts = axis.options, var opts = axis.options,
ticks = axis.ticks || [], ticks = axis.ticks || [],
// Label width & height are deprecated; remove in 1.0! // Label width & height are deprecated; remove in 1.0!
tickWidth = opts.tickWidth || opts.labelWidth || 0, tickWidth = opts.tickWidth || opts.labelWidth || 0,
tickHeight = opts.tickHeight || opts.labelHeight || 0, tickHeight = opts.tickHeight || opts.labelHeight || 0,
...@@ -1619,18 +1749,17 @@ Licensed under the MIT license. ...@@ -1619,18 +1749,17 @@ Licensed under the MIT license.
axis.tickHeight = opts.tickHeight || opts.labelHeight || tickHeight; axis.tickHeight = opts.tickHeight || opts.labelHeight || tickHeight;
// Label width/height properties are deprecated; remove in 1.0! // Label width/height properties are deprecated; remove in 1.0!
axis.labelWidth = axis.tickWidth; axis.labelWidth = axis.tickWidth;
axis.labelHeight = axis.tickHeight; axis.labelHeight = axis.tickHeight;
} }
/////////////////////////////////////////////////////////////////////// /**
// Compute the axis bounding box based on the dimensions of its label * Compute the axis bounding box based on the dimensions of its label
// and tick labels, then adjust the plotOffset to make room for it. * and tick labels, then adjust the plotOffset to make room for it.
// *
// This first phase only considers one dimension per axis; the other * This first phase only considers one dimension per axis; the other
// dimension depends on the other axes, and will be calculated later. * dimension depends on the other axes, and will be calculated later.
*/
function allocateAxisBoxFirstPhase(axis) { function allocateAxisBoxFirstPhase(axis) {
var contentWidth = axis.tickWidth, var contentWidth = axis.tickWidth,
...@@ -1647,7 +1776,6 @@ Licensed under the MIT license. ...@@ -1647,7 +1776,6 @@ Licensed under the MIT license.
found = false; found = false;
// Determine the axis's position in its direction and on its side // Determine the axis's position in its direction and on its side
$.each(isXAxis ? xaxes : yaxes, function(i, a) { $.each(isXAxis ? xaxes : yaxes, function(i, a) {
if (a && a.reserveSpace) { if (a && a.reserveSpace) {
if (a === axis) { if (a === axis) {
...@@ -1666,13 +1794,11 @@ Licensed under the MIT license. ...@@ -1666,13 +1794,11 @@ Licensed under the MIT license.
}); });
// The outermost axis on each side has no margin // The outermost axis on each side has no margin
if (outermost) { if (outermost) {
axisMargin = 0; axisMargin = 0;
} }
// The ticks for the first axis in each direction stretch across // The ticks for the first axis in each direction stretch across
if (tickLength == null) { if (tickLength == null) {
tickLength = first ? "full" : 5; tickLength = first ? "full" : 5;
} }
...@@ -1682,7 +1808,6 @@ Licensed under the MIT license. ...@@ -1682,7 +1808,6 @@ Licensed under the MIT license.
} }
// Measure the dimensions of the axis label, if it has one // Measure the dimensions of the axis label, if it has one
if (axisOptions.label) { if (axisOptions.label) {
var legacyStyles = "Axis " + axis.direction + axis.n + "Axis", var legacyStyles = "Axis " + axis.direction + axis.n + "Axis",
layer = "flot-" + axis.direction + "-axis flot-" + axis.direction + axis.n + "-axis " + axis.direction + legacyStyles, layer = "flot-" + axis.direction + "-axis flot-" + axis.direction + axis.n + "-axis " + axis.direction + legacyStyles,
...@@ -1694,7 +1819,6 @@ Licensed under the MIT license. ...@@ -1694,7 +1819,6 @@ Licensed under the MIT license.
} }
// Compute the axis bounding box and update the plot bounds // Compute the axis bounding box and update the plot bounds
if (isXAxis) { if (isXAxis) {
contentHeight += padding; contentHeight += padding;
if (axisPosition === "top") { if (axisPosition === "top") {
...@@ -1722,6 +1846,7 @@ Licensed under the MIT license. ...@@ -1722,6 +1846,7 @@ Licensed under the MIT license.
} }
function allocateAxisBoxSecondPhase(axis) { function allocateAxisBoxSecondPhase(axis) {
// now that all axis boxes have been placed in one // now that all axis boxes have been placed in one
// dimension, we can set the remaining dimension coordinates // dimension, we can set the remaining dimension coordinates
if (axis.direction === "x") { if (axis.direction === "x") {
...@@ -1734,9 +1859,9 @@ Licensed under the MIT license. ...@@ -1734,9 +1859,9 @@ Licensed under the MIT license.
} }
function adjustLayoutForThingsStickingOut() { function adjustLayoutForThingsStickingOut() {
// possibly adjust plot offset to ensure everything stays // possibly adjust plot offset to ensure everything stays
// inside the canvas and isn't clipped off // inside the canvas and isn't clipped off
var minMargin = options.grid.minBorderMargin; var minMargin = options.grid.minBorderMargin;
// check stuff from the plot (FIXME: this should just read // check stuff from the plot (FIXME: this should just read
...@@ -1789,7 +1914,6 @@ Licensed under the MIT license. ...@@ -1789,7 +1914,6 @@ Licensed under the MIT license.
i, a; i, a;
// Initialize the plot's offset from the edge of the canvas // Initialize the plot's offset from the edge of the canvas
for (a in plotOffset) { for (a in plotOffset) {
if (Object.prototype.hasOwnProperty.call(plotOffset, a)) { if (Object.prototype.hasOwnProperty.call(plotOffset, a)) {
plotOffset[a] = isNumeric(margin) ? margin : margin[a] || 0; plotOffset[a] = isNumeric(margin) ? margin : margin[a] || 0;
...@@ -1799,7 +1923,6 @@ Licensed under the MIT license. ...@@ -1799,7 +1923,6 @@ Licensed under the MIT license.
executeHooks(hooks.processOffset, [plotOffset]); executeHooks(hooks.processOffset, [plotOffset]);
// If the grid is visible, add its border width to the offset // If the grid is visible, add its border width to the offset
for (a in plotOffset) { for (a in plotOffset) {
if (typeof(options.grid.borderWidth) === "object") { if (typeof(options.grid.borderWidth) === "object") {
plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0; plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0;
...@@ -1812,7 +1935,9 @@ Licensed under the MIT license. ...@@ -1812,7 +1935,9 @@ Licensed under the MIT license.
$.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
// by default an axis is visible if it's got data
axis.show = axis.used;
} }
axis.reserveSpace = axis.show || axis.options.reserveSpace; axis.reserveSpace = axis.show || axis.options.reserveSpace;
...@@ -1825,6 +1950,7 @@ Licensed under the MIT license. ...@@ -1825,6 +1950,7 @@ Licensed under the MIT license.
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);
...@@ -1870,23 +1996,28 @@ Licensed under the MIT license. ...@@ -1870,23 +1996,28 @@ Licensed under the MIT license.
delta = max - min; delta = max - min;
if (delta === 0.0) { if (delta === 0.0) {
// degenerate case // degenerate case
var widen = max === 0 ? 1 : 0.01; var widen = max === 0 ? 1 : 0.01;
if (opts.min == null) { if (opts.min == null) {
min -= widen; min -= widen;
} }
// always widen max if we couldn't widen min to ensure we // always widen max if we couldn't widen min to ensure we
// don't fall into min == max which doesn't work // don't fall into min == max which doesn't work
if (opts.max == null || opts.min != null) { if (opts.max == null || opts.min != null) {
max += widen; max += widen;
} }
} else { } else {
// consider autoscaling // consider autoscaling
var margin = opts.autoscaleMargin; var margin = opts.autoscaleMargin;
if (margin != null) { if (margin != null) {
if (opts.min == null) { if (opts.min == null) {
min -= delta * margin; min -= delta * margin;
// make sure we don't go below zero if all values // make sure we don't go below zero if all values
// are positive // are positive
if (min < 0 && axis.datamin != null && axis.datamin >= 0) { if (min < 0 && axis.datamin != null && axis.datamin >= 0) {
...@@ -1909,12 +2040,12 @@ Licensed under the MIT license. ...@@ -1909,12 +2040,12 @@ Licensed under the MIT license.
var opts = axis.options, var opts = axis.options,
// estimate number of ticks // estimate number of ticks
noTicks; noTicks;
if (isNumeric(opts.ticks) && opts.ticks > 0) { if (isNumeric(opts.ticks) && opts.ticks > 0) {
noTicks = opts.ticks; noTicks = opts.ticks;
} else { } else {
// heuristic based on the model a*sqrt(x) fitted to // heuristic based on the model a*sqrt(x) fitted to
// some data points that seemed reasonable // some data points that seemed reasonable
noTicks = 0.3 * Math.sqrt(axis.direction === "x" ? surface.width : surface.height); noTicks = 0.3 * Math.sqrt(axis.direction === "x" ? surface.width : surface.height);
...@@ -1929,13 +2060,16 @@ Licensed under the MIT license. ...@@ -1929,13 +2060,16 @@ Licensed under the MIT license.
} }
var magn = Math.pow(10, -dec), var magn = Math.pow(10, -dec),
norm = delta / magn, // norm is between 1.0 and 10.0
// norm is between 1.0 and 10.0
norm = delta / magn,
size; size;
if (norm < 1.5) { if (norm < 1.5) {
size = 1; size = 1;
} else if (norm < 3) { } else if (norm < 3) {
size = 2; size = 2;
// special case for 2.5, requires an extra decimal // special case for 2.5, requires an extra decimal
if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) { if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) {
size = 2.5; size = 2.5;
...@@ -1959,14 +2093,12 @@ Licensed under the MIT license. ...@@ -1959,14 +2093,12 @@ Licensed under the MIT license.
// Time mode was moved to a plug-in in 0.8, but since so many people use this // Time mode was moved to a plug-in in 0.8, but since so many people use this
// we'll add an especially friendly make sure they remembered to include it. // we'll add an especially friendly make sure they remembered to include it.
if (opts.mode === "time" && !axis.tickGenerator) { if (opts.mode === "time" && !axis.tickGenerator) {
throw new Error("Time mode requires the flot.time plugin."); throw new Error("Time mode requires the flot.time plugin.");
} }
// Flot supports base-10 axes; any other mode else is handled by a plug-in, // Flot supports base-10 axes; any other mode else is handled by a plug-in,
// like flot.time.js. // like flot.time.js.
if (!axis.tickGenerator) { if (!axis.tickGenerator) {
axis.tickGenerator = function(axis) { axis.tickGenerator = function(axis) {
...@@ -1993,7 +2125,6 @@ Licensed under the MIT license. ...@@ -1993,7 +2125,6 @@ Licensed under the MIT license.
// 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("."),
precision = decimal === -1 ? 0 : formatted.length - decimal - 1; precision = decimal === -1 ? 0 : formatted.length - decimal - 1;
...@@ -2014,6 +2145,7 @@ Licensed under the MIT license. ...@@ -2014,6 +2145,7 @@ Licensed under the MIT license.
if (opts.alignTicksWithAxis != null) { if (opts.alignTicksWithAxis != null) {
var otherAxis = (axis.direction === "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1]; var otherAxis = (axis.direction === "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1];
if (otherAxis && otherAxis.used && otherAxis !== axis) { if (otherAxis && otherAxis.used && otherAxis !== axis) {
// consider snapping min/max to outermost nice ticks // consider snapping min/max to outermost nice ticks
var niceTicks = axis.tickGenerator(axis); var niceTicks = axis.tickGenerator(axis);
if (niceTicks.length > 0) { if (niceTicks.length > 0) {
...@@ -2026,6 +2158,7 @@ Licensed under the MIT license. ...@@ -2026,6 +2158,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) {
...@@ -2059,6 +2192,7 @@ Licensed under the MIT license. ...@@ -2059,6 +2192,7 @@ Licensed under the MIT license.
ticks = axis.tickGenerator(axis); ticks = axis.tickGenerator(axis);
} else if (oticks) { } else if (oticks) {
if ($.isFunction(oticks)) { if ($.isFunction(oticks)) {
// generate the ticks // generate the ticks
ticks = oticks(axis); ticks = oticks(axis);
} else { } else {
...@@ -2092,6 +2226,7 @@ Licensed under the MIT license. ...@@ -2092,6 +2226,7 @@ Licensed under the MIT license.
function snapRangeToTicks(axis, ticks) { function snapRangeToTicks(axis, ticks) {
if (axis.options.autoscaleMargin && ticks.length > 0) { if (axis.options.autoscaleMargin && ticks.length > 0) {
// snap to ticks // snap to ticks
if (axis.options.min == null) { if (axis.options.min == null) {
axis.min = Math.min(axis.min, ticks[0].v); axis.min = Math.min(axis.min, ticks[0].v);
...@@ -2146,7 +2281,9 @@ Licensed under the MIT license. ...@@ -2146,7 +2281,9 @@ Licensed under the MIT license.
if (axis.direction === coord) { if (axis.direction === coord) {
key = coord + axis.n + "axis"; key = coord + axis.n + "axis";
if (!ranges[key] && axis.n === 1) { if (!ranges[key] && axis.n === 1) {
key = coord + "axis"; // support x1axis as xaxis
// support x1axis as xaxis
key = coord + "axis";
} }
if (ranges[key]) { if (ranges[key]) {
from = ranges[key].from; from = ranges[key].from;
...@@ -2199,6 +2336,7 @@ Licensed under the MIT license. ...@@ -2199,6 +2336,7 @@ Licensed under the MIT license.
if (markings) { if (markings) {
if ($.isFunction(markings)) { if ($.isFunction(markings)) {
axes = plot.getAxes(); axes = plot.getAxes();
// xmin etc. is backwards compatibility, to be // xmin etc. is backwards compatibility, to be
// removed in the future // removed in the future
axes.xmin = axes.xaxis.min; axes.xmin = axes.xaxis.min;
...@@ -2277,7 +2415,6 @@ Licensed under the MIT license. ...@@ -2277,7 +2415,6 @@ Licensed under the MIT license.
} }
// draw ticks // draw ticks
ctx.strokeStyle = axis.options.tickColor; ctx.strokeStyle = axis.options.tickColor;
ctx.beginPath(); ctx.beginPath();
...@@ -2287,6 +2424,7 @@ Licensed under the MIT license. ...@@ -2287,6 +2424,7 @@ Licensed under the MIT license.
xoff = yoff = 0; xoff = yoff = 0;
if (isNaN(v) || v < axis.min || v > axis.max || ( if (isNaN(v) || v < axis.min || v > axis.max || (
// skip those lying on the axes if we got a border // skip those lying on the axes if we got a border
t === "full" && ((typeof bw === "object" && bw[axis.position] > 0) || bw > 0) && t === "full" && ((typeof bw === "object" && bw[axis.position] > 0) || bw > 0) &&
(v === axis.min || v === axis.max) (v === axis.min || v === axis.max)
...@@ -2329,6 +2467,7 @@ Licensed under the MIT license. ...@@ -2329,6 +2467,7 @@ Licensed under the MIT license.
// draw border // draw border
if (bw) { if (bw) {
// If either borderWidth or borderColor is an object, then draw the border // If either borderWidth or borderColor is an object, then draw the border
// line by line instead of as one rectangle // line by line instead of as one rectangle
bc = options.grid.borderColor; bc = options.grid.borderColor;
...@@ -2386,11 +2525,11 @@ Licensed under the MIT license. ...@@ -2386,11 +2525,11 @@ Licensed under the MIT license.
} }
function drawMarkings(markings, markingLayer) { function drawMarkings(markings, markingLayer) {
if (!markings) { if (!markings) {
return; return;
} }
for (var i = 0; i < markings.length; i++) { for (var i = 0; i < markings.length; i++) {
drawMarking(markings[i], markingLayer); drawMarking(markings[i], markingLayer);
} }
} }
...@@ -2432,6 +2571,7 @@ Licensed under the MIT license. ...@@ -2432,6 +2571,7 @@ Licensed under the MIT license.
if (xrange.from !== xrange.to || xrange.from !== yrange.to) { if (xrange.from !== xrange.to || xrange.from !== yrange.to) {
if (xrange.from === xrange.to || yrange.from === yrange.to) { if (xrange.from === xrange.to || yrange.from === yrange.to) {
// draw line // draw line
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = m.color || options.grid.markingsColor; ctx.strokeStyle = m.color || options.grid.markingsColor;
...@@ -2440,6 +2580,7 @@ Licensed under the MIT license. ...@@ -2440,6 +2580,7 @@ Licensed under the MIT license.
ctx.lineTo(xrange.to, yrange.to); ctx.lineTo(xrange.to, yrange.to);
ctx.stroke(); ctx.stroke();
} else { } else {
// fill area // fill area
ctx.fillStyle = m.color || options.grid.markingsColor; ctx.fillStyle = m.color || options.grid.markingsColor;
...@@ -2455,12 +2596,11 @@ Licensed under the MIT license. ...@@ -2455,12 +2596,11 @@ 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, var xPos = xrange.from + plotOffset.left,
// top baselined vertical position: // top baselined vertical position:
yPos = (yrange.to + plotOffset.top); yPos = (yrange.to + plotOffset.top);
if (!!m.textAlign) { if (!!m.textAlign) {
...@@ -2504,7 +2644,6 @@ Licensed under the MIT license. ...@@ -2504,7 +2644,6 @@ Licensed under the MIT license.
// Remove text before checking for axis.show and ticks.length; // Remove text before checking for axis.show and ticks.length;
// otherwise plugins, like flot-tickrotor, that draw their own // otherwise plugins, like flot-tickrotor, that draw their own
// tick labels will end up with both theirs and the defaults. // tick labels will end up with both theirs and the defaults.
surface.removeText(layer); surface.removeText(layer);
if (!axis.show || axis.ticks.length === 0) { if (!axis.show || axis.ticks.length === 0) {
...@@ -2528,7 +2667,6 @@ Licensed under the MIT license. ...@@ -2528,7 +2667,6 @@ Licensed under the MIT license.
} }
// Add labels for the ticks on this axis // Add labels for the ticks on this axis
for (var i = 0; i < axis.ticks.length; ++i) { for (var i = 0; i < axis.ticks.length; ++i) {
tick = axis.ticks[i]; tick = axis.ticks[i];
...@@ -2592,8 +2730,11 @@ Licensed under the MIT license. ...@@ -2592,8 +2730,11 @@ Licensed under the MIT license.
// clip with ymin // clip with ymin
if (y1 <= y2 && y1 < axisy.min) { if (y1 <= y2 && y1 < axisy.min) {
if (y2 < axisy.min) { if (y2 < axisy.min) {
continue; // line segment is outside
// line segment is outside
continue;
} }
// compute new intersection point // compute new intersection point
x1 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = showSteps ? x2 : (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.min; y1 = axisy.min;
...@@ -2656,6 +2797,7 @@ Licensed under the MIT license. ...@@ -2656,6 +2797,7 @@ Licensed under the MIT license.
prevx = x2; prevx = x2;
prevy = y2; prevy = y2;
// Draw a step // Draw a step
if (showSteps) { if (showSteps) {
if (x1 < x2) { if (x1 < x2) {
...@@ -2685,7 +2827,8 @@ Licensed under the MIT license. ...@@ -2685,7 +2827,8 @@ Licensed under the MIT license.
break; break;
} }
i += ps; // ps is negative if going backwards // ps is negative if going backwards
i += ps;
var x1 = points[i - ps], var x1 = points[i - ps],
y1 = points[i - ps + ypos], y1 = points[i - ps + ypos],
...@@ -2693,6 +2836,7 @@ Licensed under the MIT license. ...@@ -2693,6 +2836,7 @@ Licensed under the MIT license.
if (areaOpen) { if (areaOpen) {
if (ps > 0 && x1 != null && x2 == null) { if (ps > 0 && x1 != null && x2 == null) {
// at turning point // at turning point
segmentEnd = i; segmentEnd = i;
ps = -ps; ps = -ps;
...@@ -2701,6 +2845,7 @@ Licensed under the MIT license. ...@@ -2701,6 +2845,7 @@ Licensed under the MIT license.
} }
if (ps < 0 && i === segmentStart + ps) { if (ps < 0 && i === segmentStart + ps) {
// done with the reverse sweep // done with the reverse sweep
ctx.fill(); ctx.fill();
areaOpen = false; areaOpen = false;
...@@ -2748,6 +2893,7 @@ Licensed under the MIT license. ...@@ -2748,6 +2893,7 @@ Licensed under the MIT license.
} }
if (!areaOpen) { if (!areaOpen) {
// open area // open area
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom)); ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom));
...@@ -2792,17 +2938,18 @@ Licensed under the MIT license. ...@@ -2792,17 +2938,18 @@ Licensed under the MIT license.
y2 = axisy.max; y2 = axisy.max;
} }
// if the x value was changed we got a rectangle // if the x value was changed we got a rectangle to fill
// to fill
if (x1 !== x1old) { if (x1 !== x1old) {
ctx.lineTo(axisx.p2c(x1old), axisy.p2c(y1));
// it goes to (x1, y1), but we fill that below // it goes to (x1, y1), but we fill that below
ctx.lineTo(axisx.p2c(x1old), axisy.p2c(y1));
} }
// fill triangular section, this sometimes result // fill triangular section, this sometimes result
// in redundant points if (x1, y1) hasn't changed // in redundant points if (x1, y1) hasn't changed
// from previous line to, but we just ignore that // from previous line to, but we just ignore that
ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1)); ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1));
// Draw a step // Draw a step
if (showSteps) { if (showSteps) {
if (x1 < x2) { if (x1 < x2) {
...@@ -2827,11 +2974,14 @@ Licensed under the MIT license. ...@@ -2827,11 +2974,14 @@ Licensed under the MIT license.
var lw = series.lines.lineWidth, var lw = series.lines.lineWidth,
sw = series.shadowSize; sw = series.shadowSize;
// FIXME: consider another form of shadow when filling is turned on // FIXME: consider another form of shadow when filling is turned on
if (lw > 0 && sw > 0) { if (lw > 0 && sw > 0) {
// draw shadow as a thick and thin line with transparency // draw shadow as a thick and thin line with transparency
ctx.lineWidth = sw; ctx.lineWidth = sw;
ctx.strokeStyle = "rgba(0,0,0,0.1)"; ctx.strokeStyle = "rgba(0,0,0,0.1)";
// position shadow at angle from the mid of line // position shadow at angle from the mid of line
var angle = Math.PI / 18; var angle = Math.PI / 18;
plotLine(series.datapoints, Math.sin(angle) * (lw / 2 + sw / 2), Math.cos(angle) * (lw / 2 + sw / 2), series.xaxis, series.yaxis); plotLine(series.datapoints, Math.sin(angle) * (lw / 2 + sw / 2), Math.cos(angle) * (lw / 2 + sw / 2), series.xaxis, series.yaxis);
...@@ -2893,12 +3043,12 @@ Licensed under the MIT license. ...@@ -2893,12 +3043,12 @@ Licensed under the MIT license.
// small value. A line width of 0 seems to force the default of 1. // small value. A line width of 0 seems to force the default of 1.
// Doing the conditional here allows the shadow setting to still be // Doing the conditional here allows the shadow setting to still be
// optional even with a lineWidth of 0. // optional even with a lineWidth of 0.
if (lw === 0) { if (lw === 0) {
lw = 0.0001; lw = 0.0001;
} }
if (lw > 0 && sw > 0) { if (lw > 0 && sw > 0) {
// draw shadow in two steps // draw shadow in two steps
var w = sw / 2; var w = sw / 2;
ctx.lineWidth = w; ctx.lineWidth = w;
...@@ -3096,7 +3246,6 @@ Licensed under the MIT license. ...@@ -3096,7 +3246,6 @@ Licensed under the MIT license.
var entries = [], lf = options.legend.labelFormatter, s, label, i; var entries = [], lf = options.legend.labelFormatter, s, label, i;
// Build a list of legend entries, with each having a label and a color // Build a list of legend entries, with each having a label and a color
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
if (s.label) { if (s.label) {
...@@ -3111,13 +3260,11 @@ Licensed under the MIT license. ...@@ -3111,13 +3260,11 @@ Licensed under the MIT license.
} }
// No entries implies no legend // No entries implies no legend
if (entries.length === 0) { if (entries.length === 0) {
return; return;
} }
// Sort the legend using either the default or a custom comparator // Sort the legend using either the default or a custom comparator
if (options.legend.sorted) { if (options.legend.sorted) {
if ($.isFunction(options.legend.sorted)) { if ($.isFunction(options.legend.sorted)) {
entries.sort(options.legend.sorted); entries.sort(options.legend.sorted);
...@@ -3134,7 +3281,6 @@ Licensed under the MIT license. ...@@ -3134,7 +3281,6 @@ Licensed under the MIT license.
} }
// Generate markup for the list of entries, in their final order // Generate markup for the list of entries, in their final order
var table = $("<table></table>").css({ var table = $("<table></table>").css({
"font-size": "smaller", "font-size": "smaller",
"color": options.grid.color "color": options.grid.color
...@@ -3192,6 +3338,7 @@ Licensed under the MIT license. ...@@ -3192,6 +3338,7 @@ Licensed under the MIT license.
} }
var legend = $("<div></div>").addClass("legend").append(table.css(pos)).appendTo(placeholder); var legend = $("<div></div>").addClass("legend").append(table.css(pos)).appendTo(placeholder);
if (options.legend.backgroundOpacity !== 0.0) { if (options.legend.backgroundOpacity !== 0.0) {
// put in the transparent background // put in the transparent background
// separately to avoid blended labels and // separately to avoid blended labels and
// label boxes // label boxes
...@@ -3220,11 +3367,12 @@ Licensed under the MIT license. ...@@ -3220,11 +3367,12 @@ Licensed under the MIT license.
} }
// interactive features // interactive features
var highlights = [], var highlights = [],
redrawTimeout = null; redrawTimeout = null;
// returns the data item the mouse is over, or null if none is found /**
* returns the data item the mouse is over, or null if none is found
*/
function findNearbyItem(mouseX, mouseY, seriesFilter) { function findNearbyItem(mouseX, mouseY, seriesFilter) {
var maxDistance = options.grid.mouseActiveRadius, var maxDistance = options.grid.mouseActiveRadius,
smallestDistance = maxDistance * maxDistance + 1, smallestDistance = maxDistance * maxDistance + 1,
...@@ -3239,13 +3387,16 @@ Licensed under the MIT license. ...@@ -3239,13 +3387,16 @@ Licensed under the MIT license.
axisx = s.xaxis, axisx = s.xaxis,
axisy = s.yaxis, axisy = s.yaxis,
points = s.datapoints.points, points = s.datapoints.points,
mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster
// precompute some stuff to make the loop faster
mx = axisx.c2p(mouseX),
my = axisy.c2p(mouseY), my = axisy.c2p(mouseY),
maxx = maxDistance / axisx.scale, maxx = maxDistance / axisx.scale,
maxy = maxDistance / axisy.scale, maxy = maxDistance / axisy.scale,
x, y; x, y;
ps = s.datapoints.pointsize; ps = s.datapoints.pointsize;
// with inverse transforms, we can't use the maxx/maxy // with inverse transforms, we can't use the maxx/maxy
// optimization, sadly // optimization, sadly
if (axisx.options.inverseTransform) { if (axisx.options.inverseTransform) {
...@@ -3287,8 +3438,9 @@ Licensed under the MIT license. ...@@ -3287,8 +3438,9 @@ Licensed under the MIT license.
} }
} }
if (s.bars.show && !item) { // no other point can be nearby if (s.bars.show && !item) {
// no other point can be nearby
var barLeft, barRight; var barLeft, barRight;
switch (s.bars.align) { switch (s.bars.align) {
...@@ -3357,8 +3509,10 @@ Licensed under the MIT license. ...@@ -3357,8 +3509,10 @@ Licensed under the MIT license.
function(s) { return s.clickable !== false; }); function(s) { return s.clickable !== false; });
} }
// trigger click or hover event (they send the same parameters /**
// so we share their code) * trigger click or hover event (they send the same parameters
* so we share their code)
*/
function triggerClickHoverEvent(eventname, event, seriesFilter) { function triggerClickHoverEvent(eventname, event, seriesFilter) {
var offset = eventHolder.offset(), var offset = eventHolder.offset(),
canvasX = event.pageX - offset.left - plotOffset.left, canvasX = event.pageX - offset.left - plotOffset.left,
...@@ -3371,12 +3525,14 @@ Licensed under the MIT license. ...@@ -3371,12 +3525,14 @@ Licensed under the MIT license.
var item = findNearbyItem(canvasX, canvasY, seriesFilter); var item = findNearbyItem(canvasX, canvasY, seriesFilter);
if (item) { if (item) {
// fill in mouse pos for any listeners out there // fill in mouse pos for any listeners out there
item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left, 10); item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left, 10);
item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top, 10); item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top, 10);
} }
if (options.grid.autoHighlight) { if (options.grid.autoHighlight) {
// clear auto-highlights // clear auto-highlights
for (var i = 0; i < highlights.length; ++i) { for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i]; var h = highlights[i];
...@@ -3399,7 +3555,10 @@ Licensed under the MIT license. ...@@ -3399,7 +3555,10 @@ Licensed under the MIT license.
function triggerRedrawOverlay() { function triggerRedrawOverlay() {
var t = options.interaction.redrawOverlayInterval; var t = options.interaction.redrawOverlayInterval;
if (t === -1) { // skip event queue
if (t === -1) {
// skip event queue
drawOverlay(); drawOverlay();
return; return;
} }
...@@ -3544,6 +3703,7 @@ Licensed under the MIT license. ...@@ -3544,6 +3703,7 @@ Licensed under the MIT license.
if (typeof spec === "string") { if (typeof spec === "string") {
return spec; return spec;
} else { } else {
// assume this is a gradient spec; IE currently only // assume this is a gradient spec; IE currently only
// supports a simple vertical gradient properly, so that's // supports a simple vertical gradient properly, so that's
// what we support too // what we support too
...@@ -3569,12 +3729,11 @@ Licensed under the MIT license. ...@@ -3569,12 +3729,11 @@ Licensed under the MIT license.
} }
} }
// Add the plot function to the top level of the jQuery object /**
* Add the plot function to the top level of the jQuery object
*/
$.plot = function(placeholder, data, options) { $.plot = function(placeholder, data, options) {
//var t0 = new Date();
var plot = new Plot($(placeholder), data, options, $.plot.plugins); var plot = new Plot($(placeholder), data, options, $.plot.plugins);
//(window.console ? console.log : alert)("time used (msecs): " + ((new Date()).getTime() - t0.getTime()));
return plot; return plot;
}; };
...@@ -3582,30 +3741,35 @@ Licensed under the MIT license. ...@@ -3582,30 +3741,35 @@ Licensed under the MIT license.
$.plot.plugins = []; $.plot.plugins = [];
// Also add the plot function as a chainable property /**
* Also add the plot function as a chainable property
*/
$.fn.plot = function(data, options) { $.fn.plot = function(data, options) {
return this.each(function() { return this.each(function() {
$.plot(this, data, options); $.plot(this, data, options);
}); });
}; };
// round to nearby lower multiple of base /**
* round to nearby lower multiple of base
*/
function floorInBase(n, base) { function floorInBase(n, base) {
return base * Math.floor(n / base); return base * Math.floor(n / base);
} }
// 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 {number} x The x-axis coordinate of the upper left corner of * @param {CanvasRenderingContext2D} ctx The canvas 2D context.
// the rectangle to be drawn. * @param {number} x The x-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} y The y-axis coordinate of the upper left corner of
// @param {number} width The width of the rectangle to be drawn. * the rectangle to be drawn.
// @param {number} height The height of the rectangle to be drawn. * @param {number} width The width of the rectangle to be drawn.
// @param {number} radius The radius of the corner of the rectangle * @param {number} height The height of the rectangle to be drawn.
// 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) { function roundRect(ctx, x, y, width, height, radius) {
var r = x + width, var r = x + width,
b = y + height; b = y + height;
......
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