@@ -36,7 +36,6 @@ def sankey_base() -> Sankey:
3636 )
3737 .set_global_opts (title_opts = opts .TitleOpts (title = "Sankey-基本示例" ))
3838 )
39-
4039 return c
4140
4241
@@ -58,4 +57,99 @@ def sankey_offical() -> Sankey:
5857 return c
5958
6059
60+ @C .funcs
61+ def sankey_vertical () -> Sankey :
62+ colors = [
63+ "#67001f" ,
64+ "#b2182b" ,
65+ "#d6604d" ,
66+ "#f4a582" ,
67+ "#fddbc7" ,
68+ "#d1e5f0" ,
69+ "#92c5de" ,
70+ "#4393c3" ,
71+ "#2166ac" ,
72+ "#053061" ,
73+ ]
74+ nodes = [
75+ {"name" : "a" },
76+ {"name" : "b" },
77+ {"name" : "a1" },
78+ {"name" : "b1" },
79+ {"name" : "c" },
80+ {"name" : "e" },
81+ ]
82+ links = [
83+ {"source" : "a" , "target" : "a1" , "value" : 5 },
84+ {"source" : "e" , "target" : "b" , "value" : 3 },
85+ {"source" : "a" , "target" : "b1" , "value" : 3 },
86+ {"source" : "b1" , "target" : "a1" , "value" : 1 },
87+ {"source" : "b1" , "target" : "c" , "value" : 2 },
88+ {"source" : "b" , "target" : "c" , "value" : 1 },
89+ ]
90+ c = (
91+ Sankey ()
92+ .set_colors (colors )
93+ .add (
94+ "sankey" ,
95+ nodes = nodes ,
96+ links = links ,
97+ pos_bottom = "10%" ,
98+ focus_node_adjacency = "allEdges" ,
99+ orient = "vertical" ,
100+ linestyle_opt = opts .LineStyleOpts (opacity = 0.2 , curve = 0.5 , color = "source" ),
101+ label_opts = opts .LabelOpts (position = "top" ),
102+ )
103+ .set_global_opts (
104+ title_opts = opts .TitleOpts (title = "Sankey-Vertical" ),
105+ tooltip_opts = opts .TooltipOpts (trigger = "item" , trigger_on = "mousemove" ),
106+ )
107+ )
108+ return c
109+
110+
111+ @C .funcs
112+ def sankey_with_level_setting () -> Sankey :
113+ with open (os .path .join ("fixtures" , "product.json" ), "r" , encoding = "utf-8" ) as f :
114+ j = json .load (f )
115+ c = (
116+ Sankey ()
117+ .add (
118+ "sankey" ,
119+ nodes = j ["nodes" ],
120+ links = j ["links" ],
121+ pos_top = "10%" ,
122+ focus_node_adjacency = True ,
123+ levels = [
124+ opts .SankeyLevelsOpts (
125+ depth = 0 ,
126+ itemstyle_opts = opts .ItemStyleOpts (color = "#fbb4ae" ),
127+ linestyle_opts = opts .LineStyleOpts (color = "source" , opacity = 0.6 ),
128+ ),
129+ opts .SankeyLevelsOpts (
130+ depth = 1 ,
131+ itemstyle_opts = opts .ItemStyleOpts (color = "#b3cde3" ),
132+ linestyle_opts = opts .LineStyleOpts (color = "source" , opacity = 0.6 ),
133+ ),
134+ opts .SankeyLevelsOpts (
135+ depth = 2 ,
136+ itemstyle_opts = opts .ItemStyleOpts (color = "#ccebc5" ),
137+ linestyle_opts = opts .LineStyleOpts (color = "source" , opacity = 0.6 ),
138+ ),
139+ opts .SankeyLevelsOpts (
140+ depth = 3 ,
141+ itemstyle_opts = opts .ItemStyleOpts (color = "#decbe4" ),
142+ linestyle_opts = opts .LineStyleOpts (color = "source" , opacity = 0.6 ),
143+ ),
144+ ],
145+ linestyle_opt = opts .LineStyleOpts (curve = 0.5 ),
146+ )
147+ .set_global_opts (
148+ title_opts = opts .TitleOpts (title = "Sankey-Level Settings" ),
149+ tooltip_opts = opts .TooltipOpts (trigger = "item" , trigger_on = "mousemove" ),
150+ )
151+ )
152+ return c
153+
154+
61155Page ().add (* [fn () for fn , _ in C .charts ]).render ()
0 commit comments