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
43 changes: 43 additions & 0 deletions samples/parsing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

<!doctype html>
<html>

<head>
<title>Sankey diagram</title>
<script src="utils.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</link>
</head>

<body>
<div class="canvas-holder">
<canvas id="chart-area"></canvas>
</div>

<script>
Utils.load(() => {
Chart.defaults.font.size = 9;
const ctx = document.getElementById('chart-area').getContext('2d');
window.chart = new Chart(ctx, {
type: 'sankey',
data: {
datasets: [{
data: [
{source: 'a', dest: 'b', value: 20},
{source: 'c', dest: 'd', value: 10},
{source: 'c', dest: 'e', value: 5},
],
parsing: { from: 'source', to: 'dest', flow: 'value' }
}],
},
options: {
animation: false,
responsive: false
}
});

});
</script>
</body>

</html>
5 changes: 3 additions & 2 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
return ''
},
label(context) {
const item = context.dataset.data[context.dataIndex]
return item.from + ' -> ' + item.to + ': ' + item.flow
const parsedCustom = context.parsed._custom
return parsedCustom.from.key + ' -> ' + parsedCustom.to.key + ': ' + parsedCustom.flow
},
},
},
Expand Down Expand Up @@ -128,7 +128,7 @@
private _maxX: number
private _maxY: number

override parseObjectData(

Check warning on line 131 in src/controller.ts

View workflow job for this annotation

GitHub Actions / ci

Method 'parseObjectData' has a complexity of 17. Maximum allowed is 10
meta: ChartMeta<'sankey', Flow>,
data: AnyObject[],
start: number,
Expand Down Expand Up @@ -183,6 +183,7 @@
x: xScale.parse(to.x, i) as number,
y: yScale.parse(toY, i) as number,
height: yScale.parse(dataPoint.flow, i) as number,
flow: dataPoint.flow,
},
})
}
Expand Down Expand Up @@ -241,7 +242,7 @@
this.updateSharedOptions(sharedOptions, mode, firstOpts)
}

private _drawLabels() {

Check warning on line 245 in src/controller.ts

View workflow job for this annotation

GitHub Actions / ci

Method '_drawLabels' has a complexity of 13. Maximum allowed is 10
const ctx = this.chart.ctx
const options = this.options
const nodes = this._nodes || new Map()
Expand Down Expand Up @@ -297,7 +298,7 @@
}
}

private _drawNodes() {

Check warning on line 301 in src/controller.ts

View workflow job for this annotation

GitHub Actions / ci

Method '_drawNodes' has a complexity of 11. Maximum allowed is 10
const ctx = this.chart.ctx
const nodes = this._nodes || new Map()
const { borderColor, borderWidth = 0, nodeWidth = 10, size } = this.options
Expand Down
1 change: 1 addition & 0 deletions types/index.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
addY: number
flow: number
key: string
node: SankeyNode

Check warning on line 54 in types/index.esm.d.ts

View workflow job for this annotation

GitHub Actions / ci

'SankeyNode' was used before it was defined
index: number
}

Expand Down Expand Up @@ -84,6 +84,7 @@
x: number
y: number
height: number
flow: number
}
}

Expand All @@ -94,7 +95,7 @@
parsedDataType: SankeyParsedData
metaExtensions: AnyObject
/* TODO: define sankey chart options */
chartOptions: FlowOptions

Check warning on line 98 in types/index.esm.d.ts

View workflow job for this annotation

GitHub Actions / ci

'FlowOptions' was used before it was defined
scales: keyof CartesianScaleTypeRegistry
}
}
Expand Down