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.2.0 to 0.3.0

30

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

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

function calculateYUsingPriority(nodeArray, maxX) {
let maxY = 0;
for (let x = 0; x <= maxX; x++) {
let y = 0;
const nodes = nodeArray.filter(node => node.x === x).sort((a, b) => a.priority - b.priority);
for (const node of nodes) {
node.y = y;
y += node.out;
}
maxY = Math.max(y, maxY);
}
return maxY;
}
function maxRows(nodeArray, maxX) {

@@ -175,6 +189,6 @@ let max = 0;

function layout(nodes, data) {
function layout(nodes, data, priority) {
const nodeArray = [...nodes.values()];
const maxX = calculateX(nodes, data);
const maxY = calculateY(nodeArray, maxX);
const maxY = priority ? calculateYUsingPriority(nodeArray, maxX) : calculateY(nodeArray, maxX);
const rows = maxRows(nodeArray, maxX);

@@ -253,4 +267,12 @@ const padding = maxY * 0.03; // rows;

const nodes = me._nodes = buildNodesFromFlows(data);
const priority = me.getDataset().priority;
if (priority) {
for (const node of nodes.values()) {
if (node.key in priority) {
node.priority = priority[node.key];
}
}
}
const {maxX, maxY} = layout(nodes, data);
const {maxX, maxY} = layout(nodes, data, !!priority);

@@ -257,0 +279,0 @@ xScale.options.max = maxX;

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

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

function calculateYUsingPriority(nodeArray, maxX) {
let maxY = 0;
for (let x = 0; x <= maxX; x++) {
let y = 0;
const nodes = nodeArray.filter(node => node.x === x).sort((a, b) => a.priority - b.priority);
for (const node of nodes) {
node.y = y;
y += node.out;
}
maxY = Math.max(y, maxY);
}
return maxY;
}
function maxRows(nodeArray, maxX) {

@@ -182,6 +196,6 @@ let max = 0;

function layout(nodes, data) {
function layout(nodes, data, priority) {
const nodeArray = [...nodes.values()];
const maxX = calculateX(nodes, data);
const maxY = calculateY(nodeArray, maxX);
const maxY = priority ? calculateYUsingPriority(nodeArray, maxX) : calculateY(nodeArray, maxX);
const rows = maxRows(nodeArray, maxX);

@@ -260,4 +274,12 @@ const padding = maxY * 0.03; // rows;

const nodes = me._nodes = buildNodesFromFlows(data);
const priority = me.getDataset().priority;
if (priority) {
for (const node of nodes.values()) {
if (node.key in priority) {
node.priority = priority[node.key];
}
}
}
const {maxX, maxY} = layout(nodes, data);
const {maxX, maxY} = layout(nodes, data, !!priority);

@@ -264,0 +286,0 @@ xScale.options.max = maxX;

4

dist/chartjs-chart-sankey.min.js
/*!
* chartjs-chart-sankey v0.2.0
* chartjs-chart-sankey v0.3.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,s=(t,e)=>t.x!==e.x?t.x-e.x:t.y-e.y,l=(t,e)=>t.reduce((t,o)=>t+o.node[e].length+l(o.node[e],e),0),i=t=>(e,o)=>l(e.node[t],t)-l(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),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 l=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 l>=i?(a.forEach(t=>{l=h(t,l),l=Math.max(l+t.out,f(t,l))}),s.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))})):(s.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))}),a.forEach(t=>{l=h(t,l),l=Math.max(l+t.out,f(t,l))})),Math.max(l,i)}(t,e);return Math.max(r,a,s)}function x(t,e){const o=[...t.values()],r=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),n=d(o,r),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}(o,r),i=.03*n;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++}})}(o,i),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})})}(o),{maxX:r,maxY:n+l*i}}function y(t,e){for(let o=0;o<t.length;o++)if(t[o].key===e)return t[o].addY;return 0}class u extends t.DatasetController{parseObjectData(t,e,o,r){if(0===r)return[];const{xScale:a,yScale:n}=t,s=[],l=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),{maxX:i,maxY:c}=x(l,e);a.options.max=i,n.options.max=c;for(let t=0,o=e.length;t<o;++t){const o=e[t],r=l.get(o.from),i=l.get(o.to),c=r.y+y(r.to,o.to),f=i.y+y(i.from,o.from);s.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 s.slice(o,o+r)}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,o,r){const a=this,{xScale:n,yScale:s}=a._cachedMeta,l=a.resolveDataElementOptions(e,r),i=a.getSharedOptions(r,t[e],l);for(let l=e;l<e+o;l++){const e=a.getParsed(l),o=e._custom,i=s.getPixelForValue(e.y);a.updateElement(t[l],l,{x:n.getPixelForValue(e.x)+11,y:i,x2:n.getPixelForValue(o.x)-1,y2:s.getPixelForValue(o.y),from:o.from,to:o.to,progress:"reset"===r?0:1,height:Math.abs(s.getPixelForValue(e.y+o.height)-i),options:a.resolveDataElementOptions(l,r)},r)}a.updateSharedOptions(i,r)}_drawLabels(){const t=this,e=t._ctx,o=t._nodes||new Map,{xScale:r,yScale:a}=t._cachedMeta;e.save();const n=t.chart.chartArea;for(const s of o.values()){const o=r.getPixelForValue(s.x),l=a.getPixelForValue(s.y),i=Math.max(s.in,s.out),c=Math.abs(a.getPixelForValue(s.y+i)-l);e.fillStyle=t.getDataset().color||"black",e.textBaseline="middle",o<n.width/2?(e.textAlign="left",e.fillText(s.key,o+15,l+c/2)):(e.textAlign="right",e.fillText(s.key,o-5,l+c/2))}e.restore()}_drawNodes(){const t=this,e=t._ctx,o=t._nodes||new Map,{xScale:r,yScale:a}=t._cachedMeta;e.save(),e.strokeStyle="black";for(const t of o.values()){e.fillStyle=t.color;const o=r.getPixelForValue(t.x),n=a.getPixelForValue(t.y),s=Math.max(t.in,t.out),l=Math.abs(a.getPixelForValue(t.y+s)-n);e.strokeRect(o,n,10,l),e.fillRect(o,n,10,l)}e.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)}}u.id="sankey",u.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:s,progress:l}=this,{cp1:i,cp2:c}=p(o,a,r,n),f=this.options;if(0===l)return;t.save(),l<1&&(t.beginPath(),t.rect(o,Math.min(a,n),(r-o)*l+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(i.x,i.y,c.x,c.y,r,n),t.lineTo(r,n+s),t.bezierCurveTo(c.x,c.y+s,i.x,i.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:l}=this.getProps(["x","y","x2","y2","height"],o);if(t<r||t>n)return!1;const{cp1:i,cp2:c}=p(r,a,n,s),f=(t-r)/(n-r),h={x:n,y:s},d=g({x:r,y:a},i,f),x=g(i,c,f),y=g(c,h,f),u=g(d,x,f),m=g(x,y,f),w=g(u,m,f).y;return e>=w&&e<=w+l}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(u,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 n(t,e){const o=t.filter(t=>!e.has(t));return o.length?o:t.slice(0,1)}const a=t=>void 0!==t,s=(t,e)=>t.x!==e.x?t.x-e.x:t.y-e.y,l=(t,e)=>t.reduce((t,o)=>t+o.node[e].length+l(o.node[e],e),0),i=t=>(e,o)=>l(e.node[t],t)-l(o.node[t],t);function c(t,e){return t.from.sort(i("from")).forEach(t=>{const o=t.node;a(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;a(o.y)||(o.y=e,e=Math.max(e+o.in,f(o,e)))}),e}function h(t,e){return a(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),n=f(o,0),s=function(t,e){const o=t.filter(t=>0===t.x),r=t.filter(t=>t.x===e),n=o.filter(t=>!a(t.y)),s=r.filter(t=>!a(t.y));let l=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 l>=i?(n.forEach(t=>{l=h(t,l),l=Math.max(l+t.out,f(t,l))}),s.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))})):(s.forEach(t=>{i=h(t,i),i=Math.max(i+t.in,f(t,i))}),n.forEach(t=>{l=h(t,l),l=Math.max(l+t.out,f(t,l))})),Math.max(l,i)}(t,e);return Math.max(r,n,s)}function y(t,e,o){const r=[...t.values()],a=function(t,e){const o=new Set(e.map(t=>t.to)),r=new Set(e.map(t=>t.from)),a=new Set([...t.keys()]);let s=0;for(;a.size;){const r=n([...a],o);for(let e=0;e<r.length;e++)t.get(r[e]).x=s,a.delete(r[e]);a.size&&(o.clear(),e.filter(t=>a.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),l=o?function(t,e){let o=0;for(let r=0;r<=e;r++){let e=0;const n=t.filter(t=>t.x===r).sort((t,e)=>t.priority-e.priority);for(const t of n)t.y=e,e+=t.out;o=Math.max(e,o)}return o}(r,a):d(r,a),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,a),c=.03*l;return function(t,e){let o=1,r=0,n=0;const a=[];t.sort(s).forEach(t=>{if(t.y){if(0===t.x)a.push(t.y);else{for(r!==t.x&&(r=t.x,n=0),o=n+1;o<a.length&&!(a[o]>t.y);o++);n=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:a,maxY:l+i*c}}function x(t,e){for(let o=0;o<t.length;o++)if(t[o].key===e)return t[o].addY;return 0}class u extends t.DatasetController{parseObjectData(t,e,o,r){if(0===r)return[];const{xScale:n,yScale:a}=t,s=[],l=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 l.values())t.key in i&&(t.priority=i[t.key]);const{maxX:c,maxY:f}=y(l,e,!!i);n.options.max=c,a.options.max=f;for(let t=0,o=e.length;t<o;++t){const o=e[t],r=l.get(o.from),i=l.get(o.to),c=r.y+x(r.to,o.to),f=i.y+x(i.from,o.from);s.push({x:n.parse(r.x,t),y:a.parse(c,t),_custom:{from:r,to:i,x:n.parse(i.x,t),y:a.parse(f,t),height:a.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,e,o,r){const n=this,{xScale:a,yScale:s}=n._cachedMeta,l=n.resolveDataElementOptions(e,r),i=n.getSharedOptions(r,t[e],l);for(let l=e;l<e+o;l++){const e=n.getParsed(l),o=e._custom,i=s.getPixelForValue(e.y);n.updateElement(t[l],l,{x:a.getPixelForValue(e.x)+11,y:i,x2:a.getPixelForValue(o.x)-1,y2:s.getPixelForValue(o.y),from:o.from,to:o.to,progress:"reset"===r?0:1,height:Math.abs(s.getPixelForValue(e.y+o.height)-i),options:n.resolveDataElementOptions(l,r)},r)}n.updateSharedOptions(i,r)}_drawLabels(){const t=this,e=t._ctx,o=t._nodes||new Map,{xScale:r,yScale:n}=t._cachedMeta;e.save();const a=t.chart.chartArea;for(const s of o.values()){const o=r.getPixelForValue(s.x),l=n.getPixelForValue(s.y),i=Math.max(s.in,s.out),c=Math.abs(n.getPixelForValue(s.y+i)-l);e.fillStyle=t.getDataset().color||"black",e.textBaseline="middle",o<a.width/2?(e.textAlign="left",e.fillText(s.key,o+15,l+c/2)):(e.textAlign="right",e.fillText(s.key,o-5,l+c/2))}e.restore()}_drawNodes(){const t=this,e=t._ctx,o=t._nodes||new Map,{xScale:r,yScale:n}=t._cachedMeta;e.save(),e.strokeStyle="black";for(const t of o.values()){e.fillStyle=t.color;const o=r.getPixelForValue(t.x),a=n.getPixelForValue(t.y),s=Math.max(t.in,t.out),l=Math.abs(n.getPixelForValue(t.y+s)-a);e.strokeRect(o,a,10,l),e.fillRect(o,a,10,l)}e.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)}}u.id="sankey",u.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:n,y2:a,height:s,progress:l}=this,{cp1:i,cp2:c}=p(o,n,r,a),f=this.options;if(0===l)return;t.save(),l<1&&(t.beginPath(),t.rect(o,Math.min(n,a),(r-o)*l+1,Math.abs(a-n)+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,n),t.bezierCurveTo(i.x,i.y,c.x,c.y,r,a),t.lineTo(r,a+s),t.bezierCurveTo(c.x,c.y+s,i.x,i.y+s,o,n+s),t.lineTo(o,n),t.stroke(),t.closePath(),t.fill(),t.restore()}inRange(t,e,o){const{x:r,y:n,x2:a,y2:s,height:l}=this.getProps(["x","y","x2","y2","height"],o);if(t<r||t>a)return!1;const{cp1:i,cp2:c}=p(r,n,a,s),f=(t-r)/(a-r),h={x:a,y:s},d=g({x:r,y:n},i,f),y=g(i,c,f),x=g(c,h,f),u=g(d,y,f),m=g(y,x,f),w=g(u,m,f).y;return e>=w&&e<=w+l}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:n}=this.getProps(["y","y2","height"],e),a=Math.min(o,r),s=Math.max(o,r)+n;return t>=a&&t<=s}getCenterPoint(t){const{x:e,y:o,x2:r,y2:n,height:a}=this.getProps(["x","y","x2","y2","height"],t);return{x:(e+r)/2,y:(o+n+a)/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(u,m)}));
{
"name": "chartjs-chart-sankey",
"version": "0.2.0",
"version": "0.3.0",
"description": "Chart.js module for creating sankey diagrams",

@@ -38,6 +38,6 @@ "main": "dist/chartjs-chart-sankey.js",

"chartjs-adapter-date-fns": "^1.1.0-alpha.3",
"chartjs-test-utils": "^0.1.2",
"chartjs-test-utils": "^0.2.1",
"concurrently": "^5.3.0",
"cross-env": "^7.0.3",
"date-fns": "^2.16.1",
"date-fns": "^2.17.0",
"eslint": "^7.19.0",

@@ -57,3 +57,3 @@ "eslint-config-chartjs": "^0.3.0",

"merge2": "^1.4.1",
"rollup": "^2.38.4",
"rollup": "^2.38.5",
"rollup-plugin-istanbul": "^3.0.0",

@@ -60,0 +60,0 @@ "rollup-plugin-terser": "^7.0.2"

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