-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sankey): 修复桑基图 rawFields 在 label & tooltip 处不生效 (#2756)
* fix(sankey): 修复桑基图 rawFields 在 label & tooltip 处不生效 * fix: 修改 lint 问题
- Loading branch information
Showing
3 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Sankey } from '../../src'; | ||
import { createDiv, removeDom } from '../utils/dom'; | ||
import { PARALLEL_SET } from '../data/parallel-set'; | ||
|
||
describe('sankey', () => { | ||
const data = []; | ||
const keys = ['Survived', 'Sex', 'Age', 'Class']; | ||
PARALLEL_SET.forEach((d) => { | ||
keys.reduce((a, b) => { | ||
if (a && b) { | ||
data.push({ | ||
source: d[a], | ||
target: d[b], | ||
value: d.value, | ||
path: `${d[keys[0]]} -> ${d[keys[1]]} -> ${d[keys[2]]} -> ${d[keys[3]]}`, | ||
}); | ||
} | ||
return b; | ||
}); | ||
}); | ||
|
||
const dom = createDiv(); | ||
const sankey = new Sankey(dom, { | ||
data: data.map((d) => ({ ...d, append: 'hello' })), | ||
sourceField: 'source', | ||
targetField: 'target', | ||
weightField: 'value', | ||
rawFields: ['append'], | ||
nodeWidthRatio: 0.01, | ||
nodePaddingRatio: 0.03, | ||
nodeDraggable: true, | ||
}); | ||
|
||
sankey.render(); | ||
|
||
it('label', () => { | ||
sankey.update({ label: { formatter: () => 'HELLO' } }); | ||
expect(sankey.chart.views[1].geometries[0].labelsContainer.getChildByIndex(0).cfg.children[0].attr('text')).toBe( | ||
'HELLO' | ||
); | ||
// with rawFields | ||
sankey.update({ label: { formatter: ({ append }) => append } }); | ||
expect(sankey.chart.views[1].geometries[0].labelsContainer.getChildByIndex(0).cfg.children[0].attr('text')).toBe( | ||
'hello' | ||
); | ||
}); | ||
|
||
afterAll(() => { | ||
sankey.destroy(); | ||
removeDom(dom); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters