chartjs-plugin-waterfall
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -372,2 +372,16 @@ (function (global, factory) { | ||
var initializeDatasets = function initializeDatasets(chart) { | ||
chart.data.datasets.forEach(function (dataset, i) { | ||
dataset.waterfall = merge({}, { | ||
stepLines: {} | ||
}, dataset.waterfall); | ||
// Each dataset must have a unique label so we set the dummy stacks to have dummy labels | ||
if (dataset.waterfall.dummyStack) { | ||
dataset.label = 'dummyStack_' + i; | ||
dataset.backgroundColor = 'rgba(0, 0, 0, 0)'; | ||
} | ||
}); | ||
}; | ||
var waterFallPlugin = { | ||
@@ -380,2 +394,4 @@ beforeInit: function beforeInit(chart) { | ||
afterInit: function afterInit(chart) { | ||
initializeDatasets(chart); | ||
chart.options.plugins = merge({}, defaultOptions, chart.options.plugins); | ||
@@ -391,14 +407,2 @@ chart.options.tooltips.filter = filterDummyStacks; | ||
}, chart.options.animation.duration); | ||
chart.data.datasets.forEach(function (dataset, i) { | ||
dataset.waterfall = merge({}, { | ||
stepLines: {} | ||
}, dataset.waterfall); | ||
// Each dataset must have a unique label so we set the dummy stacks to have dummy labels | ||
if (dataset.waterfall.dummyStack) { | ||
dataset.label = 'dummyStack_' + i; | ||
dataset.backgroundColor = 'rgba(0, 0, 0, 0)'; | ||
} | ||
}); | ||
}, | ||
@@ -408,2 +412,4 @@ afterDraw: function afterDraw(chart) { | ||
initializeDatasets(chart); | ||
if (options.stepLines.enabled && status[chart.id].readyToDrawStepLines) { | ||
@@ -410,0 +416,0 @@ drawStepLines(chart); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lodash.merge"),require("lodash.groupby")):"function"==typeof define&&define.amd?define(["lodash.merge","lodash.groupby"],e):t.chartjsWPluginWaterfall=e(t._.merge,t._.groupby)}(this,function(t,e){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;!function(){function t(t){this.value=t}function e(e){function o(n,r){try{var s=e[n](r),i=s.value;i instanceof t?Promise.resolve(i.value).then(function(t){o("next",t)},function(t){o("throw",t)}):a(s.done?"return":"normal",s.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):r=null}var n,r;this._invoke=function(t,e){return new Promise(function(a,s){var i={key:t,arg:e,resolve:a,reject:s,next:null};r?r=r.next=i:(n=r=i,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var o=function(t){if(Array.isArray(t)){for(var e=0,o=Array(t.length);e<t.length;e++)o[e]=t[e];return o}return Array.from(t)},a=function(t,e,o,a){var n=o.stackBase,r=a.stackBase,s=o.stackTopYPos,i=a.stackTopYPos;s===r?(i=r,r=a.dummyStackBase):n===i&&(s=n,n=o.dummyStackBase),!o.isPositive&&a.isPositive&&(i=r,r=a.stackTopYPos),o.isPositive&&!a.isPositive&&(s=n,n=o.stackTopYPos);var l=s>i?s:i,u=n>r?n:r,c=t.createLinearGradient(0,l,0,u),f=o.options.startColor||e.startColor,p=o.options.endColor||e.endColor,d=o.options.startColorStop||e.startColorStop,k=o.options.endColorStop||e.endColorStop;c.addColorStop(d,f),c.addColorStop(k,p),t.fillStyle=c,t.beginPath(),t.lineTo(o.stackRightXPos,s),t.lineTo(a.stackLeftXPos,i),t.lineTo(a.stackLeftXPos,r),t.lineTo(o.stackRightXPos,n),t.fill()},n=function(t){var n=t.ctx,r=t.data.datasets,s=t.options.plugins.waterFallPlugin.stepLines,i=e(r,"stack"),l=[],u=function(t){var e=Object.keys(t._meta)[0];return t._meta[e].data[0]._model};Object.keys(i).forEach(function(t){var e=i[t],a=e.filter(function(t){return!t.waterfall.dummyStack}).map(function(t){return u(t).base}),n=Math.max.apply(Math,o(a)),r=e.map(function(t){return u(t).base}),s=Math.max.apply(Math,o(r)),c=e.map(function(t){var e=u(t);return{stackRightXPos:e.x+e.width/2,stackLeftXPos:e.x-e.width/2,stackTopYPos:e.y,stackBase:n,dummyStackBase:s,isPositive:t.data[0]>0,options:t.waterfall.stepLines}});l.push(c)});for(var c=function(t){var e=t.length-1;return{stackRightXPos:t[e].stackRightXPos,stackLeftXPos:t[e].stackLeftXPos,stackTopYPos:t[e].stackTopYPos,stackBase:t[e].stackBase,dummyStackBase:t[e].dummyStackBase,isPositive:t[e].isPositive,options:t[e].options}},f=function(t,e){return t.stackTopYPos===e.stackTopYPos&&t.stackBase===e.stackBase},p=0;p<l.length;p+=1)!function(t){var e=l[t];if(t!==l.length-1){var o=l[t+1],r=c(e),i=c(o);(s.diagonalStepLines||f(r,i))&&a(n,s,r,i),Array.isArray(s.diagonalStepLines)&&s.diagonalStepLines.forEach(function(t){var r=t[0],i=t[1],l=e[r],u=o[i];l&&u&&a(n,s,l,u)})}}(p)},r={waterFallPlugin:{stepLines:{enabled:!0,startColorStop:0,endColorStop:.6,startColor:"rgba(0, 0, 0, 0.55)",endColor:"rgba(0, 0, 0, 0)",diagonalStepLines:!0}}},s={},i=function(t,e){return!e.datasets[t.datasetIndex].waterfall.dummyStack};return{beforeInit:function(t){s[t.id]={readyToDrawStepLines:!1}},afterInit:function(e){e.options.plugins=t({},r,e.options.plugins),e.options.tooltips.filter=i,e.options.legend.labels.filter=i,setTimeout(function(){s[e.id].readyToDrawStepLines=!0,n(e)},e.options.animation.duration),e.data.datasets.forEach(function(e,o){e.waterfall=t({},{stepLines:{}},e.waterfall),e.waterfall.dummyStack&&(e.label="dummyStack_"+o,e.backgroundColor="rgba(0, 0, 0, 0)")})},afterDraw:function(t){t.options.plugins.waterFallPlugin.stepLines.enabled&&s[t.id].readyToDrawStepLines&&n(t)}}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lodash.merge"),require("lodash.groupby")):"function"==typeof define&&define.amd?define(["lodash.merge","lodash.groupby"],e):t.chartjsWPluginWaterfall=e(t._.merge,t._.groupby)}(this,function(t,e){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;!function(){function t(t){this.value=t}function e(e){function o(n,r){try{var s=e[n](r),i=s.value;i instanceof t?Promise.resolve(i.value).then(function(t){o("next",t)},function(t){o("throw",t)}):a(s.done?"return":"normal",s.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):r=null}var n,r;this._invoke=function(t,e){return new Promise(function(a,s){var i={key:t,arg:e,resolve:a,reject:s,next:null};r?r=r.next=i:(n=r=i,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var o=function(t){if(Array.isArray(t)){for(var e=0,o=Array(t.length);e<t.length;e++)o[e]=t[e];return o}return Array.from(t)},a=function(t,e,o,a){var n=o.stackBase,r=a.stackBase,s=o.stackTopYPos,i=a.stackTopYPos;s===r?(i=r,r=a.dummyStackBase):n===i&&(s=n,n=o.dummyStackBase),!o.isPositive&&a.isPositive&&(i=r,r=a.stackTopYPos),o.isPositive&&!a.isPositive&&(s=n,n=o.stackTopYPos);var l=s>i?s:i,u=n>r?n:r,c=t.createLinearGradient(0,l,0,u),f=o.options.startColor||e.startColor,p=o.options.endColor||e.endColor,d=o.options.startColorStop||e.startColorStop,k=o.options.endColorStop||e.endColorStop;c.addColorStop(d,f),c.addColorStop(k,p),t.fillStyle=c,t.beginPath(),t.lineTo(o.stackRightXPos,s),t.lineTo(a.stackLeftXPos,i),t.lineTo(a.stackLeftXPos,r),t.lineTo(o.stackRightXPos,n),t.fill()},n=function(t){var n=t.ctx,r=t.data.datasets,s=t.options.plugins.waterFallPlugin.stepLines,i=e(r,"stack"),l=[],u=function(t){var e=Object.keys(t._meta)[0];return t._meta[e].data[0]._model};Object.keys(i).forEach(function(t){var e=i[t],a=e.filter(function(t){return!t.waterfall.dummyStack}).map(function(t){return u(t).base}),n=Math.max.apply(Math,o(a)),r=e.map(function(t){return u(t).base}),s=Math.max.apply(Math,o(r)),c=e.map(function(t){var e=u(t);return{stackRightXPos:e.x+e.width/2,stackLeftXPos:e.x-e.width/2,stackTopYPos:e.y,stackBase:n,dummyStackBase:s,isPositive:t.data[0]>0,options:t.waterfall.stepLines}});l.push(c)});for(var c=function(t){var e=t.length-1;return{stackRightXPos:t[e].stackRightXPos,stackLeftXPos:t[e].stackLeftXPos,stackTopYPos:t[e].stackTopYPos,stackBase:t[e].stackBase,dummyStackBase:t[e].dummyStackBase,isPositive:t[e].isPositive,options:t[e].options}},f=function(t){var e=l[t];if(t!==l.length-1){var o=l[t+1],r=c(e),i=c(o);(s.diagonalStepLines||function(t,e){return t.stackTopYPos===e.stackTopYPos&&t.stackBase===e.stackBase}(r,i))&&a(n,s,r,i),Array.isArray(s.diagonalStepLines)&&s.diagonalStepLines.forEach(function(t){var r=t[0],i=t[1],l=e[r],u=o[i];l&&u&&a(n,s,l,u)})}},p=0;p<l.length;p+=1)f(p)},r={waterFallPlugin:{stepLines:{enabled:!0,startColorStop:0,endColorStop:.6,startColor:"rgba(0, 0, 0, 0.55)",endColor:"rgba(0, 0, 0, 0)",diagonalStepLines:!0}}},s={},i=function(t,e){return!e.datasets[t.datasetIndex].waterfall.dummyStack},l=function(e){e.data.datasets.forEach(function(e,o){e.waterfall=t({},{stepLines:{}},e.waterfall),e.waterfall.dummyStack&&(e.label="dummyStack_"+o,e.backgroundColor="rgba(0, 0, 0, 0)")})};return{beforeInit:function(t){s[t.id]={readyToDrawStepLines:!1}},afterInit:function(e){l(e),e.options.plugins=t({},r,e.options.plugins),e.options.tooltips.filter=i,e.options.legend.labels.filter=i,setTimeout(function(){s[e.id].readyToDrawStepLines=!0,n(e)},e.options.animation.duration)},afterDraw:function(t){var e=t.options.plugins.waterFallPlugin;l(t),e.stepLines.enabled&&s[t.id].readyToDrawStepLines&&n(t)}}}); | ||
//# sourceMappingURL=chartjs-plugin-waterfall.min.js.map |
@@ -370,2 +370,16 @@ 'use strict'; | ||
var initializeDatasets = function initializeDatasets(chart) { | ||
chart.data.datasets.forEach(function (dataset, i) { | ||
dataset.waterfall = merge({}, { | ||
stepLines: {} | ||
}, dataset.waterfall); | ||
// Each dataset must have a unique label so we set the dummy stacks to have dummy labels | ||
if (dataset.waterfall.dummyStack) { | ||
dataset.label = 'dummyStack_' + i; | ||
dataset.backgroundColor = 'rgba(0, 0, 0, 0)'; | ||
} | ||
}); | ||
}; | ||
var waterFallPlugin = { | ||
@@ -378,2 +392,4 @@ beforeInit: function beforeInit(chart) { | ||
afterInit: function afterInit(chart) { | ||
initializeDatasets(chart); | ||
chart.options.plugins = merge({}, defaultOptions, chart.options.plugins); | ||
@@ -389,14 +405,2 @@ chart.options.tooltips.filter = filterDummyStacks; | ||
}, chart.options.animation.duration); | ||
chart.data.datasets.forEach(function (dataset, i) { | ||
dataset.waterfall = merge({}, { | ||
stepLines: {} | ||
}, dataset.waterfall); | ||
// Each dataset must have a unique label so we set the dummy stacks to have dummy labels | ||
if (dataset.waterfall.dummyStack) { | ||
dataset.label = 'dummyStack_' + i; | ||
dataset.backgroundColor = 'rgba(0, 0, 0, 0)'; | ||
} | ||
}); | ||
}, | ||
@@ -406,2 +410,4 @@ afterDraw: function afterDraw(chart) { | ||
initializeDatasets(chart); | ||
if (options.stepLines.enabled && status[chart.id].readyToDrawStepLines) { | ||
@@ -408,0 +414,0 @@ drawStepLines(chart); |
@@ -5,3 +5,3 @@ { | ||
"description": "Chart.js plugin for easy waterfall charts", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "lib/chartjs-plugin-waterfall.js", |
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
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
79730
624