@kevinburke/flot 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +1814 -0
  2. package/LICENSE.txt +22 -0
  3. package/README.md +119 -0
  4. package/dist/flot.js +9830 -0
  5. package/dist/flot.min.js +2 -0
  6. package/dist/flot.min.js.map +1 -0
  7. package/dist/flot.mjs +9805 -0
  8. package/dist/jquery.flot.js +9869 -0
  9. package/dist/jquery.flot.min.js +2 -0
  10. package/dist/jquery.flot.min.js.map +1 -0
  11. package/dist/plugins/jquery.flot.crosshair.js +207 -0
  12. package/dist/plugins/jquery.flot.crosshair.min.js +2 -0
  13. package/dist/plugins/jquery.flot.crosshair.min.js.map +1 -0
  14. package/dist/plugins/jquery.flot.image.js +261 -0
  15. package/dist/plugins/jquery.flot.image.min.js +2 -0
  16. package/dist/plugins/jquery.flot.image.min.js.map +1 -0
  17. package/dist/plugins/jquery.flot.pie.js +815 -0
  18. package/dist/plugins/jquery.flot.pie.min.js +2 -0
  19. package/dist/plugins/jquery.flot.pie.min.js.map +1 -0
  20. package/dist/plugins/jquery.flot.resize.js +62 -0
  21. package/dist/plugins/jquery.flot.resize.min.js +2 -0
  22. package/dist/plugins/jquery.flot.resize.min.js.map +1 -0
  23. package/dist/plugins/jquery.flot.threshold.js +148 -0
  24. package/dist/plugins/jquery.flot.threshold.min.js +2 -0
  25. package/dist/plugins/jquery.flot.threshold.min.js.map +1 -0
  26. package/docs/API.md +1767 -0
  27. package/docs/PLUGINS.md +143 -0
  28. package/docs/absRelTime.md +42 -0
  29. package/docs/browser.md +24 -0
  30. package/docs/canvaswrapper.md +116 -0
  31. package/docs/composeImages.md +32 -0
  32. package/docs/drawSeries.md +35 -0
  33. package/docs/hover.md +21 -0
  34. package/docs/interactions.md +57 -0
  35. package/docs/logaxis.md +27 -0
  36. package/docs/navigate.md +110 -0
  37. package/package.json +53 -0
  38. package/source/helpers.js +168 -0
  39. package/source/index.js +70 -0
  40. package/source/jquery-adapter.js +83 -0
  41. package/source/jquery.canvaswrapper.js +546 -0
  42. package/source/jquery.colorhelpers.js +198 -0
  43. package/source/jquery.flot.axislabels.js +214 -0
  44. package/source/jquery.flot.browser.js +53 -0
  45. package/source/jquery.flot.categories.js +202 -0
  46. package/source/jquery.flot.composeImages.js +327 -0
  47. package/source/jquery.flot.crosshair.js +203 -0
  48. package/source/jquery.flot.drawSeries.js +699 -0
  49. package/source/jquery.flot.errorbars.js +375 -0
  50. package/source/jquery.flot.fillbetween.js +254 -0
  51. package/source/jquery.flot.flatdata.js +47 -0
  52. package/source/jquery.flot.hover.js +354 -0
  53. package/source/jquery.flot.image.js +252 -0
  54. package/source/jquery.flot.js +2814 -0
  55. package/source/jquery.flot.legend.js +444 -0
  56. package/source/jquery.flot.logaxis.js +299 -0
  57. package/source/jquery.flot.navigate.js +842 -0
  58. package/source/jquery.flot.pie.js +811 -0
  59. package/source/jquery.flot.resize.js +57 -0
  60. package/source/jquery.flot.saturated.js +40 -0
  61. package/source/jquery.flot.selection.js +552 -0
  62. package/source/jquery.flot.stack.js +220 -0
  63. package/source/jquery.flot.symbol.js +98 -0
  64. package/source/jquery.flot.threshold.js +144 -0
  65. package/source/jquery.flot.time.js +584 -0
  66. package/source/jquery.flot.touch.js +320 -0
  67. package/source/jquery.flot.touchNavigate.js +357 -0
  68. package/source/jquery.flot.uiConstants.js +9 -0
  69. package/source/jquery.js +9473 -0
@@ -0,0 +1,327 @@
1
+ /** ## jquery.flot.composeImages.js
2
+
3
+ This plugin is used to expose a function used to overlap several canvases and
4
+ SVGs, for the purpose of creating a snaphot out of them.
5
+
6
+ ### When composeImages is used:
7
+ When multiple canvases and SVGs have to be overlapped into a single image
8
+ and their offset on the page, must be preserved.
9
+
10
+ ### Where can be used:
11
+ In creating a downloadable snapshot of the plots, axes, cursors etc of a graph.
12
+
13
+ ### How it works:
14
+ The entry point is composeImages function. It expects an array of objects,
15
+ which should be either canvases or SVGs (or a mix). It does a prevalidation
16
+ of them, by verifying if they will be usable or not, later in the flow.
17
+ After selecting only usable sources, it passes them to getGenerateTempImg
18
+ function, which generates temporary images out of them. This function
19
+ expects that some of the passed sources (canvas or SVG) may still have
20
+ problems being converted to an image and makes sure the promises system,
21
+ used by composeImages function, moves forward. As an example, SVGs with
22
+ missing information from header or with unsupported content, may lead to
23
+ failure in generating the temporary image. Temporary images are required
24
+ mostly on extracting content from SVGs, but this is also where the x/y
25
+ offsets are extracted for each image which will be added. For SVGs in
26
+ particular, their CSS rules have to be applied.
27
+ After all temporary images are generated, they are overlapped using
28
+ getExecuteImgComposition function. This is where the destination canvas
29
+ is set to the proper dimensions. It is then output by composeImages.
30
+ This function returns a promise, which can be used to wait for the whole
31
+ composition process. It requires to be asynchronous, because this is how
32
+ temporary images load their data.
33
+ */
34
+
35
+ import { plugins } from './jquery.flot.js';
36
+ import { browser } from './jquery.flot.browser.js';
37
+
38
+ "use strict";
39
+ const GENERALFAILURECALLBACKERROR = -100; //simply a negative number
40
+ const SUCCESSFULIMAGEPREPARATION = 0;
41
+ const EMPTYARRAYOFIMAGESOURCES = -1;
42
+ const NEGATIVEIMAGESIZE = -2;
43
+ var pixelRatio = 1;
44
+ var getPixelRatio = browser.getPixelRatio;
45
+
46
+ export function composeImages(canvasOrSvgSources, destinationCanvas) {
47
+ var validCanvasOrSvgSources = canvasOrSvgSources.filter(isValidSource);
48
+ pixelRatio = getPixelRatio(destinationCanvas.getContext('2d'));
49
+
50
+ var allImgCompositionPromises = validCanvasOrSvgSources.map(function(validCanvasOrSvgSource) {
51
+ var tempImg = new Image();
52
+ var currentPromise = new Promise(getGenerateTempImg(tempImg, validCanvasOrSvgSource));
53
+ return currentPromise;
54
+ });
55
+
56
+ var lastPromise = Promise.all(allImgCompositionPromises).then(getExecuteImgComposition(destinationCanvas), failureCallback);
57
+ return lastPromise;
58
+ }
59
+
60
+ function isValidSource(canvasOrSvgSource) {
61
+ var isValidFromCanvas = true;
62
+ var isValidFromContent = true;
63
+ if ((canvasOrSvgSource === null) || (canvasOrSvgSource === undefined)) {
64
+ isValidFromContent = false;
65
+ } else {
66
+ if (canvasOrSvgSource.tagName === 'CANVAS') {
67
+ if ((canvasOrSvgSource.getBoundingClientRect().right === canvasOrSvgSource.getBoundingClientRect().left) ||
68
+ (canvasOrSvgSource.getBoundingClientRect().bottom === canvasOrSvgSource.getBoundingClientRect().top)) {
69
+ isValidFromCanvas = false;
70
+ }
71
+ }
72
+ }
73
+ return isValidFromContent && isValidFromCanvas && (window.getComputedStyle(canvasOrSvgSource).visibility === 'visible');
74
+ }
75
+
76
+ function getGenerateTempImg(tempImg, canvasOrSvgSource) {
77
+ tempImg.sourceDescription = '<info className="' + canvasOrSvgSource.className + '" tagName="' + canvasOrSvgSource.tagName + '" id="' + canvasOrSvgSource.id + '">';
78
+ tempImg.sourceComponent = canvasOrSvgSource;
79
+
80
+ return function doGenerateTempImg(successCallbackFunc, failureCallbackFunc) {
81
+ tempImg.onload = function(evt) {
82
+ tempImg.successfullyLoaded = true;
83
+ successCallbackFunc(tempImg);
84
+ };
85
+
86
+ tempImg.onabort = function(evt) {
87
+ tempImg.successfullyLoaded = false;
88
+ console.log('Can\'t generate temp image from ' + tempImg.sourceDescription + '. It is possible that it is missing some properties or its content is not supported by this browser. Source component:', tempImg.sourceComponent);
89
+ successCallbackFunc(tempImg); //call successCallback, to allow snapshot of all working images
90
+ };
91
+
92
+ tempImg.onerror = function(evt) {
93
+ tempImg.successfullyLoaded = false;
94
+ console.log('Can\'t generate temp image from ' + tempImg.sourceDescription + '. It is possible that it is missing some properties or its content is not supported by this browser. Source component:', tempImg.sourceComponent);
95
+ successCallbackFunc(tempImg); //call successCallback, to allow snapshot of all working images
96
+ };
97
+
98
+ generateTempImageFromCanvasOrSvg(canvasOrSvgSource, tempImg);
99
+ };
100
+ }
101
+
102
+ function getExecuteImgComposition(destinationCanvas) {
103
+ return function executeImgComposition(tempImgs) {
104
+ var compositionResult = copyImgsToCanvas(tempImgs, destinationCanvas);
105
+ return compositionResult;
106
+ };
107
+ }
108
+
109
+ function copyCanvasToImg(canvas, img) {
110
+ img.src = canvas.toDataURL('image/png');
111
+ }
112
+
113
+ function getCSSRules(document) {
114
+ var styleSheets = document.styleSheets,
115
+ rulesList = [];
116
+ for (var i = 0; i < styleSheets.length; i++) {
117
+ // CORS requests for style sheets throw and an exception on Chrome > 64
118
+ try {
119
+ // in Chrome, the external CSS files are empty when the page is directly loaded from disk
120
+ var rules = styleSheets[i].cssRules || [];
121
+ for (var j = 0; j < rules.length; j++) {
122
+ var rule = rules[j];
123
+ rulesList.push(rule.cssText);
124
+ }
125
+ } catch (e) {
126
+ console.log('Failed to get some css rules');
127
+ }
128
+ }
129
+ return rulesList;
130
+ }
131
+
132
+ function embedCSSRulesInSVG(rules, svg) {
133
+ var text = [
134
+ '<svg class="snapshot ' + svg.classList + '" width="' + svg.width.baseVal.value * pixelRatio + '" height="' + svg.height.baseVal.value * pixelRatio + '" viewBox="0 0 ' + svg.width.baseVal.value + ' ' + svg.height.baseVal.value + '" xmlns="http://www.w3.org/2000/svg">',
135
+ '<style>',
136
+ '/* <![CDATA[ */',
137
+ rules.join('\n'),
138
+ '/* ]]> */',
139
+ '</style>',
140
+ svg.innerHTML,
141
+ '</svg>'
142
+ ].join('\n');
143
+ return text;
144
+ }
145
+
146
+ function copySVGToImgMostBrowsers(svg, img) {
147
+ var rules = getCSSRules(document),
148
+ source = embedCSSRulesInSVG(rules, svg);
149
+
150
+ source = patchSVGSource(source);
151
+
152
+ var blob = new Blob([source], {type: "image/svg+xml;charset=utf-8"}),
153
+ domURL = self.URL || self.webkitURL || self,
154
+ url = domURL.createObjectURL(blob);
155
+ img.src = url;
156
+ }
157
+
158
+ function copySVGToImgSafari(svg, img) {
159
+ // Use this method to convert a string buffer array to a binary string.
160
+ // Do so by breaking up large strings into smaller substrings; this is necessary to avoid the
161
+ // "maximum call stack size exceeded" exception that can happen when calling 'String.fromCharCode.apply'
162
+ // with a very long array.
163
+ function buildBinaryString (arrayBuffer) {
164
+ var binaryString = "";
165
+ const utf8Array = new Uint8Array(arrayBuffer);
166
+ const blockSize = 16384;
167
+ for (var i = 0; i < utf8Array.length; i = i + blockSize) {
168
+ const binarySubString = String.fromCharCode.apply(null, utf8Array.subarray(i, i + blockSize));
169
+ binaryString = binaryString + binarySubString;
170
+ }
171
+ return binaryString;
172
+ };
173
+
174
+ var rules = getCSSRules(document),
175
+ source = embedCSSRulesInSVG(rules, svg),
176
+ data,
177
+ utf8BinaryString;
178
+
179
+ source = patchSVGSource(source);
180
+
181
+ // Encode the string as UTF-8 and convert it to a binary string. The UTF-8 encoding is required to
182
+ // capture unicode characters correctly.
183
+ utf8BinaryString = buildBinaryString(new (TextEncoder || TextEncoderLite)('utf-8').encode(source));
184
+
185
+ data = "data:image/svg+xml;base64," + btoa(utf8BinaryString);
186
+ img.src = data;
187
+ }
188
+
189
+ function patchSVGSource(svgSource) {
190
+ var source = '';
191
+ //add name spaces.
192
+ if (!svgSource.match(/^<svg[^>]+xmlns="http:\/\/www\.w3\.org\/2000\/svg"/)) {
193
+ source = svgSource.replace(/^<svg/, '<svg xmlns="http://www.w3.org/2000/svg"');
194
+ }
195
+ if (!svgSource.match(/^<svg[^>]+"http:\/\/www\.w3\.org\/1999\/xlink"/)) {
196
+ source = svgSource.replace(/^<svg/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
197
+ }
198
+
199
+ //add xml declaration
200
+ return '<?xml version="1.0" standalone="no"?>\r\n' + source;
201
+ }
202
+
203
+ function copySVGToImg(svg, img) {
204
+ if (browser.isSafari() || browser.isMobileSafari()) {
205
+ copySVGToImgSafari(svg, img);
206
+ } else {
207
+ copySVGToImgMostBrowsers(svg, img);
208
+ }
209
+ }
210
+
211
+ function adaptDestSizeToZoom(destinationCanvas, sources) {
212
+ function containsSVGs(source) {
213
+ return source.srcImgTagName === 'svg';
214
+ }
215
+
216
+ if (sources.find(containsSVGs) !== undefined) {
217
+ if (pixelRatio < 1) {
218
+ destinationCanvas.width = destinationCanvas.width * pixelRatio;
219
+ destinationCanvas.height = destinationCanvas.height * pixelRatio;
220
+ }
221
+ }
222
+ }
223
+
224
+ function prepareImagesToBeComposed(sources, destination) {
225
+ var result = SUCCESSFULIMAGEPREPARATION;
226
+ if (sources.length === 0) {
227
+ result = EMPTYARRAYOFIMAGESOURCES; //nothing to do if called without sources
228
+ } else {
229
+ var minX = sources[0].genLeft;
230
+ var minY = sources[0].genTop;
231
+ var maxX = sources[0].genRight;
232
+ var maxY = sources[0].genBottom;
233
+ var i = 0;
234
+
235
+ for (i = 1; i < sources.length; i++) {
236
+ if (minX > sources[i].genLeft) {
237
+ minX = sources[i].genLeft;
238
+ }
239
+
240
+ if (minY > sources[i].genTop) {
241
+ minY = sources[i].genTop;
242
+ }
243
+ }
244
+
245
+ for (i = 1; i < sources.length; i++) {
246
+ if (maxX < sources[i].genRight) {
247
+ maxX = sources[i].genRight;
248
+ }
249
+
250
+ if (maxY < sources[i].genBottom) {
251
+ maxY = sources[i].genBottom;
252
+ }
253
+ }
254
+
255
+ if ((maxX - minX <= 0) || (maxY - minY <= 0)) {
256
+ result = NEGATIVEIMAGESIZE; //this might occur on hidden images
257
+ } else {
258
+ destination.width = Math.round(maxX - minX);
259
+ destination.height = Math.round(maxY - minY);
260
+
261
+ for (i = 0; i < sources.length; i++) {
262
+ sources[i].xCompOffset = sources[i].genLeft - minX;
263
+ sources[i].yCompOffset = sources[i].genTop - minY;
264
+ }
265
+
266
+ adaptDestSizeToZoom(destination, sources);
267
+ }
268
+ }
269
+ return result;
270
+ }
271
+
272
+ function copyImgsToCanvas(sources, destination) {
273
+ var prepareImagesResult = prepareImagesToBeComposed(sources, destination);
274
+ if (prepareImagesResult === SUCCESSFULIMAGEPREPARATION) {
275
+ var destinationCtx = destination.getContext('2d');
276
+
277
+ for (var i = 0; i < sources.length; i++) {
278
+ if (sources[i].successfullyLoaded === true) {
279
+ destinationCtx.drawImage(sources[i], sources[i].xCompOffset * pixelRatio, sources[i].yCompOffset * pixelRatio);
280
+ }
281
+ }
282
+ }
283
+ return prepareImagesResult;
284
+ }
285
+
286
+ function adnotateDestImgWithBoundingClientRect(srcCanvasOrSvg, destImg) {
287
+ destImg.genLeft = srcCanvasOrSvg.getBoundingClientRect().left;
288
+ destImg.genTop = srcCanvasOrSvg.getBoundingClientRect().top;
289
+
290
+ if (srcCanvasOrSvg.tagName === 'CANVAS') {
291
+ destImg.genRight = destImg.genLeft + srcCanvasOrSvg.width;
292
+ destImg.genBottom = destImg.genTop + srcCanvasOrSvg.height;
293
+ }
294
+
295
+ if (srcCanvasOrSvg.tagName === 'svg') {
296
+ destImg.genRight = srcCanvasOrSvg.getBoundingClientRect().right;
297
+ destImg.genBottom = srcCanvasOrSvg.getBoundingClientRect().bottom;
298
+ }
299
+ }
300
+
301
+ function generateTempImageFromCanvasOrSvg(srcCanvasOrSvg, destImg) {
302
+ if (srcCanvasOrSvg.tagName === 'CANVAS') {
303
+ copyCanvasToImg(srcCanvasOrSvg, destImg);
304
+ }
305
+
306
+ if (srcCanvasOrSvg.tagName === 'svg') {
307
+ copySVGToImg(srcCanvasOrSvg, destImg);
308
+ }
309
+
310
+ destImg.srcImgTagName = srcCanvasOrSvg.tagName;
311
+ adnotateDestImgWithBoundingClientRect(srcCanvasOrSvg, destImg);
312
+ }
313
+
314
+ function failureCallback() {
315
+ return GENERALFAILURECALLBACKERROR;
316
+ }
317
+
318
+ function init(plot) {
319
+ // used to extend the public API of the plot
320
+ plot.composeImages = composeImages;
321
+ }
322
+
323
+ plugins.push({
324
+ init: init,
325
+ name: 'composeImages',
326
+ version: '1.0'
327
+ });
@@ -0,0 +1,203 @@
1
+ /* Flot plugin for showing crosshairs when the mouse hovers over the plot.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin supports these options:
7
+
8
+ crosshair: {
9
+ mode: null or "x" or "y" or "xy"
10
+ color: color
11
+ lineWidth: number
12
+ }
13
+
14
+ Set the mode to one of "x", "y" or "xy". The "x" mode enables a vertical
15
+ crosshair that lets you trace the values on the x axis, "y" enables a
16
+ horizontal crosshair and "xy" enables them both. "color" is the color of the
17
+ crosshair (default is "rgba(170, 0, 0, 0.80)"), "lineWidth" is the width of
18
+ the drawn lines (default is 1).
19
+
20
+ The plugin also adds four public methods:
21
+
22
+ - setCrosshair( pos )
23
+
24
+ Set the position of the crosshair. Note that this is cleared if the user
25
+ moves the mouse. "pos" is in coordinates of the plot and should be on the
26
+ form { x: xpos, y: ypos } (you can use x2/x3/... if you're using multiple
27
+ axes), which is coincidentally the same format as what you get from a
28
+ "plothover" event. If "pos" is null, the crosshair is cleared.
29
+
30
+ - clearCrosshair()
31
+
32
+ Clear the crosshair.
33
+
34
+ - lockCrosshair(pos)
35
+
36
+ Cause the crosshair to lock to the current location, no longer updating if
37
+ the user moves the mouse. Optionally supply a position (passed on to
38
+ setCrosshair()) to move it to.
39
+
40
+ Example usage:
41
+
42
+ var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
43
+ $("#graph").bind( "plothover", function ( evt, position, item ) {
44
+ if ( item ) {
45
+ // Lock the crosshair to the data point being hovered
46
+ myFlot.lockCrosshair({
47
+ x: item.datapoint[ 0 ],
48
+ y: item.datapoint[ 1 ]
49
+ });
50
+ } else {
51
+ // Return normal crosshair operation
52
+ myFlot.unlockCrosshair();
53
+ }
54
+ });
55
+
56
+ - unlockCrosshair()
57
+
58
+ Free the crosshair to move again after locking it.
59
+ */
60
+
61
+ import { plugins } from './jquery.flot.js';
62
+ import { bind, unbind } from './helpers.js';
63
+
64
+ var options = {
65
+ crosshair: {
66
+ mode: null, // one of null, "x", "y" or "xy",
67
+ color: "rgba(170, 0, 0, 0.80)",
68
+ lineWidth: 1
69
+ }
70
+ };
71
+
72
+ function init(plot) {
73
+ // position of crosshair in pixels
74
+ var crosshair = {x: -1, y: -1, locked: false, highlighted: false};
75
+
76
+ plot.setCrosshair = function setCrosshair(pos) {
77
+ if (!pos) {
78
+ crosshair.x = -1;
79
+ } else {
80
+ var o = plot.p2c(pos);
81
+ crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
82
+ crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
83
+ }
84
+
85
+ plot.triggerRedrawOverlay();
86
+ };
87
+
88
+ plot.clearCrosshair = plot.setCrosshair; // passes null for pos
89
+
90
+ plot.lockCrosshair = function lockCrosshair(pos) {
91
+ if (pos) {
92
+ plot.setCrosshair(pos);
93
+ }
94
+
95
+ crosshair.locked = true;
96
+ };
97
+
98
+ plot.unlockCrosshair = function unlockCrosshair() {
99
+ crosshair.locked = false;
100
+ crosshair.rect = null;
101
+ };
102
+
103
+ function onMouseOut(e) {
104
+ if (crosshair.locked) {
105
+ return;
106
+ }
107
+
108
+ if (crosshair.x !== -1) {
109
+ crosshair.x = -1;
110
+ plot.triggerRedrawOverlay();
111
+ }
112
+ }
113
+
114
+ function onMouseMove(e) {
115
+ var offset = plot.offset();
116
+ if (crosshair.locked) {
117
+ var mouseX = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
118
+ var mouseY = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
119
+
120
+ if ((mouseX > crosshair.x - 4) && (mouseX < crosshair.x + 4) && (mouseY > crosshair.y - 4) && (mouseY < crosshair.y + 4)) {
121
+ if (!crosshair.highlighted) {
122
+ crosshair.highlighted = true;
123
+ plot.triggerRedrawOverlay();
124
+ }
125
+ } else {
126
+ if (crosshair.highlighted) {
127
+ crosshair.highlighted = false;
128
+ plot.triggerRedrawOverlay();
129
+ }
130
+ }
131
+ return;
132
+ }
133
+
134
+ if (plot.getSelection && plot.getSelection()) {
135
+ crosshair.x = -1; // hide the crosshair while selecting
136
+ return;
137
+ }
138
+
139
+ crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
140
+ crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
141
+ plot.triggerRedrawOverlay();
142
+ }
143
+
144
+ plot.hooks.bindEvents.push(function (plot, eventHolder) {
145
+ if (!plot.getOptions().crosshair.mode) {
146
+ return;
147
+ }
148
+
149
+ bind(eventHolder, "mouseout", onMouseOut);
150
+ bind(eventHolder, "mousemove", onMouseMove);
151
+ });
152
+
153
+ plot.hooks.drawOverlay.push(function (plot, ctx) {
154
+ var c = plot.getOptions().crosshair;
155
+ if (!c.mode) {
156
+ return;
157
+ }
158
+
159
+ var plotOffset = plot.getPlotOffset();
160
+
161
+ ctx.save();
162
+ ctx.translate(plotOffset.left, plotOffset.top);
163
+
164
+ if (crosshair.x !== -1) {
165
+ var adj = plot.getOptions().crosshair.lineWidth % 2 ? 0.5 : 0;
166
+
167
+ ctx.strokeStyle = c.color;
168
+ ctx.lineWidth = c.lineWidth;
169
+ ctx.lineJoin = "round";
170
+
171
+ ctx.beginPath();
172
+ if (c.mode.indexOf("x") !== -1) {
173
+ var drawX = Math.floor(crosshair.x) + adj;
174
+ ctx.moveTo(drawX, 0);
175
+ ctx.lineTo(drawX, plot.height());
176
+ }
177
+ if (c.mode.indexOf("y") !== -1) {
178
+ var drawY = Math.floor(crosshair.y) + adj;
179
+ ctx.moveTo(0, drawY);
180
+ ctx.lineTo(plot.width(), drawY);
181
+ }
182
+ if (crosshair.locked) {
183
+ if (crosshair.highlighted) ctx.fillStyle = 'orange';
184
+ else ctx.fillStyle = c.color;
185
+ ctx.fillRect(Math.floor(crosshair.x) + adj - 4, Math.floor(crosshair.y) + adj - 4, 8, 8);
186
+ }
187
+ ctx.stroke();
188
+ }
189
+ ctx.restore();
190
+ });
191
+
192
+ plot.hooks.shutdown.push(function (plot, eventHolder) {
193
+ unbind(eventHolder, "mouseout", onMouseOut);
194
+ unbind(eventHolder, "mousemove", onMouseMove);
195
+ });
196
+ }
197
+
198
+ plugins.push({
199
+ init: init,
200
+ options: options,
201
+ name: 'crosshair',
202
+ version: '1.0'
203
+ });