New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chartjs-chart-sankey

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-chart-sankey - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

77

dist/chartjs-chart-sankey.esm.js
/*!
* chartjs-chart-sankey v0.3.2
* chartjs-chart-sankey v0.4.0
* https://github.com/kurkle/chartjs-chart-sankey#readme

@@ -424,49 +424,44 @@ * (c) 2021 Jukka Kurkela

dataElementType: 'flow',
dataElementOptions: [
'colorFrom',
'colorTo'
],
interaction: {
mode: 'nearest',
intersect: true
animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'x2', 'y2', 'height']
},
progress: {
easing: 'linear',
duration: (ctx) => ctx.type === 'data' ? (ctx.parsed._custom.x - ctx.parsed.x) * 200 : undefined,
delay: (ctx) => ctx.type === 'data' ? ctx.parsed.x * 500 + ctx.dataIndex * 20 : undefined,
},
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
},
},
datasets: {
animation: (ctx) => {
let delay = 0;
let duration = 0;
const parsed = ctx.chart.getDatasetMeta(ctx.datasetIndex).controller.getParsed(ctx.dataIndex);
if (parsed) {
delay = parsed.x * 500 + ctx.dataIndex * 20;
duration = (parsed._custom.x - parsed.x) * 200;
transitions: {
hide: {
animations: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
to: 'transparent'
}
}
return {
numbers: {
type: 'number',
properties: ['x', 'y', 'x2', 'y2', 'height']
},
progress: {
easing: 'linear',
duration,
delay
},
},
show: {
animations: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
},
hide: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
to: 'transparent'
}
},
show: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
from: 'transparent'
}
from: 'transparent'
}
};
}
},
}
};
SankeyController.overrides = {
interaction: {
mode: 'nearest',
intersect: true
},
datasets: {
color: () => '#efefef',

@@ -473,0 +468,0 @@ clip: false,

/*!
* chartjs-chart-sankey v0.3.2
* chartjs-chart-sankey v0.4.0
* https://github.com/kurkle/chartjs-chart-sankey#readme

@@ -431,49 +431,44 @@ * (c) 2021 Jukka Kurkela

dataElementType: 'flow',
dataElementOptions: [
'colorFrom',
'colorTo'
],
interaction: {
mode: 'nearest',
intersect: true
animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'x2', 'y2', 'height']
},
progress: {
easing: 'linear',
duration: (ctx) => ctx.type === 'data' ? (ctx.parsed._custom.x - ctx.parsed.x) * 200 : undefined,
delay: (ctx) => ctx.type === 'data' ? ctx.parsed.x * 500 + ctx.dataIndex * 20 : undefined,
},
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
},
},
datasets: {
animation: (ctx) => {
let delay = 0;
let duration = 0;
const parsed = ctx.chart.getDatasetMeta(ctx.datasetIndex).controller.getParsed(ctx.dataIndex);
if (parsed) {
delay = parsed.x * 500 + ctx.dataIndex * 20;
duration = (parsed._custom.x - parsed.x) * 200;
transitions: {
hide: {
animations: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
to: 'transparent'
}
}
return {
numbers: {
type: 'number',
properties: ['x', 'y', 'x2', 'y2', 'height']
},
progress: {
easing: 'linear',
duration,
delay
},
},
show: {
animations: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
},
hide: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
to: 'transparent'
}
},
show: {
colors: {
type: 'color',
properties: ['colorFrom', 'colorTo'],
from: 'transparent'
}
from: 'transparent'
}
};
}
},
}
};
SankeyController.overrides = {
interaction: {
mode: 'nearest',
intersect: true
},
datasets: {
color: () => '#efefef',

@@ -480,0 +475,0 @@ clip: false,

/*!
* chartjs-chart-sankey v0.3.2
* chartjs-chart-sankey v0.4.0
* https://github.com/kurkle/chartjs-chart-sankey#readme

@@ -7,2 +7,2 @@ * (c) 2021 Jukka Kurkela

*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(t);function a(t,e){const o=t.filter(t=>!e.has(t));return o.length?o:t.slice(0,1)}const n=t=>void 0!==t,l=(t,e)=>t.x!==e.x?t.x-e.x:t.y-e.y,s=(t,e)=>t.reduce((t,o)=>t+o.node[e].length+s(o.node[e],e),0),i=t=>(e,o)=>s(e.node[t],t)-s(o.node[t],t);function c(t,e){return t.from.sort(i("from")).forEach(t=>{const o=t.node;n(o.y)||(o.y=e,e=Math.max(e+o.out,c(o,e)))}),e}function f(t,e){return t.to.sort(i("to")).forEach(t=>{const o=t.node;n(o.y)||(o.y=e,e=Math.max(e+o.in,f(o,e)))}),e}function h(t,e){return n(t.y)?t.y:(t.y=e,e)}function d(t,e){const o=function(t){return t.sort((t,e)=>Math.max(e.in,e.out)-Math.max(t.in,t.out))[0]}(t);o.y=0;const r=c(o,0),a=f(o,0),l=function(t,e){const o=t.filter(t=>0===t.x),r=t.filter(t=>t.x===e),a=o.filter(t=>!n(t.y)),l=r.filter(t=>!n(t.y));let s=o.reduce((t,e)=>Math.max(t,e.y+e.out||0),0),i=r.reduce((t,e)=>Math.max(t,e.y+e.in||0),0);return s>=i?(a.forEach(t=>{s=h(t,s),s=Math.max(s+t.out,f(t,s))}),l.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))})):(l.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))}),a.forEach(t=>{s=h(t,s),s=Math.max(s+t.out,f(t,s))})),Math.max(s,i)}(t,e);return Math.max(r,a,l)}function u(t,e,o){const r=[...t.values()],n=function(t,e){const o=new Set(e.map(t=>t.to)),r=new Set(e.map(t=>t.from)),n=new Set([...t.keys()]);let l=0;for(;n.size;){const r=a([...n],o);for(let e=0;e<r.length;e++)t.get(r[e]).x=l,n.delete(r[e]);n.size&&(o.clear(),e.filter(t=>n.has(t.from)).forEach(t=>o.add(t.to)),l++)}return[...t.keys()].filter(t=>!r.has(t)).forEach(e=>{t.get(e).x=l}),l}(t,e),s=o?function(t,e){let o=0;for(let r=0;r<=e;r++){let e=0;const a=t.filter(t=>t.x===r).sort((t,e)=>t.priority-e.priority);for(const t of a)t.y=e,e+=t.out;o=Math.max(e,o)}return o}(r,n):d(r,n),i=function(t,e){let o=0;for(let r=0;r<=e;r++)o=Math.max(o,t.filter(t=>t.x===r).length);return o}(r,n),c=.03*s;return function(t,e){let o=1,r=0,a=0;const n=[];t.sort(l).forEach(t=>{if(t.y){if(0===t.x)n.push(t.y);else{for(r!==t.x&&(r=t.x,a=0),o=a+1;o<n.length&&!(n[o]>t.y);o++);a=o}t.y+=o*e,o++}})}(r,c),function(t){t.forEach(t=>{let e=0;t.from.sort((t,e)=>t.node.y+t.node.out/2-(e.node.y+e.node.out/2)).forEach(t=>{t.addY=e,e+=t.flow}),e=0,t.to.sort((t,e)=>t.node.y+t.node.in/2-(e.node.y+e.node.in/2)).forEach(t=>{t.addY=e,e+=t.flow})})}(r),{maxX:n,maxY:s+i*c}}function y(t,e){for(let o=0;o<t.length;o++)if(t[o].key===e)return t[o].addY;return 0}class x extends t.DatasetController{parseObjectData(t,e,o,r){if(0===r)return[];const{xScale:a,yScale:n}=t,l=[],s=this._nodes=function(t){const e=new Map;for(let o=0;o<t.length;o++){const r=t[o];if(e.has(r.from)){const t=e.get(r.from);t.out+=r.flow,t.to.push({key:r.to,flow:r.flow})}else e.set(r.from,{key:r.from,in:0,out:r.flow,from:[],to:[{key:r.to,flow:r.flow}]});if(e.has(r.to)){const t=e.get(r.to);t.in+=r.flow,t.from.push({key:r.from,flow:r.flow})}else e.set(r.to,{key:r.to,in:r.flow,out:0,from:[{key:r.from,flow:r.flow}],to:[]})}const o=(t,e)=>e.flow-t.flow;return[...e.values()].forEach(t=>{let r=0;t.from=t.from.sort(o),t.from.forEach(t=>{t.node=e.get(t.key),t.addY=r,r+=t.flow}),r=0,t.to=t.to.sort(o),t.to.forEach(t=>{t.node=e.get(t.key),t.addY=r,r+=t.flow})}),e}(e),i=this.getDataset().priority;if(i)for(const t of s.values())t.key in i&&(t.priority=i[t.key]);const{maxX:c,maxY:f}=u(s,e,!!i);a.options.max=c,n.options.max=f;for(let t=0,o=e.length;t<o;++t){const o=e[t],r=s.get(o.from),i=s.get(o.to),c=r.y+y(r.to,o.to),f=i.y+y(i.from,o.from);l.push({x:a.parse(r.x,t),y:n.parse(c,t),_custom:{from:r,to:i,x:a.parse(i.x,t),y:n.parse(f,t),height:n.parse(o.flow,t)}})}return l.slice(o,o+r)}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,o,r,a){const n=this,{xScale:l,yScale:s}=n._cachedMeta,i=n.resolveDataElementOptions(o,a),c=n.getSharedOptions(a,t[o],i),f=n.getDataset(),h=e.valueOrDefault(f.borderWidth,1)/2+.5,d=e.valueOrDefault(f.nodeWidth,10);for(let e=o;e<o+r;e++){const o=n.getParsed(e),r=o._custom,i=s.getPixelForValue(o.y);n.updateElement(t[e],e,{x:l.getPixelForValue(o.x)+d+h,y:i,x2:l.getPixelForValue(r.x)-h,y2:s.getPixelForValue(r.y),from:r.from,to:r.to,progress:"reset"===a?0:1,height:Math.abs(s.getPixelForValue(o.y+r.height)-i),options:n.resolveDataElementOptions(e,a)},a)}n.updateSharedOptions(c,a)}_drawLabels(){const t=this,o=t._ctx,r=t._nodes||new Map,a=t.getDataset(),n=e.valueOrDefault(a.borderWidth,1),l=e.valueOrDefault(a.nodeWidth,10),s=a.labels,{xScale:i,yScale:c}=t._cachedMeta;o.save();const f=t.chart.chartArea;for(const t of r.values()){const e=i.getPixelForValue(t.x),r=c.getPixelForValue(t.y),h=Math.max(t.in,t.out),d=Math.abs(c.getPixelForValue(t.y+h)-r),u=s&&s[t.key]||t.key;let y=e;o.fillStyle=a.color||"black",o.textBaseline="middle",e<f.width/2?(o.textAlign="left",y+=l+n+4):(o.textAlign="right",y-=n+4),o.fillText(u,y,r+d/2)}o.restore()}_drawNodes(){const t=this,o=t._ctx,r=t._nodes||new Map,a=t.getDataset(),{xScale:n,yScale:l}=t._cachedMeta,s=e.valueOrDefault(a.borderWidth,1),i=e.valueOrDefault(a.nodeWidth,10);o.save(),o.strokeStyle=a.borderColor||"black",o.lineWidth=s;for(const t of r.values()){o.fillStyle=t.color;const e=n.getPixelForValue(t.x),r=l.getPixelForValue(t.y),a=Math.max(t.in,t.out),c=Math.abs(l.getPixelForValue(t.y+a)-r);s&&o.strokeRect(e,r,i,c),o.fillRect(e,r,i,c)}o.restore()}draw(){const t=this,e=t._ctx,o=t.getMeta().data||[];for(let t=0,e=o.length;t<e;++t){const e=o[t];e.from.color=e.options.colorFrom,e.to.color=e.options.colorTo}t._drawLabels(),t._drawNodes();for(let t=0,r=o.length;t<r;++t)o[t].draw(e)}}x.id="sankey",x.defaults={dataElementType:"flow",dataElementOptions:["colorFrom","colorTo"],interaction:{mode:"nearest",intersect:!0},datasets:{animation:t=>{let e=0,o=0;const r=t.chart.getDatasetMeta(t.datasetIndex).controller.getParsed(t.dataIndex);return r&&(e=500*r.x+20*t.dataIndex,o=200*(r._custom.x-r.x)),{numbers:{type:"number",properties:["x","y","x2","y2","height"]},progress:{easing:"linear",duration:o,delay:e},colors:{type:"color",properties:["colorFrom","colorTo"]},hide:{colors:{type:"color",properties:["colorFrom","colorTo"],to:"transparent"}},show:{colors:{type:"color",properties:["colorFrom","colorTo"],from:"transparent"}}}},color:()=>"#efefef",clip:!1,parsing:!0},plugins:{tooltip:{callbacks:{title:()=>"",label(t){const e=t.dataset.data[t.dataIndex];return e.from+" -> "+e.to+": "+e.flow}}},legend:{display:!1}},scales:{x:{type:"linear",display:!1,min:0,offset:!0},y:{type:"linear",display:!1,min:0,reverse:!0,offset:!0}},layout:{padding:{right:10}}};const p=(t,e,o,r)=>t<o?{cp1:{x:t+(o-t)/3*2,y:e},cp2:{x:t+(o-t)/3,y:r}}:{cp1:{x:t-(t-o)/3,y:0},cp2:{x:o+(t-o)/3,y:0}},g=(t,e,o)=>({x:t.x+o*(e.x-t.x),y:t.y+o*(e.y-t.y)});class m extends t.Element{constructor(t){super(),this.options=void 0,this.x=void 0,this.y=void 0,this.x2=void 0,this.y2=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const{x:o,x2:r,y:a,y2:n,height:l,progress:s}=this,{cp1:i,cp2:c}=p(o,a,r,n),f=this.options;if(0===s)return;t.save(),s<1&&(t.beginPath(),t.rect(o,Math.min(a,n),(r-o)*s+1,Math.abs(n-a)+l+1),t.clip());const h=t.createLinearGradient(o,0,r,0);h.addColorStop(0,e.color(f.colorFrom).alpha(.5).rgbString()),h.addColorStop(1,e.color(f.colorTo).alpha(.5).rgbString()),t.fillStyle=h,t.strokeStyle=h,t.lineWidth=.5,t.beginPath(),t.moveTo(o,a),t.bezierCurveTo(i.x,i.y,c.x,c.y,r,n),t.lineTo(r,n+l),t.bezierCurveTo(c.x,c.y+l,i.x,i.y+l,o,a+l),t.lineTo(o,a),t.stroke(),t.closePath(),t.fill(),t.restore()}inRange(t,e,o){const{x:r,y:a,x2:n,y2:l,height:s}=this.getProps(["x","y","x2","y2","height"],o);if(t<r||t>n)return!1;const{cp1:i,cp2:c}=p(r,a,n,l),f=(t-r)/(n-r),h={x:n,y:l},d=g({x:r,y:a},i,f),u=g(i,c,f),y=g(c,h,f),x=g(d,u,f),m=g(u,y,f),w=g(x,m,f).y;return e>=w&&e<=w+s}inXRange(t,e){const{x:o,x2:r}=this.getProps(["x","x2"],e);return t>=o&&t<=r}inYRange(t,e){const{y:o,y2:r,height:a}=this.getProps(["y","y2","height"],e),n=Math.min(o,r),l=Math.max(o,r)+a;return t>=n&&t<=l}getCenterPoint(t){const{x:e,y:o,x2:r,y2:a,height:n}=this.getProps(["x","y","x2","y2","height"],t);return{x:(e+r)/2,y:(o+a+n)/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return"x"===t?this.width/2:this.height/2}}m.id="flow",m.defaults={colorFrom:"red",colorTo:"green"},r.default.register(x,m)}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Chart,t.Chart.helpers)}(this,(function(t,e){"use strict";function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(t);function a(t,e){const o=t.filter(t=>!e.has(t));return o.length?o:t.slice(0,1)}const n=t=>void 0!==t,s=(t,e)=>t.x!==e.x?t.x-e.x:t.y-e.y,i=(t,e)=>t.reduce((t,o)=>t+o.node[e].length+i(o.node[e],e),0),l=t=>(e,o)=>i(e.node[t],t)-i(o.node[t],t);function c(t,e){return t.from.sort(l("from")).forEach(t=>{const o=t.node;n(o.y)||(o.y=e,e=Math.max(e+o.out,c(o,e)))}),e}function f(t,e){return t.to.sort(l("to")).forEach(t=>{const o=t.node;n(o.y)||(o.y=e,e=Math.max(e+o.in,f(o,e)))}),e}function h(t,e){return n(t.y)?t.y:(t.y=e,e)}function d(t,e){const o=function(t){return t.sort((t,e)=>Math.max(e.in,e.out)-Math.max(t.in,t.out))[0]}(t);o.y=0;const r=c(o,0),a=f(o,0),s=function(t,e){const o=t.filter(t=>0===t.x),r=t.filter(t=>t.x===e),a=o.filter(t=>!n(t.y)),s=r.filter(t=>!n(t.y));let i=o.reduce((t,e)=>Math.max(t,e.y+e.out||0),0),l=r.reduce((t,e)=>Math.max(t,e.y+e.in||0),0);return i>=l?(a.forEach(t=>{i=h(t,i),i=Math.max(i+t.out,f(t,i))}),s.forEach(t=>{l=h(t,l),l=Math.max(l+t.in,f(t,l))})):(s.forEach(t=>{l=h(t,l),l=Math.max(l+t.in,f(t,l))}),a.forEach(t=>{i=h(t,i),i=Math.max(i+t.out,f(t,i))})),Math.max(i,l)}(t,e);return Math.max(r,a,s)}function u(t,e,o){const r=[...t.values()],n=function(t,e){const o=new Set(e.map(t=>t.to)),r=new Set(e.map(t=>t.from)),n=new Set([...t.keys()]);let s=0;for(;n.size;){const r=a([...n],o);for(let e=0;e<r.length;e++)t.get(r[e]).x=s,n.delete(r[e]);n.size&&(o.clear(),e.filter(t=>n.has(t.from)).forEach(t=>o.add(t.to)),s++)}return[...t.keys()].filter(t=>!r.has(t)).forEach(e=>{t.get(e).x=s}),s}(t,e),i=o?function(t,e){let o=0;for(let r=0;r<=e;r++){let e=0;const a=t.filter(t=>t.x===r).sort((t,e)=>t.priority-e.priority);for(const t of a)t.y=e,e+=t.out;o=Math.max(e,o)}return o}(r,n):d(r,n),l=function(t,e){let o=0;for(let r=0;r<=e;r++)o=Math.max(o,t.filter(t=>t.x===r).length);return o}(r,n),c=.03*i;return function(t,e){let o=1,r=0,a=0;const n=[];t.sort(s).forEach(t=>{if(t.y){if(0===t.x)n.push(t.y);else{for(r!==t.x&&(r=t.x,a=0),o=a+1;o<n.length&&!(n[o]>t.y);o++);a=o}t.y+=o*e,o++}})}(r,c),function(t){t.forEach(t=>{let e=0;t.from.sort((t,e)=>t.node.y+t.node.out/2-(e.node.y+e.node.out/2)).forEach(t=>{t.addY=e,e+=t.flow}),e=0,t.to.sort((t,e)=>t.node.y+t.node.in/2-(e.node.y+e.node.in/2)).forEach(t=>{t.addY=e,e+=t.flow})})}(r),{maxX:n,maxY:i+l*c}}function y(t,e){for(let o=0;o<t.length;o++)if(t[o].key===e)return t[o].addY;return 0}class x extends t.DatasetController{parseObjectData(t,e,o,r){if(0===r)return[];const{xScale:a,yScale:n}=t,s=[],i=this._nodes=function(t){const e=new Map;for(let o=0;o<t.length;o++){const r=t[o];if(e.has(r.from)){const t=e.get(r.from);t.out+=r.flow,t.to.push({key:r.to,flow:r.flow})}else e.set(r.from,{key:r.from,in:0,out:r.flow,from:[],to:[{key:r.to,flow:r.flow}]});if(e.has(r.to)){const t=e.get(r.to);t.in+=r.flow,t.from.push({key:r.from,flow:r.flow})}else e.set(r.to,{key:r.to,in:r.flow,out:0,from:[{key:r.from,flow:r.flow}],to:[]})}const o=(t,e)=>e.flow-t.flow;return[...e.values()].forEach(t=>{let r=0;t.from=t.from.sort(o),t.from.forEach(t=>{t.node=e.get(t.key),t.addY=r,r+=t.flow}),r=0,t.to=t.to.sort(o),t.to.forEach(t=>{t.node=e.get(t.key),t.addY=r,r+=t.flow})}),e}(e),l=this.getDataset().priority;if(l)for(const t of i.values())t.key in l&&(t.priority=l[t.key]);const{maxX:c,maxY:f}=u(i,e,!!l);a.options.max=c,n.options.max=f;for(let t=0,o=e.length;t<o;++t){const o=e[t],r=i.get(o.from),l=i.get(o.to),c=r.y+y(r.to,o.to),f=l.y+y(l.from,o.from);s.push({x:a.parse(r.x,t),y:n.parse(c,t),_custom:{from:r,to:l,x:a.parse(l.x,t),y:n.parse(f,t),height:n.parse(o.flow,t)}})}return s.slice(o,o+r)}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,o,r,a){const n=this,{xScale:s,yScale:i}=n._cachedMeta,l=n.resolveDataElementOptions(o,a),c=n.getSharedOptions(a,t[o],l),f=n.getDataset(),h=e.valueOrDefault(f.borderWidth,1)/2+.5,d=e.valueOrDefault(f.nodeWidth,10);for(let e=o;e<o+r;e++){const o=n.getParsed(e),r=o._custom,l=i.getPixelForValue(o.y);n.updateElement(t[e],e,{x:s.getPixelForValue(o.x)+d+h,y:l,x2:s.getPixelForValue(r.x)-h,y2:i.getPixelForValue(r.y),from:r.from,to:r.to,progress:"reset"===a?0:1,height:Math.abs(i.getPixelForValue(o.y+r.height)-l),options:n.resolveDataElementOptions(e,a)},a)}n.updateSharedOptions(c,a)}_drawLabels(){const t=this,o=t._ctx,r=t._nodes||new Map,a=t.getDataset(),n=e.valueOrDefault(a.borderWidth,1),s=e.valueOrDefault(a.nodeWidth,10),i=a.labels,{xScale:l,yScale:c}=t._cachedMeta;o.save();const f=t.chart.chartArea;for(const t of r.values()){const e=l.getPixelForValue(t.x),r=c.getPixelForValue(t.y),h=Math.max(t.in,t.out),d=Math.abs(c.getPixelForValue(t.y+h)-r),u=i&&i[t.key]||t.key;let y=e;o.fillStyle=a.color||"black",o.textBaseline="middle",e<f.width/2?(o.textAlign="left",y+=s+n+4):(o.textAlign="right",y-=n+4),o.fillText(u,y,r+d/2)}o.restore()}_drawNodes(){const t=this,o=t._ctx,r=t._nodes||new Map,a=t.getDataset(),{xScale:n,yScale:s}=t._cachedMeta,i=e.valueOrDefault(a.borderWidth,1),l=e.valueOrDefault(a.nodeWidth,10);o.save(),o.strokeStyle=a.borderColor||"black",o.lineWidth=i;for(const t of r.values()){o.fillStyle=t.color;const e=n.getPixelForValue(t.x),r=s.getPixelForValue(t.y),a=Math.max(t.in,t.out),c=Math.abs(s.getPixelForValue(t.y+a)-r);i&&o.strokeRect(e,r,l,c),o.fillRect(e,r,l,c)}o.restore()}draw(){const t=this,e=t._ctx,o=t.getMeta().data||[];for(let t=0,e=o.length;t<e;++t){const e=o[t];e.from.color=e.options.colorFrom,e.to.color=e.options.colorTo}t._drawLabels(),t._drawNodes();for(let t=0,r=o.length;t<r;++t)o[t].draw(e)}}x.id="sankey",x.defaults={dataElementType:"flow",animations:{numbers:{type:"number",properties:["x","y","x2","y2","height"]},progress:{easing:"linear",duration:t=>"data"===t.type?200*(t.parsed._custom.x-t.parsed.x):void 0,delay:t=>"data"===t.type?500*t.parsed.x+20*t.dataIndex:void 0},colors:{type:"color",properties:["colorFrom","colorTo"]}},transitions:{hide:{animations:{colors:{type:"color",properties:["colorFrom","colorTo"],to:"transparent"}}},show:{animations:{colors:{type:"color",properties:["colorFrom","colorTo"],from:"transparent"}}}}},x.overrides={interaction:{mode:"nearest",intersect:!0},datasets:{color:()=>"#efefef",clip:!1,parsing:!0},plugins:{tooltip:{callbacks:{title:()=>"",label(t){const e=t.dataset.data[t.dataIndex];return e.from+" -> "+e.to+": "+e.flow}}},legend:{display:!1}},scales:{x:{type:"linear",display:!1,min:0,offset:!0},y:{type:"linear",display:!1,min:0,reverse:!0,offset:!0}},layout:{padding:{right:10}}};const p=(t,e,o,r)=>t<o?{cp1:{x:t+(o-t)/3*2,y:e},cp2:{x:t+(o-t)/3,y:r}}:{cp1:{x:t-(t-o)/3,y:0},cp2:{x:o+(t-o)/3,y:0}},g=(t,e,o)=>({x:t.x+o*(e.x-t.x),y:t.y+o*(e.y-t.y)});class m extends t.Element{constructor(t){super(),this.options=void 0,this.x=void 0,this.y=void 0,this.x2=void 0,this.y2=void 0,this.height=void 0,t&&Object.assign(this,t)}draw(t){const{x:o,x2:r,y:a,y2:n,height:s,progress:i}=this,{cp1:l,cp2:c}=p(o,a,r,n),f=this.options;if(0===i)return;t.save(),i<1&&(t.beginPath(),t.rect(o,Math.min(a,n),(r-o)*i+1,Math.abs(n-a)+s+1),t.clip());const h=t.createLinearGradient(o,0,r,0);h.addColorStop(0,e.color(f.colorFrom).alpha(.5).rgbString()),h.addColorStop(1,e.color(f.colorTo).alpha(.5).rgbString()),t.fillStyle=h,t.strokeStyle=h,t.lineWidth=.5,t.beginPath(),t.moveTo(o,a),t.bezierCurveTo(l.x,l.y,c.x,c.y,r,n),t.lineTo(r,n+s),t.bezierCurveTo(c.x,c.y+s,l.x,l.y+s,o,a+s),t.lineTo(o,a),t.stroke(),t.closePath(),t.fill(),t.restore()}inRange(t,e,o){const{x:r,y:a,x2:n,y2:s,height:i}=this.getProps(["x","y","x2","y2","height"],o);if(t<r||t>n)return!1;const{cp1:l,cp2:c}=p(r,a,n,s),f=(t-r)/(n-r),h={x:n,y:s},d=g({x:r,y:a},l,f),u=g(l,c,f),y=g(c,h,f),x=g(d,u,f),m=g(u,y,f),w=g(x,m,f).y;return e>=w&&e<=w+i}inXRange(t,e){const{x:o,x2:r}=this.getProps(["x","x2"],e);return t>=o&&t<=r}inYRange(t,e){const{y:o,y2:r,height:a}=this.getProps(["y","y2","height"],e),n=Math.min(o,r),s=Math.max(o,r)+a;return t>=n&&t<=s}getCenterPoint(t){const{x:e,y:o,x2:r,y2:a,height:n}=this.getProps(["x","y","x2","y2","height"],t);return{x:(e+r)/2,y:(o+a+n)/2}}tooltipPosition(){return this.getCenterPoint()}getRange(t){return"x"===t?this.width/2:this.height/2}}m.id="flow",m.defaults={colorFrom:"red",colorTo:"green"},r.default.register(x,m)}));
{
"name": "chartjs-chart-sankey",
"version": "0.3.2",
"version": "0.4.0",
"description": "Chart.js module for creating sankey diagrams",

@@ -35,15 +35,15 @@ "main": "dist/chartjs-chart-sankey.js",

"devDependencies": {
"@rollup/plugin-node-resolve": "^11.1.1",
"chart.js": "^3.0.0-beta.10",
"chartjs-adapter-date-fns": "^1.1.0-alpha.3",
"chartjs-test-utils": "^0.2.1",
"concurrently": "^5.3.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"chart.js": "^3.0.0-rc.2",
"chartjs-adapter-date-fns": "^1.1.0-beta.1",
"chartjs-test-utils": "^0.2.2",
"concurrently": "^6.0.0",
"cross-env": "^7.0.3",
"date-fns": "^2.17.0",
"eslint": "^7.19.0",
"date-fns": "^2.19.0",
"eslint": "^7.22.0",
"eslint-config-chartjs": "^0.3.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-html": "^6.1.1",
"jasmine-core": "^3.6.0",
"karma": "^6.1.0",
"eslint-plugin-html": "^6.1.2",
"jasmine-core": "^3.7.1",
"karma": "^6.2.0",
"karma-chrome-launcher": "^3.1.0",

@@ -54,6 +54,6 @@ "karma-coverage": "^2.0.3",

"karma-jasmine-html-reporter": "^1.5.4",
"karma-rollup-preprocessor": "^7.0.5",
"karma-rollup-preprocessor": "^7.0.7",
"karma-spec-reporter": "0.0.32",
"merge2": "^1.4.1",
"rollup": "^2.38.5",
"rollup": "^2.42.1",
"rollup-plugin-istanbul": "^3.0.0",

@@ -63,5 +63,5 @@ "rollup-plugin-terser": "^7.0.2"

"peerDependencies": {
"chart.js": "^3.0.0-beta.10"
"chart.js": "^3.0.0-rc.2"
},
"dependencies": {}
}
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