Skip to content

Commit

Permalink
fix: Sankey ordering should be based on data input, not inconsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
billyc committed Mar 16, 2022
1 parent 0f9bc47 commit 04f6a12
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
33 changes: 21 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"d3-array": "^3.1.1",
"d3-hexbin": "^0.2.2",
"d3-request": "^1.0.6",
"d3-sankey-diagram": "^0.7.3",
"d3-sankey-diagram": "^0.8.0",
"d3-scale": "^3.2.2",
"d3-scale-chromatic": "^1.5.0",
"d3-selection": "^1.4.1",
Expand Down
34 changes: 21 additions & 13 deletions src/plugins/sankey/SankeyDiagram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import globalStore from '@/store'
import { FileSystemConfig, VisualizationPlugin } from '@/Globals'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import { Context } from 'react'
interface SankeyYaml {
csv: string
Expand Down Expand Up @@ -211,22 +210,30 @@ class MyComponent extends Vue {
}
// build js object
const answer: {
nodes: { id: any; title: string }[]
links: { source: any; target: any; value: number }[]
} = { nodes: [], links: [] }
const fromOrder = [] as number[]
const toOrder = [] as number[]
const answer = {
nodes: [] as { id: any; title: string }[],
links: [] as { source: any; target: any; value: number }[],
// alignTypes: true,
ordering: [[fromOrder], [toOrder]],
}
const fromLookup: any = {}
const toLookup: any = {}
fromNodes.forEach((value: string, i: number) => {
answer.nodes.push({ id: i, title: value })
fromLookup[value] = i
fromNodes.forEach((title: string, i: number) => {
answer.nodes.push({ id: i, title })
fromLookup[title] = i
fromOrder.push(i)
})
toNodes.forEach((value: string, i: number) => {
answer.nodes.push({ id: i + fromNodes.length, title: value })
toLookup[value] = i + fromNodes.length
toNodes.forEach((title: string, i: number) => {
const offset = i + fromNodes.length
answer.nodes.push({ id: offset, title })
toLookup[title] = offset
toOrder.push(offset)
})
for (const link of links) {
Expand Down Expand Up @@ -267,8 +274,8 @@ class MyComponent extends Vue {
private doD3() {
const data = this.jsonChart
data.alignTypes = true
data.alignLinkTypes = true
// data.alignTypes = true
// data.alignLinkTypes = true
// figure out dimensions, depending on if we are in a dashboard or not
let box = document.querySelector(`#${this.cleanConfigId}`) as Element
Expand All @@ -279,6 +286,7 @@ class MyComponent extends Vue {
const layout = sankey()
.nodeWidth(8)
.ordering(data.ordering)
.extent([
[labelWidth, 0],
[width - labelWidth, height],
Expand Down

0 comments on commit 04f6a12

Please sign in to comment.