nowthis / sankeymatic

Make Beautiful Flow Diagrams
http://sankeymatic.com/build/
ISC License
841 stars 122 forks source link

Color themes don't affect on the node of which name is in Chinese #53

Closed IvanaGyro closed 2 years ago

IvanaGyro commented 2 years ago

Here is an example input:

汽車[166] 汽車導致死亡事故
機車 [136] 機車導致死亡事故
汽車[52717] 汽車導致受傷事故
汽車[66859] 汽車導致無傷亡事故

機車 [53444] 機車導致受傷事故
機車 [10283] 機車導致無傷亡事故

汽車導致死亡事故 [9] 自撞死亡
汽車導致死亡事故 [157] 非自撞死亡
機車導致死亡事故 [42] 自撞死亡
機車導致死亡事故 [94] 非自撞死亡

汽車導致受傷事故 [376] 自撞
汽車導致受傷事故 [52341] 非自撞
機車導致受傷事故 [3417] 自撞
機車導致受傷事故 [50027] 非自撞
汽車導致無傷亡事故 [7] 自撞
汽車導致無傷亡事故 [66852] 非自撞
機車導致無傷亡事故 [1] 自撞
機車導致無傷亡事故 [10282] 非自撞

Preview when a color theme is selected: sankeymatic_20220415_011538_600x600

IvanaGyro commented 2 years ago

The first word of the node name is used to pick the color in the color scale: https://github.com/nowthis/sankeymatic/blob/abf6290747f6a7b37c4ad68ce2368a923e45c0a0/build/sankeymatic.js#L530

If all the characters of the node name are not in ASCII, the node name never passes the regular expression test /^\W*(\w+)/.

IvanaGyro commented 2 years ago

Can we pass the whole node name to scaleOrdinal?

nowthis commented 2 years ago

Thanks for the bug report, especially the sample inputs.

I will get this fixed soon; a week or less.

The algorithm ought look for 'anything which is not a space' instead of 'letters in the Latin alphabet'.

nowthis commented 2 years ago

The given inputs now produce a diagram with a fresh color assigned to each node: sankeymatic_20220417_140215_1200x1200