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.2 to 1.1.3

book.json

5

dist/chartjs-plugin-crosshair.js

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

* http://abelheinsbroek.nl/
* Version: 1.1.0
* Version: 1.1.3
*

@@ -111,3 +111,4 @@ * Copyright 2019 Abel Heinsbroek

}
}
},
_chart: chart
};

@@ -114,0 +115,0 @@

4

dist/chartjs-plugin-crosshair.min.js

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

* http://abelheinsbroek.nl/
* Version: 1.1.0
* Version: 1.1.3
*

@@ -12,2 +12,2 @@ * Copyright 2019 Abel Heinsbroek

*/
!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,b,S,a;(y=t).Interaction.modes.interpolate=function(t,e,a){for(var s=[],i=0;i<t.data.datasets.length;i++)if(t.data.datasets[i].interpolate){var o=t.getDatasetMeta(i);if(!o.hidden){var r=t.scales[o.xAxisID],n=t.scales[o.yAxisID],l=r.getValueForPixel(e.x),c=t.data.datasets[i].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[i].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:i,_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},b=(e=t).helpers,S={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){if(0!=a.config.options.scales.xAxes.length){var t=a.config.options.scales.xAxes[0].type;"linear"!==t&&"time"!==t||(void 0===a.options.plugins.crosshair&&(a.options.plugins.crosshair=S),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,i=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===i?i-a:t.crosshair.start+e),this.doZoom(t,t.crosshair.start,t.crosshair.end)}},getOption:function(t,e,a){return b.getValueOrDefault(t.options.plugins.crosshair[e]?t.options.plugins.crosshair[e][a]:void 0,S[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 i=void 0===e.original.native.buttons?e.original.native.which:e.original.native.buttons;"mouseup"===e.original.type&&(i=0);var o={type:e.original.type,chart:t,x:s.getPixelForValue(e.xValue),y:e.original.y,native:{buttons:i},stop:!0};t.controller.eventHandler(o)}}},afterEvent:function(t,e){if(0!=t.config.options.scales.xAxes.length){var a=t.config.options.scales.xAxes[0].type;if("linear"===a||"time"===a){var s=this.getXScale(t);if(s){var i=void 0===e.native.buttons?e.native.which:e.native.buttons;"mouseup"===e.native.type&&(i=0);var o=this.getOption(t,"sync","enabled"),r=this.getOption(t,"sync","group");if(!e.stop&&o){var n=new CustomEvent("sync-event");n.chartId=t.id,n.syncGroup=r,n.original=e,n.xValue=s.getValueForPixel(e.x),window.dispatchEvent(n)}var l=this.getOption(t,"sync","suppressTooltips");if(t.crosshair.suppressTooltips=e.stop&&l,t.crosshair.enabled="mouseout"!==e.type&&e.x>s.getPixelForValue(s.min)&&e.x<s.getPixelForValue(s.max),!t.crosshair.enabled)return e.x>s.getPixelForValue(s.max)&&t.update(),!0;var c=this.getOption(t,"zoom","enabled");if(1===i&&!t.crosshair.dragStarted&&c&&(t.crosshair.dragStartX=e.x,t.crosshair.dragStarted=!0),t.crosshair.dragStarted&&0===i){t.crosshair.dragStarted=!1;var d=s.getValueForPixel(t.crosshair.dragStartX),h=s.getValueForPixel(t.crosshair.x);1<Math.abs(t.crosshair.dragStartX-t.crosshair.x)&&this.doZoom(t,d,h),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 i="ticks";t.options.scales.xAxes[0].time&&(i="time"),t.crosshair.originalXRange.min?(t.options.scales.xAxes[0][i].min=t.crosshair.originalXRange.min,t.crosshair.originalXRange.min=null):delete t.options.scales.xAxes[0][i].min,t.crosshair.originalXRange.max?(t.options.scales.xAxes[0][i].max=t.crosshair.originalXRange.max,t.crosshair.originalXRange.max=null):delete t.options.scales.xAxes[0][i].max}t.crosshair.button&&t.crosshair.button.parentNode&&(t.crosshair.button.parentNode.removeChild(t.crosshair.button),t.crosshair.button=!1);var o=this.getOption(t,"sync","enabled");if(!e&&a&&o){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 s=e;e=a,a=s}if(!b.getValueOrDefault(t.options.plugins.crosshair.callbacks?t.options.plugins.crosshair.callbacks.beforeZoom:void 0,S.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 i=document.createElement("button"),o=this.getOption(t,"zoom","zoomButtonText"),r=this.getOption(t,"zoom","zoomButtonClass"),n=document.createTextNode(o);i.appendChild(n),i.className=r,i.addEventListener("click",function(){this.resetZoom(t)}.bind(this)),t.canvas.parentNode.appendChild(i),t.crosshair.button=i}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=[],h=0,x=!1,u=!1;l&&(t.crosshair.originalData[c]=t.data.datasets[c].data);for(var g=t.crosshair.originalData[c],p=0;p<g.length;p++){var m=g[p],f=this.getXScale(t).getRightValue(m);e&&!x&&0<h&&(d.push(g[h-1]),x=!0),(f=e&&m.x<=a)&&d.push(m),a<f&&!u&&h<g.length&&(d.push(m),u=!0),h+=1}t.data.datasets[c].data=d}if(t.crosshair.start=e,t.crosshair.end=a,l){var v=this.getXScale(t);t.crosshair.min=v.min,t.crosshair.max=v.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),i=t.scales[s.yAxisID];!s.hidden&&a.interpolate&&(t.ctx.beginPath(),t.ctx.arc(t.crosshair.x,i.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),i=t.scales[s.xAxisID].getValueForPixel(t.crosshair.x);if(!s.hidden&&a.interpolate){var o=a.data,r=o.findIndex(function(t){return t.x>=i}),n=o[r-1],l=o[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+(i-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,b,S,a;(y=t).Interaction.modes.interpolate=function(t,e,a){for(var s=[],i=0;i<t.data.datasets.length;i++)if(t.data.datasets[i].interpolate){var o=t.getDatasetMeta(i);if(!o.hidden){var r=t.scales[o.xAxisID],n=t.scales[o.yAxisID],l=r.getValueForPixel(e.x),c=t.data.datasets[i].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[i].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:i,_index:s.length,_xScale:{getLabelForIndex:function(t){return s[t].xValue}},_yScale:{getLabelForIndex:function(t){return s[t].value}},_chart:t};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},b=(e=t).helpers,S={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){if(0!=a.config.options.scales.xAxes.length){var t=a.config.options.scales.xAxes[0].type;"linear"!==t&&"time"!==t||(void 0===a.options.plugins.crosshair&&(a.options.plugins.crosshair=S),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,i=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===i?i-a:t.crosshair.start+e),this.doZoom(t,t.crosshair.start,t.crosshair.end)}},getOption:function(t,e,a){return b.getValueOrDefault(t.options.plugins.crosshair[e]?t.options.plugins.crosshair[e][a]:void 0,S[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 i=void 0===e.original.native.buttons?e.original.native.which:e.original.native.buttons;"mouseup"===e.original.type&&(i=0);var o={type:e.original.type,chart:t,x:s.getPixelForValue(e.xValue),y:e.original.y,native:{buttons:i},stop:!0};t.controller.eventHandler(o)}}},afterEvent:function(t,e){if(0!=t.config.options.scales.xAxes.length){var a=t.config.options.scales.xAxes[0].type;if("linear"===a||"time"===a){var s=this.getXScale(t);if(s){var i=void 0===e.native.buttons?e.native.which:e.native.buttons;"mouseup"===e.native.type&&(i=0);var o=this.getOption(t,"sync","enabled"),r=this.getOption(t,"sync","group");if(!e.stop&&o){var n=new CustomEvent("sync-event");n.chartId=t.id,n.syncGroup=r,n.original=e,n.xValue=s.getValueForPixel(e.x),window.dispatchEvent(n)}var l=this.getOption(t,"sync","suppressTooltips");if(t.crosshair.suppressTooltips=e.stop&&l,t.crosshair.enabled="mouseout"!==e.type&&e.x>s.getPixelForValue(s.min)&&e.x<s.getPixelForValue(s.max),!t.crosshair.enabled)return e.x>s.getPixelForValue(s.max)&&t.update(),!0;var c=this.getOption(t,"zoom","enabled");if(1===i&&!t.crosshair.dragStarted&&c&&(t.crosshair.dragStartX=e.x,t.crosshair.dragStarted=!0),t.crosshair.dragStarted&&0===i){t.crosshair.dragStarted=!1;var d=s.getValueForPixel(t.crosshair.dragStartX),h=s.getValueForPixel(t.crosshair.x);1<Math.abs(t.crosshair.dragStartX-t.crosshair.x)&&this.doZoom(t,d,h),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 i="ticks";t.options.scales.xAxes[0].time&&(i="time"),t.crosshair.originalXRange.min?(t.options.scales.xAxes[0][i].min=t.crosshair.originalXRange.min,t.crosshair.originalXRange.min=null):delete t.options.scales.xAxes[0][i].min,t.crosshair.originalXRange.max?(t.options.scales.xAxes[0][i].max=t.crosshair.originalXRange.max,t.crosshair.originalXRange.max=null):delete t.options.scales.xAxes[0][i].max}t.crosshair.button&&t.crosshair.button.parentNode&&(t.crosshair.button.parentNode.removeChild(t.crosshair.button),t.crosshair.button=!1);var o=this.getOption(t,"sync","enabled");if(!e&&a&&o){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 s=e;e=a,a=s}if(!b.getValueOrDefault(t.options.plugins.crosshair.callbacks?t.options.plugins.crosshair.callbacks.beforeZoom:void 0,S.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 i=document.createElement("button"),o=this.getOption(t,"zoom","zoomButtonText"),r=this.getOption(t,"zoom","zoomButtonClass"),n=document.createTextNode(o);i.appendChild(n),i.className=r,i.addEventListener("click",function(){this.resetZoom(t)}.bind(this)),t.canvas.parentNode.appendChild(i),t.crosshair.button=i}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=[],h=0,x=!1,u=!1;l&&(t.crosshair.originalData[c]=t.data.datasets[c].data);for(var g=t.crosshair.originalData[c],p=0;p<g.length;p++){var m=g[p],f=this.getXScale(t).getRightValue(m);e&&!x&&0<h&&(d.push(g[h-1]),x=!0),(f=e&&m.x<=a)&&d.push(m),a<f&&!u&&h<g.length&&(d.push(m),u=!0),h+=1}t.data.datasets[c].data=d}if(t.crosshair.start=e,t.crosshair.end=a,l){var v=this.getXScale(t);t.crosshair.min=v.min,t.crosshair.max=v.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),i=t.scales[s.yAxisID];!s.hidden&&a.interpolate&&(t.ctx.beginPath(),t.ctx.arc(t.crosshair.x,i.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),i=t.scales[s.xAxisID].getValueForPixel(t.crosshair.x);if(!s.hidden&&a.interpolate){var o=a.data,r=o.findIndex(function(t){return t.x>=i}),n=o[r-1],l=o[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+(i-n.x)*c}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.2",
"version": "1.1.3",
"license": "MIT",

@@ -34,4 +34,7 @@ "main": "dist/chartjs-plugin-crosshair.js",

"peerDependencies": {
"chart.js": ">= 2.6.0 < 3"
"chart.js": ">= 2.8.0 < 3"
},
"dependencies": {
"chart.js": "^2.8.0"
}
}

@@ -92,3 +92,4 @@ export default function(Chart) {

}
}
},
_chart: chart
};

@@ -95,0 +96,0 @@

@@ -36,3 +36,11 @@ export default function(Chart) {

if (chart.config.type !== 'scatter' && chart.config.type !== 'line') {
if (chart.config.options.scales.xAxes.length == 0) {
return
}
var xScaleType = chart.config.options.scales.xAxes[0].type
if (xScaleType !== 'linear' && xScaleType !== 'time') {
return;

@@ -159,3 +167,10 @@ }

if (chart.config.type !== 'scatter' && chart.config.type !== 'line') {
if (chart.config.options.scales.xAxes.length == 0) {
return
}
var xScaleType = chart.config.options.scales.xAxes[0].type
if (xScaleType !== 'linear' && xScaleType !== 'time') {
return;

@@ -392,12 +407,13 @@ }

var oldData = sourceDataset[oldDataIndex];
var oldDataX = this.getXScale(chart).getRightValue(oldData)
// append one value outside of bounds
if (oldData.x >= start && !started && index > 0) {
if (oldDataX = start && !started && index > 0) {
newData.push(sourceDataset[index - 1]);
started = true;
}
if (oldData.x >= start && oldData.x <= end) {
if (oldDataX = start && oldData.x <= end) {
newData.push(oldData);
}
if (oldData.x > end && !stop && index < sourceDataset.length) {
if (oldDataX > end && !stop && index < sourceDataset.length) {
newData.push(oldData);

@@ -404,0 +420,0 @@ stop = true;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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