chartjs-plugin-crosshair
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -5,3 +5,3 @@ /* | ||
* http://abelheinsbroek.nl/ | ||
* Version: 1.1.1 | ||
* Version: 1.1.0 | ||
* | ||
@@ -166,3 +166,11 @@ * Copyright 2019 Abel Heinsbroek | ||
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; | ||
@@ -289,3 +297,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; | ||
@@ -522,12 +537,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); | ||
@@ -534,0 +550,0 @@ stop = true; |
@@ -5,3 +5,3 @@ /* | ||
* http://abelheinsbroek.nl/ | ||
* Version: 1.1.1 | ||
* Version: 1.1.0 | ||
* | ||
@@ -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,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)}); | ||
!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)}); |
@@ -5,3 +5,3 @@ { | ||
"description": "Chart.js plugin to draw and sync vertical crosshair lines", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/chartjs-plugin-crosshair.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
231836
27
1726