From dd1b941f059cb9825a4f1008b043ae5689dc4788 Mon Sep 17 00:00:00 2001 From: Marcus Alsterfjord Date: Thu, 21 Nov 2019 10:55:57 +0100 Subject: [PATCH] Bump to version 0.1.3 --- LICENSE | 2 +- dist/chartjs-plugin-trendline.min.js | 2 +- package.json | 4 ++-- src/chartjs-plugin-trendline.js | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/LICENSE b/LICENSE index 65f8312..c09a322 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Marcus Alsterfjord +Copyright (c) 2019 Marcus Alsterfjord Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/dist/chartjs-plugin-trendline.min.js b/dist/chartjs-plugin-trendline.min.js index 60ed19f..a426bcc 100644 --- a/dist/chartjs-plugin-trendline.min.js +++ b/dist/chartjs-plugin-trendline.min.js @@ -1 +1 @@ -var pluginTrendlineLinear={beforeDraw:function(e){var s,a;for(var t in e.scales)if("x"==t[0]?a=e.scales[t]:s=e.scales[t],a&&s)break;var n=e.chart.ctx;e.data.datasets.forEach(function(t,i){t.trendlineLinear&&e.isDatasetVisible(i)&&addFitter(e.getDatasetMeta(i),n,t,a,s)}),n.setLineDash([])}};function addFitter(t,i,e,s,a){var n=e.trendlineLinear.style||e.borderColor,r=e.trendlineLinear.width||e.borderWidth,h=e.trendlineLinear.lineStyle||"solid";n=void 0!==n?n:"rgba(169,169,169, .6)",r=void 0!==r?r:3;var o=new LineFitter,u=e.data.length-1,d=t.data[0]._model.x,l=t.data[u]._model.x,m=!1;e.data&&"object"==typeof e.data[0]&&(m=!0),e.data.forEach(function(t,i){m?o.add(t.x,t.y):o.add(i,t)});var x=s.getPixelForValue(o.minx),c=s.getPixelForValue(o.maxx),f=a.getPixelForValue(o.f(o.minx)),X=a.getPixelForValue(o.f(o.maxx));m||(x=d,c=l),i.lineWidth=r,"dotted"===h&&i.setLineDash([2,3]),i.beginPath(),i.moveTo(x,f),i.lineTo(c,X),i.strokeStyle=n,i.stroke()}function LineFitter(){this.count=0,this.sumX=0,this.sumX2=0,this.sumXY=0,this.sumY=0,this.minx=1e100,this.maxx=-1e100}Chart.plugins.register(pluginTrendlineLinear),LineFitter.prototype={add:function(t,i){this.count++,this.sumX+=t,this.sumX2+=t*t,this.sumXY+=t*i,this.sumY+=i,tthis.maxx&&(this.maxx=t)},f:function(t){var i=this.count*this.sumX2-this.sumX*this.sumX;return(this.sumX2*this.sumY-this.sumX*this.sumXY)/i+t*((this.count*this.sumXY-this.sumX*this.sumY)/i)}}; \ No newline at end of file +var pluginTrendlineLinear={beforeDraw:function(e){var s,a;for(var t in e.scales)if("x"==t[0]?a=e.scales[t]:s=e.scales[t],a&&s)break;var r=e.chart.ctx;e.data.datasets.forEach(function(t,i){t.trendlineLinear&&e.isDatasetVisible(i)&&addFitter(e.getDatasetMeta(i),r,t,a,s)}),r.setLineDash([])}};function addFitter(t,i,e,s,a){var r=e.trendlineLinear.style||e.borderColor,n=e.trendlineLinear.width||e.borderWidth,o=e.trendlineLinear.lineStyle||"solid";r=void 0!==r?r:"rgba(169,169,169, .6)",n=void 0!==n?n:3;var h=new LineFitter,d=e.data.length-1,l=t.data[0]._model.x,u=t.data[d]._model.x,m=!1;e.data&&"object"==typeof e.data[0]&&(m=!0),e.data.forEach(function(t,i){m?h.add(t.x,t.y):h.add(i,t)});var c=s.getPixelForValue(h.minx),x=s.getPixelForValue(h.maxx),f=a.getPixelForValue(h.f(h.minx)),X=a.getPixelForValue(h.f(h.maxx));m||(c=l,x=u);var v=t.controller.chart.chartArea.bottom,g=t.controller.chart.width;if(vthis.maxx&&(this.maxx=t)},f:function(t){var i=this.count*this.sumX2-this.sumX*this.sumX;return(this.sumX2*this.sumY-this.sumX*this.sumXY)/i+t*((this.count*this.sumXY-this.sumX*this.sumY)/i)}}; \ No newline at end of file diff --git a/package.json b/package.json index 118aff5..cecc07f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chartjs-plugin-trendline", - "version": "0.1.2", + "version": "0.1.3", "description": "Trendline for Chart.js", "main": "src/chartjs-plugin-trendline.js", "scripts": { @@ -17,7 +17,7 @@ }, "homepage": "https://github.com/Makanz/chartjs-plugin-trendline#readme", "devDependencies": { - "del": "^3.0.0", + "del": "^5.1.0", "gulp": "^4.0.2", "gulp-bump": "^3.1.3", "gulp-rename": "^1.4.0", diff --git a/src/chartjs-plugin-trendline.js b/src/chartjs-plugin-trendline.js index 43460c4..faecb81 100644 --- a/src/chartjs-plugin-trendline.js +++ b/src/chartjs-plugin-trendline.js @@ -1,6 +1,6 @@ /*! * chartjs-plugin-trendline.js - * Version: 0.1.2 + * Version: 0.1.3 * * Copyright 2017 Marcus Alsterfjord * Released under the MIT license @@ -59,22 +59,22 @@ function addFitter(datasetMeta, ctx, dataset, xScale, yScale) { var y2 = yScale.getPixelForValue(fitter.f(fitter.maxx)); if ( !xy ) { x1 = startPos; x2 = endPos; } - const drawBottom = datasetMeta.controller.chart.chartArea.bottom; - const chartWidth = datasetMeta.controller.chart.width; + var drawBottom = datasetMeta.controller.chart.chartArea.bottom; + var chartWidth = datasetMeta.controller.chart.width; if(y1 > drawBottom) { // Left side is below zero - const diff = y1 - drawBottom; - const lineHeight = y1 - y2; - const overlapPercentage = diff / lineHeight; - const addition = chartWidth * overlapPercentage; + var diff = y1 - drawBottom; + var lineHeight = y1 - y2; + var overlapPercentage = diff / lineHeight; + var addition = chartWidth * overlapPercentage; y1 = drawBottom; x1 = (x1 + addition); } else if(y2 > drawBottom) { // right side is below zero - const diff = y2 - drawBottom; - const lineHeight = y2 - y1; - const overlapPercentage = diff / lineHeight; - const subtraction = chartWidth - (chartWidth * overlapPercentage); + var diff = y2 - drawBottom; + var lineHeight = y2 - y1; + var overlapPercentage = diff / lineHeight; + var subtraction = chartWidth - (chartWidth * overlapPercentage); y2 = drawBottom; x2 = chartWidth - (x2 - subtraction);