1
- use plotly:: {
2
- common:: Font ,
3
- layout:: { Axis as AxisPlotly , Legend as LegendPlotly } ,
4
- Layout as LayoutPlotly ,
5
- } ;
1
+ use plotly:: Layout as LayoutPlotly ;
6
2
7
3
use crate :: components:: { Axis , Legend , Text } ;
8
4
@@ -23,175 +19,9 @@ pub(crate) trait Layout {
23
19
layout = layout. title ( title. to_plotly ( ) ) ;
24
20
}
25
21
26
- layout = layout. x_axis ( Self :: set_axis ( x_title, x_axis) ) ;
27
- layout = layout. y_axis ( Self :: set_axis ( y_title, y_axis) ) ;
28
- layout = layout. legend ( Self :: set_legend ( legend_title, legend) ) ;
22
+ layout = layout. x_axis ( Axis :: set_axis ( x_title, x_axis) ) ;
23
+ layout = layout. y_axis ( Axis :: set_axis ( y_title, y_axis) ) ;
24
+ layout = layout. legend ( Legend :: set_legend ( legend_title, legend) ) ;
29
25
layout
30
26
}
31
-
32
- // TODO: Move axis functions to Axis struct like colorbar
33
- fn set_axis ( title : Option < Text > , format : Option < & Axis > ) -> AxisPlotly {
34
- let mut axis = AxisPlotly :: new ( ) ;
35
-
36
- if let Some ( title) = title {
37
- axis = axis. title ( title. to_plotly ( ) ) ;
38
- }
39
-
40
- if let Some ( format) = format {
41
- axis = Self :: set_axis_format ( axis, format) ;
42
- }
43
-
44
- axis
45
- }
46
-
47
- // TODO: Move legend functions to Axis struct like colorbar
48
- fn set_legend ( title : Option < Text > , format : Option < & Legend > ) -> LegendPlotly {
49
- let mut legend = LegendPlotly :: new ( ) ;
50
-
51
- if let Some ( title) = title {
52
- legend = legend. title ( title. to_plotly ( ) ) ;
53
- }
54
-
55
- if let Some ( format) = format {
56
- legend = Self :: set_legend_format ( legend, format) ;
57
- }
58
-
59
- legend
60
- }
61
-
62
- fn set_axis_format ( mut axis : AxisPlotly , format : & Axis ) -> AxisPlotly {
63
- if let Some ( visible) = format. show_axis {
64
- axis = axis. visible ( visible. to_owned ( ) ) ;
65
- }
66
-
67
- if let Some ( axis_position) = & format. axis_side {
68
- axis = axis. side ( axis_position. to_plotly ( ) ) ;
69
- }
70
-
71
- if let Some ( axis_type) = & format. axis_type {
72
- axis = axis. type_ ( axis_type. to_plotly ( ) ) ;
73
- }
74
-
75
- if let Some ( color) = format. value_color {
76
- axis = axis. color ( color. to_plotly ( ) ) ;
77
- }
78
-
79
- if let Some ( range) = & format. value_range {
80
- axis = axis. range ( range. to_owned ( ) ) ;
81
- }
82
-
83
- if let Some ( thousands) = format. value_thousands {
84
- axis = axis. separate_thousands ( thousands. to_owned ( ) ) ;
85
- }
86
-
87
- if let Some ( exponent) = & format. value_exponent {
88
- axis = axis. exponent_format ( exponent. to_plotly ( ) ) ;
89
- }
90
-
91
- if let Some ( range_values) = & format. tick_values {
92
- axis = axis. tick_values ( range_values. to_owned ( ) ) ;
93
- }
94
-
95
- if let Some ( tick_text) = & format. tick_labels {
96
- axis = axis. tick_text ( tick_text. to_owned ( ) ) ;
97
- }
98
-
99
- if let Some ( tick_direction) = & format. tick_direction {
100
- axis = axis. ticks ( tick_direction. to_plotly_tickdirection ( ) ) ;
101
- }
102
-
103
- if let Some ( tick_length) = format. tick_length {
104
- axis = axis. tick_length ( tick_length. to_owned ( ) ) ;
105
- }
106
-
107
- if let Some ( tick_width) = format. tick_width {
108
- axis = axis. tick_width ( tick_width. to_owned ( ) ) ;
109
- }
110
-
111
- if let Some ( color) = format. tick_color {
112
- axis = axis. tick_color ( color. to_plotly ( ) ) ;
113
- }
114
-
115
- if let Some ( tick_angle) = format. tick_angle {
116
- axis = axis. tick_angle ( tick_angle. to_owned ( ) ) ;
117
- }
118
-
119
- if let Some ( font) = & format. tick_font {
120
- axis = axis. tick_font ( Font :: new ( ) . family ( font. as_str ( ) ) ) ;
121
- }
122
-
123
- if let Some ( show_line) = format. show_line {
124
- axis = axis. show_line ( show_line. to_owned ( ) ) ;
125
- }
126
-
127
- if let Some ( color) = format. line_color {
128
- axis = axis. line_color ( color. to_plotly ( ) ) ;
129
- }
130
-
131
- if let Some ( line_width) = format. line_width {
132
- axis = axis. line_width ( line_width. to_owned ( ) ) ;
133
- }
134
-
135
- if let Some ( show_grid) = format. show_grid {
136
- axis = axis. show_grid ( show_grid. to_owned ( ) ) ;
137
- }
138
-
139
- if let Some ( color) = format. grid_color {
140
- axis = axis. grid_color ( color. to_plotly ( ) ) ;
141
- }
142
-
143
- if let Some ( grid_width) = format. grid_width {
144
- axis = axis. grid_width ( grid_width. to_owned ( ) ) ;
145
- }
146
-
147
- if let Some ( show_zero_line) = format. show_zero_line {
148
- axis = axis. zero_line ( show_zero_line. to_owned ( ) ) ;
149
- }
150
-
151
- if let Some ( color) = format. zero_line_color {
152
- axis = axis. zero_line_color ( color. to_plotly ( ) ) ;
153
- }
154
-
155
- if let Some ( zero_line_width) = format. zero_line_width {
156
- axis = axis. zero_line_width ( zero_line_width. to_owned ( ) ) ;
157
- }
158
-
159
- if let Some ( axis_position) = format. axis_position {
160
- axis = axis. position ( axis_position. to_owned ( ) ) ;
161
- }
162
-
163
- axis
164
- }
165
-
166
- fn set_legend_format ( mut legend : LegendPlotly , format : & Legend ) -> LegendPlotly {
167
- if let Some ( color) = format. background_color {
168
- legend = legend. background_color ( color. to_plotly ( ) ) ;
169
- }
170
-
171
- if let Some ( color) = format. border_color {
172
- legend = legend. border_color ( color. to_plotly ( ) ) ;
173
- }
174
-
175
- if let Some ( width) = format. border_width {
176
- legend = legend. border_width ( width) ;
177
- }
178
-
179
- if let Some ( font) = & format. font {
180
- legend = legend. font ( Font :: new ( ) . family ( font. as_str ( ) ) ) ;
181
- }
182
-
183
- if let Some ( orientation) = & format. orientation {
184
- legend = legend. orientation ( orientation. to_plotly ( ) ) ;
185
- }
186
-
187
- if let Some ( x) = format. x {
188
- legend = legend. x ( x) ;
189
- }
190
-
191
- if let Some ( y) = format. y {
192
- legend = legend. y ( y) ;
193
- }
194
-
195
- legend
196
- }
197
27
}
0 commit comments