parent
39172f8c49
commit
9dc33de49f
|
@ -56,7 +56,7 @@
|
|||
"vaadin-date-picker": "vaadin/vaadin-date-picker#^2.0.0",
|
||||
"web-animations-js": "^2.2.5",
|
||||
"webcomponentsjs": "^1.0.10",
|
||||
"chart.js": "~2.7.1",
|
||||
"chart.js": "~2.7.2",
|
||||
"moment": "^2.20.0",
|
||||
"chartjs-chart-timeline": "fanthos/chartjs-chart-timeline#^0.1.4",
|
||||
"chartjs-plugin-zoom": "^0.6.3",
|
||||
|
|
|
@ -7,70 +7,60 @@
|
|||
// Use minified(Chart.min.js) version to fix strange color after uglify
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
/* global Chart moment Color Hammer */
|
||||
{
|
||||
// This function add a new interaction mode to Chart.js that
|
||||
// returns one point for every dataset.
|
||||
Chart.Interaction.modes.neareach = function (chart, e, options) {
|
||||
const getRange = {
|
||||
x: (a, b) => Math.abs(a.x - b.x),
|
||||
y: (a, b) => Math.abs(a.y - b.y),
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
xy: (a, b) => Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2),
|
||||
|
||||
// This function add a new interaction mode to Chart.js that
|
||||
// returns one point for every dataset.
|
||||
Chart.Interaction.modes.neareach = function (chart, e, options) {
|
||||
const getRange = {
|
||||
x: (a, b) => Math.abs(a.x - b.x),
|
||||
y: (a, b) => Math.abs(a.y - b.y),
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
xy: (a, b) => Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2),
|
||||
};
|
||||
const getRangeMax = {
|
||||
x: r => r,
|
||||
y: r => r,
|
||||
xy: r => r * r,
|
||||
};
|
||||
let position;
|
||||
if (e.native) {
|
||||
position = {
|
||||
x: e.x,
|
||||
y: e.y
|
||||
};
|
||||
const getRangeMax = {
|
||||
x: r => r,
|
||||
y: r => r,
|
||||
xy: r => r * r,
|
||||
};
|
||||
let position;
|
||||
if (e.native) {
|
||||
position = {
|
||||
x: e.x,
|
||||
y: e.y
|
||||
};
|
||||
} else {
|
||||
position = Chart.helpers.getRelativePosition(e, chart);
|
||||
} else {
|
||||
position = Chart.helpers.getRelativePosition(e, chart);
|
||||
}
|
||||
const elements = [];
|
||||
const elementsRange = [];
|
||||
const datasets = chart.data.datasets;
|
||||
let meta;
|
||||
options.axis = options.axis || 'xy';
|
||||
const rangeFunc = getRange[options.axis];
|
||||
const rangeMaxFunc = getRangeMax[options.axis];
|
||||
|
||||
for (let i = 0, ilen = datasets.length; i < ilen; ++i) {
|
||||
if (!chart.isDatasetVisible(i)) {
|
||||
continue;
|
||||
}
|
||||
const elements = [];
|
||||
const elementsRange = [];
|
||||
const datasets = chart.data.datasets;
|
||||
let meta;
|
||||
options.axis = options.axis || 'xy';
|
||||
const rangeFunc = getRange[options.axis];
|
||||
const rangeMaxFunc = getRangeMax[options.axis];
|
||||
|
||||
for (let i = 0, ilen = datasets.length; i < ilen; ++i) {
|
||||
if (!chart.isDatasetVisible(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
meta = chart.getDatasetMeta(i);
|
||||
for (let j = 0, jlen = meta.data.length; j < jlen; ++j) {
|
||||
const element = meta.data[j];
|
||||
if (!element._view.skip) {
|
||||
const vm = element._view;
|
||||
const range = rangeFunc(vm, position);
|
||||
const oldRange = elementsRange[i];
|
||||
if (range < rangeMaxFunc(vm.radius + vm.hitRadius)) {
|
||||
if (oldRange === undefined || oldRange > range) {
|
||||
elementsRange[i] = range;
|
||||
elements[i] = element;
|
||||
}
|
||||
meta = chart.getDatasetMeta(i);
|
||||
for (let j = 0, jlen = meta.data.length; j < jlen; ++j) {
|
||||
const element = meta.data[j];
|
||||
if (!element._view.skip) {
|
||||
const vm = element._view;
|
||||
const range = rangeFunc(vm, position);
|
||||
const oldRange = elementsRange[i];
|
||||
if (range < rangeMaxFunc(vm.radius + vm.hitRadius)) {
|
||||
if (oldRange === undefined || oldRange > range) {
|
||||
elementsRange[i] = range;
|
||||
elements[i] = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const ret = elements.filter(n => n !== undefined);
|
||||
return ret;
|
||||
};
|
||||
|
||||
// Fix infinite loop bug in Chart.js 2.7.1
|
||||
const x = Chart.scaleService.constructors.time.prototype;
|
||||
x._getLabelCapacity = x.getLabelCapacity;
|
||||
x.getLabelCapacity = function () {
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
const ret = this._getLabelCapacity.apply(this, arguments);
|
||||
return ret > 0 ? ret : 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
const ret = elements.filter(n => n !== undefined);
|
||||
return ret;
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue