-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChart.CurrentMarker.min.js
10 lines (10 loc) · 3.02 KB
/
Chart.CurrentMarker.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* Chart.CurrentMarker.js
* http://www.threerabbits.io/opensource/
* Version: 0.1.2
*
* Copyright 2016 Pascal Ehlert
* Released under the MIT license
* https://github.com/pehlert/Chart.CurrentMarker.js/blob/master/LICENSE.md
*/
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),CurrentMarkerLine=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.setConfig(e.config||{}),r}return _inherits(t,e),_createClass(t,[{key:"setConfig",value:function(e){this.config={lineWidth:e.lineWidth||1,lineColor:e.lineColor||"rgba(46, 153, 122, 1)",lineDash:e.lineDash||[5,3],textColor:e.textColor||"rgb(255, 255, 255)",font:e.font||"18px Helvetica"}}},{key:"draw",value:function(e){e.save();var t=this._view;e.lineWidth=this.config.lineWidth,e.lineColor=this.config.lineColor,e.fillStyle=this.config.lineColor,e.setLineDash(this.config.lineDash);var r=100,n=15,i=30,o=5;e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2-r-n-o,t.y2),e.stroke();var a=t.y2-i/2,l=t.x2-r;e.fillRect(l,a,r,i);var s=l-n,c=a+i/2;e.setLineDash([0]),e.beginPath(),e.moveTo(s,c),e.lineTo(l,a),e.lineTo(l,a+i),e.fill(),e.fillStyle=this.config.textColor,e.font=this.config.font,e.textBaseLine="middle",e.textAlign="center",e.fillText(t.valueText,l+r/2,t.y2+5),e.restore()}}]),t}(Chart.Element),CurrentMarkerPlugin=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"beforeInit",value:function(e){this.config=e.options.currentMarker||{},e._currentMarker=new CurrentMarkerLine({_index:0,config:this.config})}},{key:"beforeDraw",value:function(e){this.config=e.options.currentMarker||{},e._currentMarker.setConfig(this.config)}},{key:"afterDraw",value:function(e,t){var r=e.data.datasets[0].data,n=r[r.length-1],i=e.chart.ctx,o=e._currentMarker,a=o._model=o._model||{},l=e.scales["y-axis-1"],s=l?l.getPixelForValue(n):NaN,c=e.chartArea;isNaN(s)||(a.x1=c.left,a.x2=c.right,a.y1=a.y2=s,a.valueText=n.y.toFixed(this.config.decimals||0)),e._currentMarker.transition(t).draw(i)}}]),t}(Chart.PluginBase);Chart.pluginService.register(new CurrentMarkerPlugin);