trading-charts 0.1.2

Rust binding of Lightweight Charts for Leptos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
pub struct TimeScaleOptions {
    #[serde(rename = "rightOffset", default = "defaults::right_offset")]
    pub right_offset: f64,

    #[serde(rename = "barSpacing", default = "defaults::bar_spacing")]
    pub bar_spacing: f64,

    #[serde(rename = "minBarWidth", default = "defaults::min_bar_width")]
    pub min_bar_width: f64,

    #[serde(rename = "fixLeftEdge", default = "defaults::fix_left_edge")]
    pub fix_left_edge: bool,

    #[serde(rename = "fixRightEdge", default = "defaults::fix_right_edge")]
    pub fix_right_edge: bool,

    #[serde(
        rename = "lockVisibleTimeRangeOnResize",
        default = "defaults::lock_visible_time_range_on_resize"
    )]
    pub lock_visible_time_range_on_resize: bool,

    #[serde(rename = "rightBarStaysOnScroll", default = "defaults::right_bar_stays_on_scroll")]
    pub right_bar_stays_on_scroll: bool,

    #[serde(rename = "borderVisible", default = "defaults::border_visible")]
    pub border_visible: bool,

    #[serde(rename = "borderColor", default = "defaults::border_color")]
    pub border_color: String,

    #[serde(rename = "visible", default = "defaults::visible")]
    pub visible: bool,

    #[serde(rename = "timeVisible", default = "defaults::time_visible")]
    pub time_visible: bool,

    #[serde(rename = "secondsVisible", default = "defaults::seconds_visible")]
    pub seconds_visible: bool,

    #[serde(
        rename = "shiftVisibleRangeOnNewBar",
        default = "defaults::shift_visible_range_on_new_bar"
    )]
    pub shift_visible_range_on_new_bar: bool,

    #[serde(
        rename = "allowShiftVisibleRangeOnWhitespaceReplacement",
        default = "defaults::allow_shift_visible_etc"
    )]
    pub allow_shift_visible_range_on_whitespace_replacement: bool,

    #[serde(rename = "ticksVisible", default = "defaults::ticks_visible")]
    pub ticks_visible: bool,

    #[serde(
        rename = "tickMarkMaxCharacterLength",
        skip_serializing_if = "Option::is_none",
        default
    )]
    pub tick_mark_max_character_length: Option<usize>,

    #[serde(rename = "uniformDistribution", default = "defaults::uniform_distribution")]
    pub uniform_distribution: bool,

    #[serde(rename = "minimumHeight", default = "defaults::minimum_height")]
    pub minimum_height: f64,

    #[serde(rename = "allowBoldLabels", default = "defaults::allow_bold_labels")]
    pub allow_bold_labels: bool,
}

impl TimeScaleOptions {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn with_right_offset(self, right_offset: f64) -> Self {
        Self {
            right_offset,
            ..self
        }
    }

    pub fn with_bar_spacing(self, bar_spacing: f64) -> Self {
        Self {
            bar_spacing,
            ..self
        }
    }

    pub fn with_min_bar_width(self, min_bar_width: f64) -> Self {
        Self {
            min_bar_width,
            ..self
        }
    }

    pub fn with_fix_left_edge(self, fix_left_edge: bool) -> Self {
        Self {
            fix_left_edge,
            ..self
        }
    }

    pub fn with_fix_right_edge(self, fix_right_edge: bool) -> Self {
        Self {
            fix_right_edge,
            ..self
        }
    }

    pub fn with_lock_visible_time_range_on_resize(self, lock_visible_time_range_on_resize: bool) -> Self {
        Self {
            lock_visible_time_range_on_resize,
            ..self
        }
    }

    pub fn with_right_bar_stays_on_scroll(self, right_bar_stays_on_scroll: bool) -> Self {
        Self {
            right_bar_stays_on_scroll,
            ..self
        }
    }

    pub fn with_border_visible(self, border_visible: bool) -> Self {
        Self {
            border_visible,
            ..self
        }
    }

    pub fn with_border_color(self, border_color: String) -> Self {
        Self {
            border_color,
            ..self
        }
    }

    pub fn with_visible(self, visible: bool) -> Self {
        Self {
            visible,
            ..self
        }
    }

    pub fn with_time_visible(self, time_visible: bool) -> Self {
        Self {
            time_visible,
            ..self
        }
    }

    pub fn with_seconds_visible(self, seconds_visible: bool) -> Self {
        Self {
            seconds_visible,
            ..self
        }
    }

    pub fn with_shift_visible_range_on_new_bar(self, shift_visible_range_on_new_bar: bool) -> Self {
        Self {
            shift_visible_range_on_new_bar,
            ..self
        }
    }

    pub fn with_allow_shift_visible_range_on_whitespace_replacement(
        self,
        allow_shift_visible_range_on_whitespace_replacement: bool,
    ) -> Self {
        Self {
            allow_shift_visible_range_on_whitespace_replacement,
            ..self
        }
    }

    pub fn with_ticks_visible(self, ticks_visible: bool) -> Self {
        Self {
            ticks_visible,
            ..self
        }
    }

    pub fn with_tick_mark_max_character_length(self, tick_mark_max_character_length: Option<usize>) -> Self {
        Self {
            tick_mark_max_character_length,
            ..self
        }
    }

    pub fn with_uniform_distribution(self, uniform_distribution: bool) -> Self {
        Self {
            uniform_distribution,
            ..self
        }
    }

    pub fn with_minimum_height(self, minimum_height: f64) -> Self {
        Self {
            minimum_height,
            ..self
        }
    }

    pub fn with_allow_bold_labels(self, allow_bold_labels: bool) -> Self {
        Self {
            allow_bold_labels,
            ..self
        }
    }

    pub fn right_offset(&self) -> f64 {
        self.right_offset
    }

    pub fn set_right_offset(&mut self, right_offset: f64) {
        self.right_offset = right_offset;
    }

    pub fn bar_spacing(&self) -> f64 {
        self.bar_spacing
    }

    pub fn set_bar_spacing(&mut self, bar_spacing: f64) {
        self.bar_spacing = bar_spacing;
    }

    pub fn min_bar_width(&self) -> f64 {
        self.min_bar_width
    }

    pub fn set_min_bar_width(&mut self, min_bar_width: f64) {
        self.min_bar_width = min_bar_width;
    }

    pub fn fix_left_edge(&self) -> bool {
        self.fix_left_edge
    }

    pub fn set_fix_left_edge(&mut self, fix_left_edge: bool) {
        self.fix_left_edge = fix_left_edge;
    }

    pub fn fix_right_edge(&self) -> bool {
        self.fix_right_edge
    }

    pub fn set_fix_right_edge(&mut self, fix_right_edge: bool) {
        self.fix_right_edge = fix_right_edge;
    }

    pub fn lock_visible_time_range_on_resize(&self) -> bool {
        self.lock_visible_time_range_on_resize
    }

    pub fn set_lock_visible_time_range_on_resize(&mut self, lock_visible_time_range_on_resize: bool) {
        self.lock_visible_time_range_on_resize = lock_visible_time_range_on_resize;
    }

    pub fn right_bar_stays_on_scroll(&self) -> bool {
        self.right_bar_stays_on_scroll
    }

    pub fn set_right_bar_stays_on_scroll(&mut self, right_bar_stays_on_scroll: bool) {
        self.right_bar_stays_on_scroll = right_bar_stays_on_scroll;
    }

    pub fn border_visible(&self) -> bool {
        self.border_visible
    }

    pub fn set_border_visible(&mut self, border_visible: bool) {
        self.border_visible = border_visible;
    }

    pub fn border_color(&self) -> &str {
        &self.border_color
    }

    pub fn set_border_color(&mut self, border_color: String) {
        self.border_color = border_color;
    }

    pub fn visible(&self) -> bool {
        self.visible
    }

    pub fn set_visible(&mut self, visible: bool) {
        self.visible = visible;
    }

    pub fn time_visible(&self) -> bool {
        self.time_visible
    }

    pub fn set_time_visible(&mut self, time_visible: bool) {
        self.time_visible = time_visible;
    }

    pub fn seconds_visible(&self) -> bool {
        self.seconds_visible
    }

    pub fn set_seconds_visible(&mut self, seconds_visible: bool) {
        self.seconds_visible = seconds_visible;
    }

    pub fn shift_visible_range_on_new_bar(&self) -> bool {
        self.shift_visible_range_on_new_bar
    }

    pub fn set_shift_visible_range_on_new_bar(&mut self, shift_visible_range_on_new_bar: bool) {
        self.shift_visible_range_on_new_bar = shift_visible_range_on_new_bar;
    }

    pub fn allow_shift_visible_range_on_whitespace_replacement(&self) -> bool {
        self.allow_shift_visible_range_on_whitespace_replacement
    }

    pub fn set_allow_shift_visible_range_on_whitespace_replacement(
        &mut self,
        allow_shift_visible_range_on_whitespace_replacement: bool,
    ) {
        self.allow_shift_visible_range_on_whitespace_replacement = allow_shift_visible_range_on_whitespace_replacement;
    }

    pub fn ticks_visible(&self) -> bool {
        self.ticks_visible
    }

    pub fn set_ticks_visible(&mut self, ticks_visible: bool) {
        self.ticks_visible = ticks_visible;
    }

    pub fn tick_mark_max_character_length(&self) -> Option<usize> {
        self.tick_mark_max_character_length
    }

    pub fn set_tick_mark_max_character_length_value(&mut self, tick_mark_max_character_length: Option<usize>) {
        self.tick_mark_max_character_length = tick_mark_max_character_length;
    }

    pub fn set_tick_mark_max_character_length(&mut self, tick_mark_max_character_length: usize) {
        self.tick_mark_max_character_length
            .replace(tick_mark_max_character_length);
    }

    pub fn reset_tick_mark_max_character_length(&mut self) {
        self.tick_mark_max_character_length = None;
    }

    pub fn uniform_distribution(&self) -> bool {
        self.uniform_distribution
    }

    pub fn set_uniform_distribution(&mut self, uniform_distribution: bool) {
        self.uniform_distribution = uniform_distribution;
    }

    pub fn minimum_height(&self) -> f64 {
        self.minimum_height
    }

    pub fn set_minimum_height(&mut self, minimum_height: f64) {
        self.minimum_height = minimum_height;
    }

    pub fn allow_bold_labels(&self) -> bool {
        self.allow_bold_labels
    }

    pub fn set_allow_bold_labels(&mut self, allow_bold_labels: bool) {
        self.allow_bold_labels = allow_bold_labels;
    }
}

impl Default for TimeScaleOptions {
    fn default() -> Self {
        Self {
            right_offset: defaults::right_offset(),
            bar_spacing: defaults::bar_spacing(),
            min_bar_width: defaults::min_bar_width(),
            fix_left_edge: defaults::fix_left_edge(),
            fix_right_edge: defaults::fix_right_edge(),
            lock_visible_time_range_on_resize: defaults::lock_visible_time_range_on_resize(),
            right_bar_stays_on_scroll: defaults::right_bar_stays_on_scroll(),
            border_visible: defaults::border_visible(),
            border_color: defaults::border_color(),
            visible: defaults::visible(),
            time_visible: defaults::time_visible(),
            seconds_visible: defaults::seconds_visible(),
            shift_visible_range_on_new_bar: defaults::shift_visible_range_on_new_bar(),
            allow_shift_visible_range_on_whitespace_replacement: defaults::allow_shift_visible_etc(),
            ticks_visible: defaults::ticks_visible(),
            tick_mark_max_character_length: None,
            uniform_distribution: defaults::uniform_distribution(),
            minimum_height: defaults::minimum_height(),
            allow_bold_labels: defaults::allow_bold_labels(),
        }
    }
}

mod defaults {
    pub(super) fn right_offset() -> f64 {
        0.
    }

    pub(super) fn bar_spacing() -> f64 {
        6.
    }

    pub(super) fn min_bar_width() -> f64 {
        0.5
    }

    pub(super) fn fix_left_edge() -> bool {
        false
    }

    pub(super) fn fix_right_edge() -> bool {
        false
    }

    pub(super) fn lock_visible_time_range_on_resize() -> bool {
        false
    }

    pub(super) fn right_bar_stays_on_scroll() -> bool {
        false
    }

    pub(super) fn border_visible() -> bool {
        true
    }

    pub(super) fn border_color() -> String {
        String::from("#2B2B43")
    }

    pub(super) fn visible() -> bool {
        true
    }

    pub(super) fn time_visible() -> bool {
        false
    }

    pub(super) fn seconds_visible() -> bool {
        true
    }

    pub(super) fn shift_visible_range_on_new_bar() -> bool {
        true
    }

    pub(super) fn allow_shift_visible_etc() -> bool {
        false
    }

    pub(super) fn ticks_visible() -> bool {
        false
    }

    pub(super) fn uniform_distribution() -> bool {
        false
    }

    pub(super) fn minimum_height() -> f64 {
        0.
    }

    pub(super) fn allow_bold_labels() -> bool {
        true
    }
}