@@ -7,18 +7,26 @@ use plotly::{
77 ColorScale , ColorScalePalette , DashType , Domain , Fill , Font , HoverInfo , Line , LineShape ,
88 Marker , Mode , Orientation , Pattern , PatternShape ,
99 } ,
10+ icicle:: {
11+ BranchValues as IcicleBranchValues , Leaf as IcicleLeaf , Marker as IcicleMarker ,
12+ PathBar as IciclePathBar , Side as IcicleSide , Tiling as IcicleTiling ,
13+ } ,
1014 layout:: {
1115 AngularAxis , Annotation , Axis , AxisRange , BarMode , CategoryOrder , Layout , LayoutGrid ,
1216 LayoutPolar , Legend , PolarAxisAttributes , PolarAxisTicks , PolarDirection , RadialAxis ,
1317 TicksDirection , TraceOrder ,
1418 } ,
1519 sankey:: { Line as SankeyLine , Link , Node } ,
1620 sunburst:: { InsideTextOrientation , Leaf } ,
21+ traces:: indicator:: {
22+ Align , Delta , DeltaPosition , Direction , Gauge , GaugeAxis , GaugeBar , GaugeShape ,
23+ IndicatorTitle , Mode as IndicatorMode , Number , Step , Threshold ,
24+ } ,
1725 traces:: table:: {
1826 Align as TableAlign , Cells , Fill as TableFill , Font as TableFont , Header , Line as TableLine ,
1927 } ,
2028 treemap:: { BranchValues , Marker as TreemapMarker , Packing , PathBar , Side , Tiling } ,
21- Bar , Pie , Plot , Sankey , Scatter , ScatterPolar , Sunburst , Table , Treemap ,
29+ Bar , Icicle , Indicator , Pie , Plot , Sankey , Scatter , ScatterPolar , Sunburst , Table , Treemap ,
2230} ;
2331use plotly_utils:: write_example_to_html;
2432use rand_distr:: { Distribution , Normal , Uniform } ;
@@ -1147,6 +1155,137 @@ fn styled_sunburst(show: bool, file_name: &str) {
11471155}
11481156// ANCHOR_END: styled_sunburst
11491157
1158+ // Icicle Charts
1159+ // ANCHOR: basic_icicle
1160+ fn basic_icicle ( show : bool , file_name : & str ) {
1161+ let labels = vec ! [
1162+ "Eve" , "Cain" , "Seth" , "Enos" , "Noam" , "Abel" , "Awan" , "Enoch" , "Azura" ,
1163+ ] ;
1164+ let parents = vec ! [
1165+ "" , "Eve" , "Eve" , "Seth" , "Seth" , "Eve" , "Eve" , "Awan" , "Eve" ,
1166+ ] ;
1167+ let trace = Icicle :: new ( labels, parents)
1168+ . values ( vec ! [ 10.0 , 14.0 , 12.0 , 10.0 , 2.0 , 6.0 , 6.0 , 4.0 , 4.0 ] )
1169+ . text_info ( "label+value" ) ;
1170+
1171+ let mut plot = Plot :: new ( ) ;
1172+ plot. add_trace ( trace) ;
1173+
1174+ let path = write_example_to_html ( & plot, file_name) ;
1175+ if show {
1176+ plot. show_html ( path) ;
1177+ }
1178+ }
1179+ // ANCHOR_END: basic_icicle
1180+
1181+ // ANCHOR: styled_icicle
1182+ fn styled_icicle ( show : bool , file_name : & str ) {
1183+ let labels = vec ! [
1184+ "Total" ,
1185+ "Tech" ,
1186+ "Health" ,
1187+ "Finance" ,
1188+ "Software" ,
1189+ "Hardware" ,
1190+ "Pharma" ,
1191+ "Devices" ,
1192+ "Banking" ,
1193+ "Insurance" ,
1194+ ] ;
1195+ let parents = vec ! [
1196+ "" , "Total" , "Total" , "Total" , "Tech" , "Tech" , "Health" , "Health" , "Finance" , "Finance" ,
1197+ ] ;
1198+ let trace = Icicle :: new ( labels, parents)
1199+ . values ( vec ! [ 0.0 , 0.0 , 0.0 , 0.0 , 40.0 , 30.0 , 25.0 , 15.0 , 20.0 , 18.0 ] )
1200+ . branch_values ( IcicleBranchValues :: Remainder )
1201+ . marker ( IcicleMarker :: new ( ) . line ( Line :: new ( ) . width ( 1.0 ) . color ( NamedColor :: White ) ) )
1202+ . tiling (
1203+ IcicleTiling :: new ( )
1204+ . orientation ( Orientation :: Horizontal )
1205+ . pad ( 2.0 ) ,
1206+ )
1207+ . path_bar ( IciclePathBar :: new ( ) . visible ( true ) . side ( IcicleSide :: Top ) )
1208+ . leaf ( IcicleLeaf :: new ( ) . opacity ( 0.7 ) )
1209+ . text_info ( "label+value+percent parent" ) ;
1210+
1211+ let mut plot = Plot :: new ( ) ;
1212+ plot. add_trace ( trace) ;
1213+
1214+ let path = write_example_to_html ( & plot, file_name) ;
1215+ if show {
1216+ plot. show_html ( path) ;
1217+ }
1218+ }
1219+ // ANCHOR_END: styled_icicle
1220+
1221+ // Indicator Charts
1222+ // ANCHOR: basic_indicator
1223+ fn basic_indicator ( show : bool , file_name : & str ) {
1224+ let trace = Indicator :: new ( 120.0 )
1225+ . mode ( IndicatorMode :: NumberAndDelta )
1226+ . align ( Align :: Center )
1227+ . title ( IndicatorTitle :: new ( ) . text ( "Revenue" ) )
1228+ . number ( Number :: new ( ) . prefix ( "$" ) . value_format ( ".2f" ) )
1229+ . delta (
1230+ Delta :: new ( )
1231+ . reference ( 100.0 )
1232+ . relative ( true )
1233+ . position ( DeltaPosition :: Top )
1234+ . increasing ( Direction :: new ( ) . color ( NamedColor :: Green ) . symbol ( "▲" ) )
1235+ . decreasing ( Direction :: new ( ) . color ( NamedColor :: Red ) . symbol ( "▼" ) ) ,
1236+ )
1237+ . domain ( Domain :: new ( ) ) ;
1238+
1239+ let layout = Layout :: new ( ) . title ( "Basic Indicator" ) ;
1240+ let mut plot = Plot :: new ( ) ;
1241+ plot. set_layout ( layout) ;
1242+ plot. add_trace ( trace) ;
1243+
1244+ let path = write_example_to_html ( & plot, file_name) ;
1245+ if show {
1246+ plot. show_html ( path) ;
1247+ }
1248+ }
1249+ // ANCHOR_END: basic_indicator
1250+
1251+ // ANCHOR: indicator_gauge
1252+ fn indicator_gauge ( show : bool , file_name : & str ) {
1253+ let trace = Indicator :: new ( 270.0 )
1254+ . mode ( IndicatorMode :: Gauge )
1255+ . title ( IndicatorTitle :: new ( ) . text ( "Speed" ) )
1256+ . gauge (
1257+ Gauge :: new ( )
1258+ . shape ( GaugeShape :: Angular )
1259+ . axis ( GaugeAxis :: new ( ) . range ( [ 0.0 , 500.0 ] ) )
1260+ . bar ( GaugeBar :: new ( ) . color ( "darkblue" ) . thickness ( 0.75 ) )
1261+ . background_color ( NamedColor :: White )
1262+ . border_color ( NamedColor :: Gray )
1263+ . border_width ( 1.0 )
1264+ . steps ( vec ! [
1265+ Step :: new( ) . range( [ 0.0 , 250.0 ] ) . color( "lightgray" ) ,
1266+ Step :: new( ) . range( [ 250.0 , 400.0 ] ) . color( "gray" ) ,
1267+ ] )
1268+ . threshold (
1269+ Threshold :: new ( )
1270+ . line ( Line :: new ( ) . color ( NamedColor :: Red ) . width ( 4.0 ) )
1271+ . thickness ( 0.75 )
1272+ . value ( 490.0 ) ,
1273+ ) ,
1274+ )
1275+ . domain ( Domain :: new ( ) ) ;
1276+
1277+ let layout = Layout :: new ( ) . title ( "Indicator Gauge" ) ;
1278+ let mut plot = Plot :: new ( ) ;
1279+ plot. set_layout ( layout) ;
1280+ plot. add_trace ( trace) ;
1281+
1282+ let path = write_example_to_html ( & plot, file_name) ;
1283+ if show {
1284+ plot. show_html ( path) ;
1285+ }
1286+ }
1287+ // ANCHOR_END: indicator_gauge
1288+
11501289// ANCHOR: set_lower_or_upper_bound_on_axis
11511290fn set_lower_or_upper_bound_on_axis ( show : bool , file_name : & str ) {
11521291 use std:: fs:: File ;
@@ -1312,6 +1451,14 @@ fn main() {
13121451 basic_sunburst ( false , "basic_sunburst" ) ;
13131452 styled_sunburst ( false , "styled_sunburst" ) ;
13141453
1454+ // Icicle Charts
1455+ basic_icicle ( false , "basic_icicle" ) ;
1456+ styled_icicle ( false , "styled_icicle" ) ;
1457+
1458+ // Indicator Charts
1459+ basic_indicator ( false , "basic_indicator" ) ;
1460+ indicator_gauge ( false , "indicator_gauge" ) ;
1461+
13151462 // Set Lower or Upper Bound on Axis
13161463 set_lower_or_upper_bound_on_axis ( false , "set_lower_or_upper_bound_on_axis" ) ;
13171464}
0 commit comments