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
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build
on: [push]
jobs:
build:
name: Build and Release
name: Test, Build and Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -20,6 +20,7 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --frozen-lockfile
- run: yarn test
- run: yarn build
- name: semantic-release
if: success()
Expand Down
3 changes: 2 additions & 1 deletion karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async function (karma) {
}

karma.set({
browsers: ['chrome', 'firefox'],
browsers: ['ChromeHeadless', 'firefox'],
frameworks: ['jasmine'],
reporters: ['spec', 'kjhtml'],
logLevel: karma.LOG_WARN,
Expand All @@ -38,6 +38,7 @@ module.exports = async function (karma) {
},
firefox: {
base: 'Firefox',
flags: ['-headless'],
prefs: {
'layers.acceleration.disabled': true,
},
Expand Down
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const { author, homepage, license, main, module, name, version } = JSON.parse(re
const banner = `/*!
* ${name} v${version}
* ${homepage}
* (c) ${new Date(process.env.SOURCE_DATE_EPOCH ? process.env.SOURCE_DATE_EPOCH * 1000 : new Date().getTime()).getFullYear()} ${author}
* (c) ${new Date(
process.env.SOURCE_DATE_EPOCH ? process.env.SOURCE_DATE_EPOCH * 1000 : new Date().getTime()
).getFullYear()} ${author}
* Released under the ${license} license
*/`

Expand Down
40 changes: 23 additions & 17 deletions src/lib/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,30 @@ export function calculateY(nodeArray: SankeyNode[], maxX: number): number {
return fixTop(nodeArray, maxX)
}

export function calculateYUsingPriority(nodeArray: SankeyNode[], maxX: number) {
let maxY = 0;
let nextYStart = 0;
for(let x = 0; x <= maxX; x++){
let y = nextYStart;
const nodes = nodeArray
.filter((node) => node.x === x)
.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
nextYStart = nodes.length ? nodes[0].to
.filter((to) => to.node.x > x + 1)
.reduce((acc, cur) => acc + cur.flow, 0) || 0 : 0;
for (const node of nodes){
node.y = y;
y += Math.max(node.out, node.in);
export function calculateYUsingPriority(nodeArray: SankeyNode[], maxX: number, mode: SankeyMode) {
let maxY = 0
let nextYStart = 0
for (let x = 0; x <= maxX; x++) {
let y = nextYStart
const nodes = nodeArray.filter((node) => node.x === x).sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0))
if (mode === 'edge') {
nextYStart = nodes.length
? nodes[0].to.filter((to) => to.node.x > x + 1).reduce((acc, cur) => acc + cur.flow, 0) || 0
: 0
for (const node of nodes) {
node.y = y
y += Math.max(node.out, node.in)
}
} else {
for (const node of nodes) {
node.y = Math.max(node.from?.[0]?.node?.y ?? 0, y)
y = node.y + Math.max(node.out, node.in)
}
nextYStart = nodes.find((node) => node.to.length)?.y ?? 0
}
maxY = Math.max(y, maxY);
maxY = Math.max(y, maxY)
}
return maxY;
return maxY
}

type NodeXYSize = Pick<SankeyNode, 'x' | 'y' | 'size'>
Expand Down Expand Up @@ -395,7 +401,7 @@ export function layout(
): { maxY: number; maxX: number } {
const nodeArray = [...nodes.values()]
const maxX = calculateX(nodes, data, modeX)
const maxY = priority ? calculateYUsingPriority(nodeArray, maxX) : calculateY(nodeArray, maxX)
const maxY = priority ? calculateYUsingPriority(nodeArray, maxX, modeX) : calculateY(nodeArray, maxX)
const padding = (maxY / height) * nodePadding
const maxYWithPadding = addPadding(nodeArray, padding)

Expand Down