Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 135 additions & 135 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@rollup/plugin-node-resolve": "^13.0.0",
"chart.js": "^3.0.0",
"chartjs-adapter-date-fns": "^2.0.0",
"chartjs-test-utils": "^0.2.2",
"chartjs-test-utils": "^0.3.0",
"concurrently": "^6.0.0",
"cross-env": "^7.0.3",
"date-fns": "^2.19.0",
Expand Down
23 changes: 18 additions & 5 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export default class SankeyController extends DatasetController {

const {maxX, maxY} = layout(nodes, data, !!priority);

xScale.options.max = maxX;
yScale.options.max = maxY;
me._maxX = maxX;
me._maxY = maxY;

for (let i = 0, ilen = data.length; i < ilen; ++i) {
const flow = data[i];
Expand All @@ -103,6 +103,14 @@ export default class SankeyController extends DatasetController {
return parsed.slice(start, start + count);
}

getMinMax(scale) {
const me = this;
return {
min: 0,
max: scale === this._cachedMeta.xScale ? this._maxX : me._maxY
};
}

update(mode) {
const me = this;
const meta = me._cachedMeta;
Expand Down Expand Up @@ -293,21 +301,26 @@ SankeyController.overrides = {
scales: {
x: {
type: 'linear',
bounds: 'data',
display: false,
min: 0,
offset: true
offset: false
},
y: {
type: 'linear',
bounds: 'data',
display: false,
min: 0,
reverse: true,
offset: true
offset: false
}
},
layout: {
padding: {
right: 10
top: 3,
left: 3,
right: 13,
bottom: 3
}
}
};
8 changes: 5 additions & 3 deletions src/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function addPadding(nodeArray, padding) {
let i = 1;
let x = 0;
let prev = 0;
let maxY = 0;
const rows = [];
nodeArray.sort(nodeByXY).forEach(node => {
if (node.y) {
Expand All @@ -157,9 +158,11 @@ export function addPadding(nodeArray, padding) {
prev = i;
}
node.y += i * padding;
maxY = Math.max(maxY, node.y + Math.max(node.in, node.out));
i++;
}
});
return maxY;
}

export function sortFlows(nodeArray) {
Expand All @@ -181,11 +184,10 @@ export function layout(nodes, data, priority) {
const nodeArray = [...nodes.values()];
const maxX = calculateX(nodes, data);
const maxY = priority ? calculateYUsingPriority(nodeArray, maxX) : calculateY(nodeArray, maxX);
const rows = maxRows(nodeArray, maxX);
const padding = maxY * 0.03; // rows;

addPadding(nodeArray, padding);
const maxYWithPadding = addPadding(nodeArray, padding);
sortFlows(nodeArray);

return {maxX, maxY: maxY + rows * padding};
return {maxX, maxY: maxYWithPadding};
}
Binary file modified test/fixtures/basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/color-mode-from.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/color-mode-gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/color-mode-to.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/energy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/issue13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/issue25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/no-border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/no-offset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/fixtures/nodeWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
options: {
layout: {
padding: {
right: 50
right: 53
}
}
}
Expand Down
Binary file modified test/fixtures/nodeWidth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/priority.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.