inviton-powerduck 0.0.224 → 0.0.226
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.
- package/common/query-string-utils.ts +67 -0
- package/common/utils/cookie.ts +10 -8
- package/components/chart-js/thirdparty/flot/jquery.flot.categories.min.js +93 -93
- package/components/chart-js/thirdparty/flot/jquery.flot.crosshair.min.js +83 -83
- package/components/chart-js/thirdparty/flot/jquery.flot.navigate.min.js +270 -270
- package/components/chart-js/thirdparty/flot/jquery.flot.pie.min.js +507 -507
- package/components/chart-js/thirdparty/flot/jquery.flot.stack.min.js +104 -104
- package/components/dropdown/css/smart-dropdown.scss +6 -3
- package/components/dropdown/smart-dropdown.tsx +81 -34
- package/components/image-crop/vendor/jquery.Jcrop.min.css +344 -344
- package/components/svg/skilift-svg.tsx +6 -6
- package/package.json +1 -1
|
@@ -45,6 +45,73 @@ export class QueryStringUtils {
|
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
static getAll(paramName: string): string[] {
|
|
49
|
+
const normalized = paramName.toLowerCase();
|
|
50
|
+
const values: string[] = [];
|
|
51
|
+
const route = PowerduckState.getCurrentRouteQuery();
|
|
52
|
+
const routeQuery = route?.value?.query ?? {};
|
|
53
|
+
|
|
54
|
+
for (const [
|
|
55
|
+
key,
|
|
56
|
+
value,
|
|
57
|
+
] of Object.entries(routeQuery)) {
|
|
58
|
+
if (key.toLowerCase() === normalized) {
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
values.push(...value.map(v => `${v}`));
|
|
61
|
+
} else if (value != null) {
|
|
62
|
+
values.push(`${value}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof location?.search === 'string' && location.search.length > 1) {
|
|
68
|
+
const params = new URLSearchParams(location.search);
|
|
69
|
+
for (const [
|
|
70
|
+
key,
|
|
71
|
+
value,
|
|
72
|
+
] of params.entries()) {
|
|
73
|
+
if (key.toLowerCase() === normalized) {
|
|
74
|
+
values.push(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return values;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static setValues(paramName: string, values: (string | number)[]): void {
|
|
83
|
+
const router = (PowerduckState as any).getRouter?.();
|
|
84
|
+
const route = router?.currentRoute?.value;
|
|
85
|
+
|
|
86
|
+
if (router && route) {
|
|
87
|
+
const nextQuery = { ...(route.query || {}) };
|
|
88
|
+
if (values?.length) {
|
|
89
|
+
nextQuery[paramName] = values.map(v => `${v}`);
|
|
90
|
+
} else {
|
|
91
|
+
delete nextQuery[paramName];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
router.replace({ ...route, query: nextQuery });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (typeof window !== 'undefined') {
|
|
99
|
+
const url = new URL(window.location.href);
|
|
100
|
+
url.searchParams.delete(paramName);
|
|
101
|
+
values?.forEach(v => url.searchParams.append(paramName, `${v}`));
|
|
102
|
+
window.history.replaceState(
|
|
103
|
+
{},
|
|
104
|
+
document.title,
|
|
105
|
+
url.toString(),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static removeValue(paramName: string, valueToRemove: string | number): void {
|
|
111
|
+
const nextValues = this.getAll(paramName).filter(v => v !== `${valueToRemove}`);
|
|
112
|
+
this.setValues(paramName, nextValues);
|
|
113
|
+
}
|
|
114
|
+
|
|
48
115
|
private static _parseQsBool(qsArg: string, defaultValue?: boolean): boolean {
|
|
49
116
|
if (qsArg == null || qsArg.length == 0) {
|
|
50
117
|
if (defaultValue != null) {
|
package/common/utils/cookie.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import { DomainHelper } from './domain-helper';
|
|
3
2
|
import { globalState } from '../../app/global-state';
|
|
3
|
+
import { DomainHelper } from './domain-helper';
|
|
4
4
|
|
|
5
5
|
// Cookie manipulation abstraction
|
|
6
6
|
export class CookieProvider {
|
|
@@ -16,9 +16,9 @@ export class CookieProvider {
|
|
|
16
16
|
value: string,
|
|
17
17
|
expiration?: Temporal.PlainDateTime,
|
|
18
18
|
) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (!globalState.windowExists) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
23
|
let domain = DomainHelper.getCookieDomain();
|
|
24
24
|
if (domain.length > 0) {
|
|
@@ -27,7 +27,9 @@ export class CookieProvider {
|
|
|
27
27
|
|
|
28
28
|
let realExpiration;
|
|
29
29
|
if (expiration != null) {
|
|
30
|
-
|
|
30
|
+
const instant = expiration.toZonedDateTime('UTC').toInstant();
|
|
31
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
32
|
+
realExpiration = new Date(instant.epochMilliseconds).toUTCString();
|
|
31
33
|
} else {
|
|
32
34
|
realExpiration = '';
|
|
33
35
|
}
|
|
@@ -41,9 +43,9 @@ export class CookieProvider {
|
|
|
41
43
|
* @param name Name of the cookie
|
|
42
44
|
*/
|
|
43
45
|
static read(name: string): string {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (!globalState.windowExists) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
name = `${name}=`;
|
|
49
51
|
const ca = document.cookie.split(';');
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/* Javascript plotting library for jQuery, version 0.8.3.
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
4
|
-
Licensed under the MIT license.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
(function ($) {
|
|
8
|
-
var options = { xaxis: { categories: null }, yaxis: { categories: null } };
|
|
9
|
-
function processRawData(plot, series, data, datapoints) {
|
|
10
|
-
var xCategories = series.xaxis.options.mode == "categories",
|
|
11
|
-
yCategories = series.yaxis.options.mode == "categories";
|
|
12
|
-
if (!(xCategories || yCategories)) return;
|
|
13
|
-
var format = datapoints.format;
|
|
14
|
-
if (!format) {
|
|
15
|
-
var s = series;
|
|
16
|
-
format = [];
|
|
17
|
-
format.push({ x: true, number: true, required: true });
|
|
18
|
-
format.push({ y: true, number: true, required: true });
|
|
19
|
-
if (s.bars.show || (s.lines.show && s.lines.fill)) {
|
|
20
|
-
var autoscale = !!((s.bars.show && s.bars.zero) || (s.lines.show && s.lines.zero));
|
|
21
|
-
format.push({ y: true, number: true, required: false, defaultValue: 0, autoscale: autoscale });
|
|
22
|
-
if (s.bars.horizontal) {
|
|
23
|
-
delete format[format.length - 1].y;
|
|
24
|
-
format[format.length - 1].x = true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
datapoints.format = format;
|
|
28
|
-
}
|
|
29
|
-
for (var m = 0; m < format.length; ++m) {
|
|
30
|
-
if (format[m].x && xCategories) format[m].number = false;
|
|
31
|
-
if (format[m].y && yCategories) format[m].number = false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function getNextIndex(categories) {
|
|
35
|
-
var index = -1;
|
|
36
|
-
for (var v in categories) if (categories[v] > index) index = categories[v];
|
|
37
|
-
return index + 1;
|
|
38
|
-
}
|
|
39
|
-
function categoriesTickGenerator(axis) {
|
|
40
|
-
var res = [];
|
|
41
|
-
for (var label in axis.categories) {
|
|
42
|
-
var v = axis.categories[label];
|
|
43
|
-
if (v >= axis.min && v <= axis.max) res.push([v, label]);
|
|
44
|
-
}
|
|
45
|
-
res.sort(function (a, b) {
|
|
46
|
-
return a[0] - b[0];
|
|
47
|
-
});
|
|
48
|
-
return res;
|
|
49
|
-
}
|
|
50
|
-
function setupCategoriesForAxis(series, axis, datapoints) {
|
|
51
|
-
if (series[axis].options.mode != "categories") return;
|
|
52
|
-
if (!series[axis].categories) {
|
|
53
|
-
var c = {},
|
|
54
|
-
o = series[axis].options.categories || {};
|
|
55
|
-
if ($.isArray(o)) {
|
|
56
|
-
for (var i = 0; i < o.length; ++i) c[o[i]] = i;
|
|
57
|
-
} else {
|
|
58
|
-
for (var v in o) c[v] = o[v];
|
|
59
|
-
}
|
|
60
|
-
series[axis].categories = c;
|
|
61
|
-
}
|
|
62
|
-
if (!series[axis].options.ticks) series[axis].options.ticks = categoriesTickGenerator;
|
|
63
|
-
transformPointsOnAxis(datapoints, axis, series[axis].categories);
|
|
64
|
-
}
|
|
65
|
-
function transformPointsOnAxis(datapoints, axis, categories) {
|
|
66
|
-
var points = datapoints.points,
|
|
67
|
-
ps = datapoints.pointsize,
|
|
68
|
-
format = datapoints.format,
|
|
69
|
-
formatColumn = axis.charAt(0),
|
|
70
|
-
index = getNextIndex(categories);
|
|
71
|
-
for (var i = 0; i < points.length; i += ps) {
|
|
72
|
-
if (points[i] == null) continue;
|
|
73
|
-
for (var m = 0; m < ps; ++m) {
|
|
74
|
-
var val = points[i + m];
|
|
75
|
-
if (val == null || !format[m][formatColumn]) continue;
|
|
76
|
-
if (!(val in categories)) {
|
|
77
|
-
categories[val] = index;
|
|
78
|
-
++index;
|
|
79
|
-
}
|
|
80
|
-
points[i + m] = categories[val];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function processDatapoints(plot, series, datapoints) {
|
|
85
|
-
setupCategoriesForAxis(series, "xaxis", datapoints);
|
|
86
|
-
setupCategoriesForAxis(series, "yaxis", datapoints);
|
|
87
|
-
}
|
|
88
|
-
function init(plot) {
|
|
89
|
-
plot.hooks.processRawData.push(processRawData);
|
|
90
|
-
plot.hooks.processDatapoints.push(processDatapoints);
|
|
91
|
-
}
|
|
92
|
-
$.plot.plugins.push({ init: init, options: options, name: "categories", version: "1.0" });
|
|
93
|
-
})(jQuery);
|
|
1
|
+
/* Javascript plotting library for jQuery, version 0.8.3.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
4
|
+
Licensed under the MIT license.
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
(function ($) {
|
|
8
|
+
var options = { xaxis: { categories: null }, yaxis: { categories: null } };
|
|
9
|
+
function processRawData(plot, series, data, datapoints) {
|
|
10
|
+
var xCategories = series.xaxis.options.mode == "categories",
|
|
11
|
+
yCategories = series.yaxis.options.mode == "categories";
|
|
12
|
+
if (!(xCategories || yCategories)) return;
|
|
13
|
+
var format = datapoints.format;
|
|
14
|
+
if (!format) {
|
|
15
|
+
var s = series;
|
|
16
|
+
format = [];
|
|
17
|
+
format.push({ x: true, number: true, required: true });
|
|
18
|
+
format.push({ y: true, number: true, required: true });
|
|
19
|
+
if (s.bars.show || (s.lines.show && s.lines.fill)) {
|
|
20
|
+
var autoscale = !!((s.bars.show && s.bars.zero) || (s.lines.show && s.lines.zero));
|
|
21
|
+
format.push({ y: true, number: true, required: false, defaultValue: 0, autoscale: autoscale });
|
|
22
|
+
if (s.bars.horizontal) {
|
|
23
|
+
delete format[format.length - 1].y;
|
|
24
|
+
format[format.length - 1].x = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
datapoints.format = format;
|
|
28
|
+
}
|
|
29
|
+
for (var m = 0; m < format.length; ++m) {
|
|
30
|
+
if (format[m].x && xCategories) format[m].number = false;
|
|
31
|
+
if (format[m].y && yCategories) format[m].number = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getNextIndex(categories) {
|
|
35
|
+
var index = -1;
|
|
36
|
+
for (var v in categories) if (categories[v] > index) index = categories[v];
|
|
37
|
+
return index + 1;
|
|
38
|
+
}
|
|
39
|
+
function categoriesTickGenerator(axis) {
|
|
40
|
+
var res = [];
|
|
41
|
+
for (var label in axis.categories) {
|
|
42
|
+
var v = axis.categories[label];
|
|
43
|
+
if (v >= axis.min && v <= axis.max) res.push([v, label]);
|
|
44
|
+
}
|
|
45
|
+
res.sort(function (a, b) {
|
|
46
|
+
return a[0] - b[0];
|
|
47
|
+
});
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
50
|
+
function setupCategoriesForAxis(series, axis, datapoints) {
|
|
51
|
+
if (series[axis].options.mode != "categories") return;
|
|
52
|
+
if (!series[axis].categories) {
|
|
53
|
+
var c = {},
|
|
54
|
+
o = series[axis].options.categories || {};
|
|
55
|
+
if ($.isArray(o)) {
|
|
56
|
+
for (var i = 0; i < o.length; ++i) c[o[i]] = i;
|
|
57
|
+
} else {
|
|
58
|
+
for (var v in o) c[v] = o[v];
|
|
59
|
+
}
|
|
60
|
+
series[axis].categories = c;
|
|
61
|
+
}
|
|
62
|
+
if (!series[axis].options.ticks) series[axis].options.ticks = categoriesTickGenerator;
|
|
63
|
+
transformPointsOnAxis(datapoints, axis, series[axis].categories);
|
|
64
|
+
}
|
|
65
|
+
function transformPointsOnAxis(datapoints, axis, categories) {
|
|
66
|
+
var points = datapoints.points,
|
|
67
|
+
ps = datapoints.pointsize,
|
|
68
|
+
format = datapoints.format,
|
|
69
|
+
formatColumn = axis.charAt(0),
|
|
70
|
+
index = getNextIndex(categories);
|
|
71
|
+
for (var i = 0; i < points.length; i += ps) {
|
|
72
|
+
if (points[i] == null) continue;
|
|
73
|
+
for (var m = 0; m < ps; ++m) {
|
|
74
|
+
var val = points[i + m];
|
|
75
|
+
if (val == null || !format[m][formatColumn]) continue;
|
|
76
|
+
if (!(val in categories)) {
|
|
77
|
+
categories[val] = index;
|
|
78
|
+
++index;
|
|
79
|
+
}
|
|
80
|
+
points[i + m] = categories[val];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function processDatapoints(plot, series, datapoints) {
|
|
85
|
+
setupCategoriesForAxis(series, "xaxis", datapoints);
|
|
86
|
+
setupCategoriesForAxis(series, "yaxis", datapoints);
|
|
87
|
+
}
|
|
88
|
+
function init(plot) {
|
|
89
|
+
plot.hooks.processRawData.push(processRawData);
|
|
90
|
+
plot.hooks.processDatapoints.push(processDatapoints);
|
|
91
|
+
}
|
|
92
|
+
$.plot.plugins.push({ init: init, options: options, name: "categories", version: "1.0" });
|
|
93
|
+
})(jQuery);
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
/* Javascript plotting library for jQuery, version 0.8.3.
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
4
|
-
Licensed under the MIT license.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
(function ($) {
|
|
8
|
-
var options = { crosshair: { mode: null, color: "rgba(170, 0, 0, 0.80)", lineWidth: 1 } };
|
|
9
|
-
function init(plot) {
|
|
10
|
-
var crosshair = { x: -1, y: -1, locked: false };
|
|
11
|
-
plot.setCrosshair = function setCrosshair(pos) {
|
|
12
|
-
if (!pos) crosshair.x = -1;
|
|
13
|
-
else {
|
|
14
|
-
var o = plot.p2c(pos);
|
|
15
|
-
crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
|
|
16
|
-
crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
|
|
17
|
-
}
|
|
18
|
-
plot.triggerRedrawOverlay();
|
|
19
|
-
};
|
|
20
|
-
plot.clearCrosshair = plot.setCrosshair;
|
|
21
|
-
plot.lockCrosshair = function lockCrosshair(pos) {
|
|
22
|
-
if (pos) plot.setCrosshair(pos);
|
|
23
|
-
crosshair.locked = true;
|
|
24
|
-
};
|
|
25
|
-
plot.unlockCrosshair = function unlockCrosshair() {
|
|
26
|
-
crosshair.locked = false;
|
|
27
|
-
};
|
|
28
|
-
function onMouseOut(e) {
|
|
29
|
-
if (crosshair.locked) return;
|
|
30
|
-
if (crosshair.x != -1) {
|
|
31
|
-
crosshair.x = -1;
|
|
32
|
-
plot.triggerRedrawOverlay();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function onMouseMove(e) {
|
|
36
|
-
if (crosshair.locked) return;
|
|
37
|
-
if (plot.getSelection && plot.getSelection()) {
|
|
38
|
-
crosshair.x = -1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
var offset = plot.offset();
|
|
42
|
-
crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
|
|
43
|
-
crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
|
|
44
|
-
plot.triggerRedrawOverlay();
|
|
45
|
-
}
|
|
46
|
-
plot.hooks.bindEvents.push(function (plot, eventHolder) {
|
|
47
|
-
if (!plot.getOptions().crosshair.mode) return;
|
|
48
|
-
eventHolder.mouseout(onMouseOut);
|
|
49
|
-
eventHolder.mousemove(onMouseMove);
|
|
50
|
-
});
|
|
51
|
-
plot.hooks.drawOverlay.push(function (plot, ctx) {
|
|
52
|
-
var c = plot.getOptions().crosshair;
|
|
53
|
-
if (!c.mode) return;
|
|
54
|
-
var plotOffset = plot.getPlotOffset();
|
|
55
|
-
ctx.save();
|
|
56
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
|
57
|
-
if (crosshair.x != -1) {
|
|
58
|
-
var adj = plot.getOptions().crosshair.lineWidth % 2 ? 0.5 : 0;
|
|
59
|
-
ctx.strokeStyle = c.color;
|
|
60
|
-
ctx.lineWidth = c.lineWidth;
|
|
61
|
-
ctx.lineJoin = "round";
|
|
62
|
-
ctx.beginPath();
|
|
63
|
-
if (c.mode.indexOf("x") != -1) {
|
|
64
|
-
var drawX = Math.floor(crosshair.x) + adj;
|
|
65
|
-
ctx.moveTo(drawX, 0);
|
|
66
|
-
ctx.lineTo(drawX, plot.height());
|
|
67
|
-
}
|
|
68
|
-
if (c.mode.indexOf("y") != -1) {
|
|
69
|
-
var drawY = Math.floor(crosshair.y) + adj;
|
|
70
|
-
ctx.moveTo(0, drawY);
|
|
71
|
-
ctx.lineTo(plot.width(), drawY);
|
|
72
|
-
}
|
|
73
|
-
ctx.stroke();
|
|
74
|
-
}
|
|
75
|
-
ctx.restore();
|
|
76
|
-
});
|
|
77
|
-
plot.hooks.shutdown.push(function (plot, eventHolder) {
|
|
78
|
-
eventHolder.unbind("mouseout", onMouseOut);
|
|
79
|
-
eventHolder.unbind("mousemove", onMouseMove);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
$.plot.plugins.push({ init: init, options: options, name: "crosshair", version: "1.0" });
|
|
83
|
-
})(jQuery);
|
|
1
|
+
/* Javascript plotting library for jQuery, version 0.8.3.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
|
4
|
+
Licensed under the MIT license.
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
(function ($) {
|
|
8
|
+
var options = { crosshair: { mode: null, color: "rgba(170, 0, 0, 0.80)", lineWidth: 1 } };
|
|
9
|
+
function init(plot) {
|
|
10
|
+
var crosshair = { x: -1, y: -1, locked: false };
|
|
11
|
+
plot.setCrosshair = function setCrosshair(pos) {
|
|
12
|
+
if (!pos) crosshair.x = -1;
|
|
13
|
+
else {
|
|
14
|
+
var o = plot.p2c(pos);
|
|
15
|
+
crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
|
|
16
|
+
crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
|
|
17
|
+
}
|
|
18
|
+
plot.triggerRedrawOverlay();
|
|
19
|
+
};
|
|
20
|
+
plot.clearCrosshair = plot.setCrosshair;
|
|
21
|
+
plot.lockCrosshair = function lockCrosshair(pos) {
|
|
22
|
+
if (pos) plot.setCrosshair(pos);
|
|
23
|
+
crosshair.locked = true;
|
|
24
|
+
};
|
|
25
|
+
plot.unlockCrosshair = function unlockCrosshair() {
|
|
26
|
+
crosshair.locked = false;
|
|
27
|
+
};
|
|
28
|
+
function onMouseOut(e) {
|
|
29
|
+
if (crosshair.locked) return;
|
|
30
|
+
if (crosshair.x != -1) {
|
|
31
|
+
crosshair.x = -1;
|
|
32
|
+
plot.triggerRedrawOverlay();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function onMouseMove(e) {
|
|
36
|
+
if (crosshair.locked) return;
|
|
37
|
+
if (plot.getSelection && plot.getSelection()) {
|
|
38
|
+
crosshair.x = -1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var offset = plot.offset();
|
|
42
|
+
crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
|
|
43
|
+
crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
|
|
44
|
+
plot.triggerRedrawOverlay();
|
|
45
|
+
}
|
|
46
|
+
plot.hooks.bindEvents.push(function (plot, eventHolder) {
|
|
47
|
+
if (!plot.getOptions().crosshair.mode) return;
|
|
48
|
+
eventHolder.mouseout(onMouseOut);
|
|
49
|
+
eventHolder.mousemove(onMouseMove);
|
|
50
|
+
});
|
|
51
|
+
plot.hooks.drawOverlay.push(function (plot, ctx) {
|
|
52
|
+
var c = plot.getOptions().crosshair;
|
|
53
|
+
if (!c.mode) return;
|
|
54
|
+
var plotOffset = plot.getPlotOffset();
|
|
55
|
+
ctx.save();
|
|
56
|
+
ctx.translate(plotOffset.left, plotOffset.top);
|
|
57
|
+
if (crosshair.x != -1) {
|
|
58
|
+
var adj = plot.getOptions().crosshair.lineWidth % 2 ? 0.5 : 0;
|
|
59
|
+
ctx.strokeStyle = c.color;
|
|
60
|
+
ctx.lineWidth = c.lineWidth;
|
|
61
|
+
ctx.lineJoin = "round";
|
|
62
|
+
ctx.beginPath();
|
|
63
|
+
if (c.mode.indexOf("x") != -1) {
|
|
64
|
+
var drawX = Math.floor(crosshair.x) + adj;
|
|
65
|
+
ctx.moveTo(drawX, 0);
|
|
66
|
+
ctx.lineTo(drawX, plot.height());
|
|
67
|
+
}
|
|
68
|
+
if (c.mode.indexOf("y") != -1) {
|
|
69
|
+
var drawY = Math.floor(crosshair.y) + adj;
|
|
70
|
+
ctx.moveTo(0, drawY);
|
|
71
|
+
ctx.lineTo(plot.width(), drawY);
|
|
72
|
+
}
|
|
73
|
+
ctx.stroke();
|
|
74
|
+
}
|
|
75
|
+
ctx.restore();
|
|
76
|
+
});
|
|
77
|
+
plot.hooks.shutdown.push(function (plot, eventHolder) {
|
|
78
|
+
eventHolder.unbind("mouseout", onMouseOut);
|
|
79
|
+
eventHolder.unbind("mousemove", onMouseMove);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
$.plot.plugins.push({ init: init, options: options, name: "crosshair", version: "1.0" });
|
|
83
|
+
})(jQuery);
|