Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chartjs-plugin-crosshair

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-plugin-crosshair - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

62

dist/chartjs-plugin-crosshair.js

@@ -5,5 +5,5 @@ /*

* http://abelheinsbroek.nl/
* Version: 1.0.9
* Version: 1.1.1
*
* Copyright 2018 Abel Heinsbroek
* Copyright 2019 Abel Heinsbroek
* Released under the MIT license

@@ -207,2 +207,3 @@ * https://github.com/abelheinsbroek/chartjs-plugin-crosshair/blob/master/LICENSE.md

chart.panZoom = this.panZoom.bind(this, chart);
},

@@ -218,2 +219,20 @@

panZoom: function(chart, increment) {
if (chart.crosshair.originalData.length === 0) {
return;
}
var diff = chart.crosshair.end - chart.crosshair.start;
var min = chart.crosshair.min;
var max = chart.crosshair.max;
if (increment < 0) { // left
chart.crosshair.start = Math.max(chart.crosshair.start + increment, min);
chart.crosshair.end = chart.crosshair.start === min ? min + diff : chart.crosshair.end + increment;
} else { // right
chart.crosshair.end = Math.min(chart.crosshair.end + increment, chart.crosshair.max);
chart.crosshair.start = chart.crosshair.end === max ? max - diff : chart.crosshair.start + increment;
}
this.doZoom(chart, chart.crosshair.start, chart.crosshair.end);
},
getOption: function(chart, category, name) {

@@ -224,3 +243,3 @@ return helpers.getValueOrDefault(chart.options.plugins.crosshair[category] ? chart.options.plugins.crosshair[category][name] : undefined, defaultOptions[category][name]);

getXScale: function(chart) {
return chart.scales[chart.getDatasetMeta(0).xAxisID];
return chart.data.datasets.length ? chart.scales[chart.getDatasetMeta(0).xAxisID] : null;
},

@@ -247,2 +266,6 @@ getYScale: function(chart) {

if (!xScale) {
return;
}
// Safari fix

@@ -275,2 +298,8 @@ var buttons = (e.original.native.buttons === undefined ? e.original.native.which : e.original.native.buttons);

if (!xScale) {
return;
}
// fix for Safari

@@ -479,7 +508,5 @@ var buttons = (e.native.buttons === undefined ? e.native.which : e.native.buttons);

var storeOriginals = (chart.crosshair.originalData.length === 0) ? true : false;
// filter dataset
for (var datasetIndex = 0; datasetIndex < chart.data.datasets.length; datasetIndex++) {
var dataset = chart.data.datasets[datasetIndex];
var newData = [];

@@ -490,14 +517,15 @@

var stop = false;
if (storeOriginals) {
chart.crosshair.originalData[datasetIndex] = dataset.data;
chart.crosshair.originalData[datasetIndex] = chart.data.datasets[datasetIndex].data;
}
for (var oldDataIndex = 0; oldDataIndex < dataset.data.length; oldDataIndex++) {
var sourceDataset = chart.crosshair.originalData[datasetIndex];
var oldData = dataset.data[oldDataIndex];
for (var oldDataIndex = 0; oldDataIndex < sourceDataset.length; oldDataIndex++) {
var oldData = sourceDataset[oldDataIndex];
// append one value outside of bounds
if (oldData.x >= start && !started && index > 0) {
newData.push(dataset.data[index - 1]);
newData.push(sourceDataset[index - 1]);
started = true;

@@ -508,3 +536,3 @@ }

}
if (oldData.x > end && !stop && index < dataset.data.length) {
if (oldData.x > end && !stop && index < sourceDataset.length) {
newData.push(oldData);

@@ -515,5 +543,15 @@ stop = true;

}
dataset.data = newData;
chart.data.datasets[datasetIndex].data = newData;
}
chart.crosshair.start = start;
chart.crosshair.end = end;
if (storeOriginals) {
var xAxes = this.getXScale(chart);
chart.crosshair.min = xAxes.min;
chart.crosshair.max = xAxes.max;
}
chart.update();

@@ -520,0 +558,0 @@

6

dist/chartjs-plugin-crosshair.min.js

@@ -5,8 +5,8 @@ /*

* http://abelheinsbroek.nl/
* Version: 1.0.9
* Version: 1.1.1
*
* Copyright 2018 Abel Heinsbroek
* Copyright 2019 Abel Heinsbroek
* Released under the MIT license
* https://github.com/abelheinsbroek/chartjs-plugin-crosshair/blob/master/LICENSE.md
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e(t.Chart)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var y,e,f,v,a;(y=t).Interaction.modes.interpolate=function(t,e,a){for(var o=[],s=0;s<t.data.datasets.length;s++)if(t.data.datasets[s].interpolate){var i=t.getDatasetMeta(s);if(!i.hidden){var r=t.scales[i.xAxisID],n=t.scales[i.yAxisID],l=r.getValueForPixel(e.x),c=t.data.datasets[s].data,d=c.findIndex(function(t){return t.x>=l});if(-1!==d){var h=c[d-1],x=c[d];if(h&&x)var u=(x.y-h.y)/(x.x-h.x),g=h.y+(l-h.x)*u;if(t.data.datasets[s].steppedLine&&h&&(g=h.y),!isNaN(g)){var p=n.getPixelForValue(g);if(!isNaN(p)){var m={value:g,xValue:l,tooltipPosition:function(){return this._model},hasValue:function(){return!0},_model:{x:e.x,y:p},_datasetIndex:s,_index:o.length,_xScale:{getLabelForIndex:function(t){return o[t].xValue}},_yScale:{getLabelForIndex:function(t){return o[t].value}}};o.push(m)}}}}}var f=y.Interaction.modes.x(t,e,a);for(d=0;d<f.length;d++){var v=f[d];t.data.datasets[v._datasetIndex].interpolate||o.push(v)}return o},f=(e=t).helpers,v={line:{color:"#F66",width:1},sync:{enabled:!0,group:1,suppressTooltips:!1},zoom:{enabled:!0,zoomboxBackgroundColor:"rgba(66,133,244,0.2)",zoomboxBorderColor:"#48F",zoomButtonText:"Reset Zoom",zoomButtonClass:"reset-zoom"},callbacks:{beforeZoom:function(t,e){return!0},afterZoom:function(t,e){}}},a={id:"crosshair",afterInit:function(a){"scatter"!==a.config.type&&"line"!==a.config.type||(void 0===a.options.plugins.crosshair&&(a.options.plugins.crosshair=v),a.crosshair={enabled:!1,x:null,originalData:[],originalXRange:{},dragStarted:!1,dragStartX:null,dragEndX:null,suppressTooltips:!1,reset:function(){this.resetZoom(a,!1,!1)}.bind(this)},this.getOption(a,"sync","enabled")&&(a.crosshair.syncEventHandler=function(t){this.handleSyncEvent(a,t)}.bind(this),a.crosshair.resetZoomEventHandler=function(t){var e=this.getOption(a,"sync","group");t.chartId!==a.id&&t.syncGroup===e&&this.resetZoom(a,!0)}.bind(this),window.addEventListener("sync-event",a.crosshair.syncEventHandler),window.addEventListener("reset-zoom-event",a.crosshair.resetZoomEventHandler)))},destroy:function(t){this.getOption(t,"sync","enabled")&&(window.removeEventListener("sync-event",t.crosshair.syncEventHandler),window.removeEventListener("reset-zoom-event",t.crosshair.resetZoomEventHandler))},getOption:function(t,e,a){return f.getValueOrDefault(t.options.plugins.crosshair[e]?t.options.plugins.crosshair[e][a]:void 0,v[e][a])},getXScale:function(t){return t.scales[t.getDatasetMeta(0).xAxisID]},getYScale:function(t){return t.scales[t.getDatasetMeta(0).yAxisID]},handleSyncEvent:function(t,e){var a=this.getOption(t,"sync","group");if(e.chartId!==t.id&&e.syncGroup===a){var o=this.getXScale(t),s=void 0===e.original.native.buttons?e.original.native.which:e.original.native.buttons;"mouseup"===e.original.type&&(s=0);var i={type:e.original.type,chart:t,x:o.getPixelForValue(e.xValue),y:e.original.y,native:{buttons:s},stop:!0};t.controller.eventHandler(i)}},afterEvent:function(t,e){if("scatter"===t.config.type||"line"===t.config.type){var a=this.getXScale(t),o=void 0===e.native.buttons?e.native.which:e.native.buttons;"mouseup"===e.native.type&&(o=0);var s=this.getOption(t,"sync","enabled"),i=this.getOption(t,"sync","group");if(!e.stop&&s){var r=new CustomEvent("sync-event");r.chartId=t.id,r.syncGroup=i,r.original=e,r.xValue=a.getValueForPixel(e.x),window.dispatchEvent(r)}var n=this.getOption(t,"sync","suppressTooltips");if(t.crosshair.suppressTooltips=e.stop&&n,t.crosshair.enabled="mouseout"!==e.type&&e.x>a.getPixelForValue(a.min)&&e.x<a.getPixelForValue(a.max),!t.crosshair.enabled)return e.x>a.getPixelForValue(a.max)&&t.update(),!0;var l=this.getOption(t,"zoom","enabled");if(1===o&&!t.crosshair.dragStarted&&l&&(t.crosshair.dragStartX=e.x,t.crosshair.dragStarted=!0),t.crosshair.dragStarted&&0===o){t.crosshair.dragStarted=!1;var c=a.getValueForPixel(t.crosshair.dragStartX),d=a.getValueForPixel(t.crosshair.x);1<Math.abs(t.crosshair.dragStartX-t.crosshair.x)&&this.doZoom(t,c,d),t.update()}t.crosshair.x=e.x,t.draw()}},afterDraw:function(t){if(t.crosshair.enabled)return t.crosshair.dragStarted?this.drawZoombox(t):(this.drawTraceLine(t),this.interpolateValues(t),this.drawTracePoints(t)),!0},beforeTooltipDraw:function(t){return!t.crosshair.dragStarted&&!t.crosshair.suppressTooltips},resetZoom:function(t){var e=1<arguments.length&&void 0!==arguments[1]&&arguments[1],a=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];if(a){for(var o=0;o<t.data.datasets.length;o++)t.data.datasets[o].data=t.crosshair.originalData.shift(0);var s="ticks";t.options.scales.xAxes[0].time&&(s="time"),t.crosshair.originalXRange.min?(t.options.scales.xAxes[0][s].min=t.crosshair.originalXRange.min,t.crosshair.originalXRange.min=null):delete t.options.scales.xAxes[0][s].min,t.crosshair.originalXRange.max?(t.options.scales.xAxes[0][s].max=t.crosshair.originalXRange.max,t.crosshair.originalXRange.max=null):delete t.options.scales.xAxes[0][s].max}t.crosshair.button&&t.crosshair.button.parentNode&&(t.crosshair.button.parentNode.removeChild(t.crosshair.button),t.crosshair.button=!1);var i=this.getOption(t,"sync","enabled");if(!e&&a&&i){var r=this.getOption(t,"sync","group"),n=new CustomEvent("reset-zoom-event");n.chartId=t.id,n.syncGroup=r,window.dispatchEvent(n)}if(a){var l=t.options.animation;t.options.animation=!1,t.update(),t.options.animation=l}},doZoom:function(t,e,a){if(a<e){var o=e;e=a,a=o}if(!f.getValueOrDefault(t.options.plugins.crosshair.callbacks?t.options.plugins.crosshair.callbacks.beforeZoom:void 0,v.callbacks.beforeZoom)(e,a))return!1;if("time"===t.options.scales.xAxes[0].type?(t.options.scales.xAxes[0].time.min&&0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.min=t.options.scales.xAxes[0].time.min),t.options.scales.xAxes[0].time.max&&0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.max=t.options.scales.xAxes[0].time.max)):(t.options.scales.xAxes[0].ticks.min&&void 0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.min=t.options.scales.xAxes[0].ticks.min),t.options.scales.xAxes[0].ticks.max&&void 0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.max=t.options.scales.xAxes[0].ticks.max)),!t.crosshair.button){var s=document.createElement("button"),i=this.getOption(t,"zoom","zoomButtonText"),r=this.getOption(t,"zoom","zoomButtonClass"),n=document.createTextNode(i);s.appendChild(n),s.className=r,s.addEventListener("click",function(){this.resetZoom(t)}.bind(this)),t.canvas.parentNode.appendChild(s),t.crosshair.button=s}t.options.scales.xAxes[0].time?(t.options.scales.xAxes[0].time.min=e,t.options.scales.xAxes[0].time.max=a):(t.options.scales.xAxes[0].ticks.min=e,t.options.scales.xAxes[0].ticks.max=a);for(var l=0===t.crosshair.originalData.length,c=0;c<t.data.datasets.length;c++){var d=t.data.datasets[c],h=[],x=0,u=!1,g=!1;l&&(t.crosshair.originalData[c]=d.data);for(var p=0;p<d.data.length;p++){var m=d.data[p];m.x>=e&&!u&&0<x&&(h.push(d.data[x-1]),u=!0),m.x>=e&&m.x<=a&&h.push(m),m.x>a&&!g&&x<d.data.length&&(h.push(m),g=!0),x+=1}d.data=h}t.update(),this.getOption(t,"callbacks","afterZoom")(e,a)},drawZoombox:function(t){var e=this.getYScale(t),a=this.getOption(t,"zoom","zoomboxBorderColor"),o=this.getOption(t,"zoom","zoomboxBackgroundColor");t.ctx.beginPath(),t.ctx.rect(t.crosshair.dragStartX,e.getPixelForValue(e.max),t.crosshair.x-t.crosshair.dragStartX,e.getPixelForValue(e.min)-e.getPixelForValue(e.max)),t.ctx.lineWidth=1,t.ctx.strokeStyle=a,t.ctx.fillStyle=o,t.ctx.fill(),t.ctx.fillStyle="",t.ctx.stroke(),t.ctx.closePath()},drawTraceLine:function(t){var e=this.getYScale(t),a=this.getOption(t,"line","width"),o=this.getOption(t,"line","color");t.ctx.beginPath(),t.ctx.moveTo(t.crosshair.x,e.getPixelForValue(e.max)),t.ctx.lineWidth=a,t.ctx.strokeStyle=o,t.ctx.lineTo(t.crosshair.x,e.getPixelForValue(e.min)),t.ctx.stroke()},drawTracePoints:function(t){for(var e=0;e<t.data.datasets.length;e++){var a=t.data.datasets[e],o=t.getDatasetMeta(e),s=t.scales[o.yAxisID];!o.hidden&&a.interpolate&&(t.ctx.beginPath(),t.ctx.arc(t.crosshair.x,s.getPixelForValue(a.interpolatedValue),3,0,2*Math.PI,!1),t.ctx.fillStyle="white",t.ctx.lineWidth=2,t.ctx.strokeStyle=a.borderColor,t.ctx.fill(),t.ctx.stroke())}},interpolateValues:function(t){for(var e=0;e<t.data.datasets.length;e++){var a=t.data.datasets[e],o=t.getDatasetMeta(e),s=t.scales[o.xAxisID].getValueForPixel(t.crosshair.x);if(!o.hidden&&a.interpolate){var i=a.data,r=i.findIndex(function(t){return t.x>=s}),n=i[r-1],l=i[r];if(t.data.datasets[e].steppedLine&&n)a.interpolatedValue=n.y;else if(n&&l){var c=(l.y-n.y)/(l.x-n.x);a.interpolatedValue=n.y+(s-n.x)*c}else a.interpolatedValue=NaN}}}},e.plugins.register(a)});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e(t.Chart)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var y,e,v,b,a;(y=t).Interaction.modes.interpolate=function(t,e,a){for(var s=[],o=0;o<t.data.datasets.length;o++)if(t.data.datasets[o].interpolate){var i=t.getDatasetMeta(o);if(!i.hidden){var r=t.scales[i.xAxisID],n=t.scales[i.yAxisID],c=r.getValueForPixel(e.x),l=t.data.datasets[o].data,d=l.findIndex(function(t){return t.x>=c});if(-1!==d){var h=l[d-1],x=l[d];if(h&&x)var u=(x.y-h.y)/(x.x-h.x),g=h.y+(c-h.x)*u;if(t.data.datasets[o].steppedLine&&h&&(g=h.y),!isNaN(g)){var p=n.getPixelForValue(g);if(!isNaN(p)){var m={value:g,xValue:c,tooltipPosition:function(){return this._model},hasValue:function(){return!0},_model:{x:e.x,y:p},_datasetIndex:o,_index:s.length,_xScale:{getLabelForIndex:function(t){return s[t].xValue}},_yScale:{getLabelForIndex:function(t){return s[t].value}}};s.push(m)}}}}}var f=y.Interaction.modes.x(t,e,a);for(d=0;d<f.length;d++){var v=f[d];t.data.datasets[v._datasetIndex].interpolate||s.push(v)}return s},v=(e=t).helpers,b={line:{color:"#F66",width:1},sync:{enabled:!0,group:1,suppressTooltips:!1},zoom:{enabled:!0,zoomboxBackgroundColor:"rgba(66,133,244,0.2)",zoomboxBorderColor:"#48F",zoomButtonText:"Reset Zoom",zoomButtonClass:"reset-zoom"},callbacks:{beforeZoom:function(t,e){return!0},afterZoom:function(t,e){}}},a={id:"crosshair",afterInit:function(a){"scatter"!==a.config.type&&"line"!==a.config.type||(void 0===a.options.plugins.crosshair&&(a.options.plugins.crosshair=b),a.crosshair={enabled:!1,x:null,originalData:[],originalXRange:{},dragStarted:!1,dragStartX:null,dragEndX:null,suppressTooltips:!1,reset:function(){this.resetZoom(a,!1,!1)}.bind(this)},this.getOption(a,"sync","enabled")&&(a.crosshair.syncEventHandler=function(t){this.handleSyncEvent(a,t)}.bind(this),a.crosshair.resetZoomEventHandler=function(t){var e=this.getOption(a,"sync","group");t.chartId!==a.id&&t.syncGroup===e&&this.resetZoom(a,!0)}.bind(this),window.addEventListener("sync-event",a.crosshair.syncEventHandler),window.addEventListener("reset-zoom-event",a.crosshair.resetZoomEventHandler)),a.panZoom=this.panZoom.bind(this,a))},destroy:function(t){this.getOption(t,"sync","enabled")&&(window.removeEventListener("sync-event",t.crosshair.syncEventHandler),window.removeEventListener("reset-zoom-event",t.crosshair.resetZoomEventHandler))},panZoom:function(t,e){if(0!==t.crosshair.originalData.length){var a=t.crosshair.end-t.crosshair.start,s=t.crosshair.min,o=t.crosshair.max;e<0?(t.crosshair.start=Math.max(t.crosshair.start+e,s),t.crosshair.end=t.crosshair.start===s?s+a:t.crosshair.end+e):(t.crosshair.end=Math.min(t.crosshair.end+e,t.crosshair.max),t.crosshair.start=t.crosshair.end===o?o-a:t.crosshair.start+e),this.doZoom(t,t.crosshair.start,t.crosshair.end)}},getOption:function(t,e,a){return v.getValueOrDefault(t.options.plugins.crosshair[e]?t.options.plugins.crosshair[e][a]:void 0,b[e][a])},getXScale:function(t){return t.data.datasets.length?t.scales[t.getDatasetMeta(0).xAxisID]:null},getYScale:function(t){return t.scales[t.getDatasetMeta(0).yAxisID]},handleSyncEvent:function(t,e){var a=this.getOption(t,"sync","group");if(e.chartId!==t.id&&e.syncGroup===a){var s=this.getXScale(t);if(s){var o=void 0===e.original.native.buttons?e.original.native.which:e.original.native.buttons;"mouseup"===e.original.type&&(o=0);var i={type:e.original.type,chart:t,x:s.getPixelForValue(e.xValue),y:e.original.y,native:{buttons:o},stop:!0};t.controller.eventHandler(i)}}},afterEvent:function(t,e){if("scatter"===t.config.type||"line"===t.config.type){var a=this.getXScale(t);if(a){var s=void 0===e.native.buttons?e.native.which:e.native.buttons;"mouseup"===e.native.type&&(s=0);var o=this.getOption(t,"sync","enabled"),i=this.getOption(t,"sync","group");if(!e.stop&&o){var r=new CustomEvent("sync-event");r.chartId=t.id,r.syncGroup=i,r.original=e,r.xValue=a.getValueForPixel(e.x),window.dispatchEvent(r)}var n=this.getOption(t,"sync","suppressTooltips");if(t.crosshair.suppressTooltips=e.stop&&n,t.crosshair.enabled="mouseout"!==e.type&&e.x>a.getPixelForValue(a.min)&&e.x<a.getPixelForValue(a.max),!t.crosshair.enabled)return e.x>a.getPixelForValue(a.max)&&t.update(),!0;var c=this.getOption(t,"zoom","enabled");if(1===s&&!t.crosshair.dragStarted&&c&&(t.crosshair.dragStartX=e.x,t.crosshair.dragStarted=!0),t.crosshair.dragStarted&&0===s){t.crosshair.dragStarted=!1;var l=a.getValueForPixel(t.crosshair.dragStartX),d=a.getValueForPixel(t.crosshair.x);1<Math.abs(t.crosshair.dragStartX-t.crosshair.x)&&this.doZoom(t,l,d),t.update()}t.crosshair.x=e.x,t.draw()}}},afterDraw:function(t){if(t.crosshair.enabled)return t.crosshair.dragStarted?this.drawZoombox(t):(this.drawTraceLine(t),this.interpolateValues(t),this.drawTracePoints(t)),!0},beforeTooltipDraw:function(t){return!t.crosshair.dragStarted&&!t.crosshair.suppressTooltips},resetZoom:function(t){var e=1<arguments.length&&void 0!==arguments[1]&&arguments[1],a=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];if(a){for(var s=0;s<t.data.datasets.length;s++)t.data.datasets[s].data=t.crosshair.originalData.shift(0);var o="ticks";t.options.scales.xAxes[0].time&&(o="time"),t.crosshair.originalXRange.min?(t.options.scales.xAxes[0][o].min=t.crosshair.originalXRange.min,t.crosshair.originalXRange.min=null):delete t.options.scales.xAxes[0][o].min,t.crosshair.originalXRange.max?(t.options.scales.xAxes[0][o].max=t.crosshair.originalXRange.max,t.crosshair.originalXRange.max=null):delete t.options.scales.xAxes[0][o].max}t.crosshair.button&&t.crosshair.button.parentNode&&(t.crosshair.button.parentNode.removeChild(t.crosshair.button),t.crosshair.button=!1);var i=this.getOption(t,"sync","enabled");if(!e&&a&&i){var r=this.getOption(t,"sync","group"),n=new CustomEvent("reset-zoom-event");n.chartId=t.id,n.syncGroup=r,window.dispatchEvent(n)}if(a){var c=t.options.animation;t.options.animation=!1,t.update(),t.options.animation=c}},doZoom:function(t,e,a){if(a<e){var s=e;e=a,a=s}if(!v.getValueOrDefault(t.options.plugins.crosshair.callbacks?t.options.plugins.crosshair.callbacks.beforeZoom:void 0,b.callbacks.beforeZoom)(e,a))return!1;if("time"===t.options.scales.xAxes[0].type?(t.options.scales.xAxes[0].time.min&&0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.min=t.options.scales.xAxes[0].time.min),t.options.scales.xAxes[0].time.max&&0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.max=t.options.scales.xAxes[0].time.max)):(t.options.scales.xAxes[0].ticks.min&&void 0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.min=t.options.scales.xAxes[0].ticks.min),t.options.scales.xAxes[0].ticks.max&&void 0===t.crosshair.originalData.length&&(t.crosshair.originalXRange.max=t.options.scales.xAxes[0].ticks.max)),!t.crosshair.button){var o=document.createElement("button"),i=this.getOption(t,"zoom","zoomButtonText"),r=this.getOption(t,"zoom","zoomButtonClass"),n=document.createTextNode(i);o.appendChild(n),o.className=r,o.addEventListener("click",function(){this.resetZoom(t)}.bind(this)),t.canvas.parentNode.appendChild(o),t.crosshair.button=o}t.options.scales.xAxes[0].time?(t.options.scales.xAxes[0].time.min=e,t.options.scales.xAxes[0].time.max=a):(t.options.scales.xAxes[0].ticks.min=e,t.options.scales.xAxes[0].ticks.max=a);for(var c=0===t.crosshair.originalData.length,l=0;l<t.data.datasets.length;l++){var d=[],h=0,x=!1,u=!1;c&&(t.crosshair.originalData[l]=t.data.datasets[l].data);for(var g=t.crosshair.originalData[l],p=0;p<g.length;p++){var m=g[p];m.x>=e&&!x&&0<h&&(d.push(g[h-1]),x=!0),m.x>=e&&m.x<=a&&d.push(m),m.x>a&&!u&&h<g.length&&(d.push(m),u=!0),h+=1}t.data.datasets[l].data=d}if(t.crosshair.start=e,t.crosshair.end=a,c){var f=this.getXScale(t);t.crosshair.min=f.min,t.crosshair.max=f.max}t.update(),this.getOption(t,"callbacks","afterZoom")(e,a)},drawZoombox:function(t){var e=this.getYScale(t),a=this.getOption(t,"zoom","zoomboxBorderColor"),s=this.getOption(t,"zoom","zoomboxBackgroundColor");t.ctx.beginPath(),t.ctx.rect(t.crosshair.dragStartX,e.getPixelForValue(e.max),t.crosshair.x-t.crosshair.dragStartX,e.getPixelForValue(e.min)-e.getPixelForValue(e.max)),t.ctx.lineWidth=1,t.ctx.strokeStyle=a,t.ctx.fillStyle=s,t.ctx.fill(),t.ctx.fillStyle="",t.ctx.stroke(),t.ctx.closePath()},drawTraceLine:function(t){var e=this.getYScale(t),a=this.getOption(t,"line","width"),s=this.getOption(t,"line","color");t.ctx.beginPath(),t.ctx.moveTo(t.crosshair.x,e.getPixelForValue(e.max)),t.ctx.lineWidth=a,t.ctx.strokeStyle=s,t.ctx.lineTo(t.crosshair.x,e.getPixelForValue(e.min)),t.ctx.stroke()},drawTracePoints:function(t){for(var e=0;e<t.data.datasets.length;e++){var a=t.data.datasets[e],s=t.getDatasetMeta(e),o=t.scales[s.yAxisID];!s.hidden&&a.interpolate&&(t.ctx.beginPath(),t.ctx.arc(t.crosshair.x,o.getPixelForValue(a.interpolatedValue),3,0,2*Math.PI,!1),t.ctx.fillStyle="white",t.ctx.lineWidth=2,t.ctx.strokeStyle=a.borderColor,t.ctx.fill(),t.ctx.stroke())}},interpolateValues:function(t){for(var e=0;e<t.data.datasets.length;e++){var a=t.data.datasets[e],s=t.getDatasetMeta(e),o=t.scales[s.xAxisID].getValueForPixel(t.crosshair.x);if(!s.hidden&&a.interpolate){var i=a.data,r=i.findIndex(function(t){return t.x>=o}),n=i[r-1],c=i[r];if(t.data.datasets[e].steppedLine&&n)a.interpolatedValue=n.y;else if(n&&c){var l=(c.y-n.y)/(c.x-n.x);a.interpolatedValue=n.y+(o-n.x)*l}else a.interpolatedValue=NaN}}}},e.plugins.register(a)});

@@ -5,3 +5,3 @@ {

"description": "Chart.js plugin to draw and sync vertical crosshair lines",
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",

@@ -8,0 +8,0 @@ "main": "dist/chartjs-plugin-crosshair.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc