poloto 19.1.2

Simple 2D plotting library that outputs SVG and can be styled using CSS
Documentation
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
//!
//! Tools to render plots
//!

use crate::build::{PlotIterator, PlotRes, Point};

use super::*;
mod render_base;
mod render_plot;

///
/// Specify options for the svg plots
///
#[derive(Clone)]
pub struct RenderFrameBuilder {
    num_css_classes: Option<usize>,
    preserve_aspect: bool,
    dim: Option<[f64; 2]>,
    xtick_lines: bool,
    ytick_lines: bool,
    precision: usize,
    bar_width: f64,
}

impl Default for RenderFrameBuilder {
    fn default() -> Self {
        RenderFrameBuilder {
            num_css_classes: Some(8),
            preserve_aspect: false,
            dim: None,
            xtick_lines: false,
            ytick_lines: false,
            precision: 2,
            bar_width: 20.0,
        }
    }
}

impl RenderFrameBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    pub fn with_viewbox(&mut self, dim: [f64; 2]) -> &mut Self {
        self.dim = Some(dim);
        self
    }

    pub fn with_tick_lines(&mut self, a: [bool; 2]) -> &mut Self {
        self.xtick_lines = a[0];
        self.ytick_lines = a[1];
        self
    }

    ///
    /// The number of distinct css classes. If there are more plots than
    /// classes, then they will wrap around. The default value is 8.
    ///
    /// A value of None, means it will never wrap around.
    ///
    pub fn num_css_class(&mut self, a: Option<usize>) -> &mut Self {
        self.num_css_classes = a;
        self
    }

    ///
    /// Specify the number of decimal places of each plot value in the SVG output itself.
    /// Defaults to a precision of 2 (2 decimal places).
    ///
    /// For most usecases, you don't need a high precision. However, if you plan on blowing
    /// up the svg output significantly or zooming in a bunch, then you might want better
    /// precision.
    ///
    pub fn with_precision(&mut self, precision: usize) -> &mut Self {
        self.precision = precision;
        self
    }
    ///
    /// Preserve the aspect ratio by drawing a smaller graph in the same area.
    ///
    pub fn preserve_aspect(&mut self) -> &mut Self {
        self.preserve_aspect = true;
        self
    }

    pub fn bar_width(&mut self, val: f64) -> &mut Self {
        self.bar_width = val;
        self
    }

    #[deprecated]
    pub fn move_into(&mut self) -> Self {
        self.clone()
    }

    pub fn build(&self) -> RenderFrame {
        let (width, height) = if let Some([x, y]) = self.dim {
            (x, y)
        } else {
            let [x, y] = Header::new().get_viewbox();
            (x, y)
        };

        let ideal_dash_size = 20.0;
        let padding = 150.0;
        let paddingy = 100.0;

        //The range over which the data will be scaled to fit
        let (scalex, scaley) = if self.preserve_aspect {
            if width > height {
                (height - paddingy * 2.0, height - paddingy * 2.0)
            } else {
                (width - padding * 2.0, width - padding * 2.0)
            }
        } else {
            (width - padding * 2.0, height - paddingy * 2.0)
        };

        let distancex_min_to_max = scalex;
        let distancey_min_to_max = scaley;

        let (xaspect_offset, yaspect_offset) = if self.preserve_aspect {
            if width > height {
                (-padding + width / 2.0 - distancey_min_to_max / 2.0, 0.0)
            } else {
                (
                    0.0,
                    -height + paddingy + height / 2.0 + distancey_min_to_max / 2.0,
                )
            }
        } else {
            (0.0, 0.0)
        };

        let ideal_xtick_spacing = 80.0;

        let ideal_ytick_spacing = 60.0;

        let ideal_num_xsteps = (distancex_min_to_max / ideal_xtick_spacing).floor() as u32;
        let ideal_num_ysteps = (distancey_min_to_max / ideal_ytick_spacing).floor() as u32;
        let ideal_num_xsteps = ideal_num_xsteps.max(2);
        let ideal_num_ysteps = ideal_num_ysteps.max(2);

        let spacing = padding / 3.0;
        let legendx1 = width - padding / 1.2 + padding / 30.0;

        RenderFrame {
            boundx: ticks::RenderFrameBound {
                ideal_num_steps: ideal_num_xsteps,
                ideal_dash_size,
                max: scalex,
                axis: Axis::X,
            },
            boundy: ticks::RenderFrameBound {
                ideal_num_steps: ideal_num_ysteps,
                ideal_dash_size,
                max: scaley,
                axis: Axis::Y,
            },

            width,
            height,
            padding,
            paddingy,
            xaspect_offset,
            yaspect_offset,
            spacing,
            legendx1,
            num_css_classes: self.num_css_classes,
            xtick_lines: self.xtick_lines,
            ytick_lines: self.ytick_lines,
            precision: self.precision,
            bar_width: self.bar_width,
        }
    }
}

///
/// Contains graphical information for a svg graph.
///
#[derive(Clone)]
pub struct RenderFrame {
    boundx: ticks::RenderFrameBound,
    boundy: ticks::RenderFrameBound,
    width: f64,
    height: f64,
    padding: f64,
    paddingy: f64,
    xaspect_offset: f64,
    yaspect_offset: f64,
    spacing: f64,
    legendx1: f64,
    num_css_classes: Option<usize>,
    xtick_lines: bool,
    ytick_lines: bool,
    precision: usize,
    bar_width: f64,
}

impl RenderFrame {
    pub fn data<X: PlotNum, Y: PlotNum, L: Point<X = X, Y = Y>, J: build::PlotIterator<L = L>>(
        self,
        plots: J,
    ) -> Stage1<PlotRes<J::P, L>, X::DefaultTicks, Y::DefaultTicks>
    where
        X: HasDefaultTicks,
        Y: HasDefaultTicks,
    {
        render::Stage1::from_parts(plots, X::default_ticks(), Y::default_ticks(), self)
    }
}

#[deprecated]
pub fn render_opt() -> RenderFrameBuilder {
    RenderFrameBuilder::default()
}

///
/// Link some plots with a way to render them.
///
pub struct Stage1<P: PlotIterator, TX, TY> {
    //TODO make this a reference eventually
    opt: RenderFrame,
    tickx: TX,
    ticky: TY,
    plots: P,
    boundx: DataBound<<P::L as Point>::X>,
    boundy: DataBound<<P::L as Point>::Y>,
}

impl<X: PlotNum, Y: PlotNum, L: Point<X = X, Y = Y>, P: build::PlotIterator<L = L>>
    Stage1<P, X::DefaultTicks, Y::DefaultTicks>
where
    X: HasDefaultTicks,
    Y: HasDefaultTicks,
{
    pub fn new(plots: P) -> Stage1<PlotRes<P::P, L>, X::DefaultTicks, Y::DefaultTicks> {
        Self::from_parts(
            plots,
            X::default_ticks(),
            Y::default_ticks(),
            RenderFrameBuilder::new().build(),
        )
    }
}

impl<
        X: PlotNum,
        Y: PlotNum,
        L: Point<X = X, Y = Y>,
        P: build::PlotIterator<L = L>,
        TX: TickDistGen<X>,
        TY: TickDistGen<Y>,
    > Stage1<P, TX, TY>
{
    pub fn from_parts(
        plots: P,
        tickx: TX,
        ticky: TY,
        opt: RenderFrame,
    ) -> Stage1<PlotRes<P::P, L>, TX, TY> {
        let PlotRes {
            area,
            it,
            num_plots,
        } = plots.unpack();

        let (boundx, boundy) = area.build();

        Stage1 {
            opt,
            plots: PlotRes {
                it,
                area,
                num_plots,
            },
            ticky,
            tickx,
            boundx,
            boundy,
        }
    }

    #[deprecated]
    pub fn map_opt<F: FnOnce(RenderFrame) -> RenderFrame>(self, func: F) -> Self {
        Stage1 {
            opt: func(self.opt),
            tickx: self.tickx,
            ticky: self.ticky,
            plots: self.plots,
            boundx: self.boundx,
            boundy: self.boundy,
        }
    }
    pub fn map_xticks<TTT: TickDistGen<X>, F: FnOnce(TX) -> TTT>(
        self,
        func: F,
    ) -> Stage1<P, TTT, TY> {
        let tickx = func(self.tickx);
        Stage1 {
            opt: self.opt,
            tickx,
            ticky: self.ticky,
            plots: self.plots,
            boundx: self.boundx,
            boundy: self.boundy,
        }
    }

    pub fn map_yticks<TTT: TickDistGen<Y>, F: FnOnce(TY) -> TTT>(
        self,
        func: F,
    ) -> Stage1<P, TX, TTT> {
        let ticky = func(self.ticky);
        Stage1 {
            opt: self.opt,
            tickx: self.tickx,
            ticky,
            plots: self.plots,
            boundx: self.boundx,
            boundy: self.boundy,
        }
    }

    pub fn build_map<F: FnOnce(Stage2<P, TX::Res, TY::Res>) -> K, K>(self, func: F) -> K {
        let k = self.build();
        func(k)
    }

    pub fn build(self) -> Stage2<P, TX::Res, TY::Res> {
        let mut index_counter = 0;
        let data = self;
        let opt = data.opt;

        let xticks = data.tickx.generate(
            &data.boundx,
            &opt.boundx,
            IndexRequester::new(&mut index_counter),
        );
        let yticks = data.ticky.generate(
            &data.boundy,
            &opt.boundy,
            IndexRequester::new(&mut index_counter),
        );
        Stage2 {
            opt,
            xticks,
            yticks,
            boundx: data.boundx,
            boundy: data.boundy,
            plots: data.plots,
        }
    }

    pub fn build_and_label<Fmt: BaseFmt>(self, fmt: Fmt) -> Stage3<P, TX::Res, TY::Res, Fmt> {
        self.build().label(fmt)
    }
}

pub struct Stage2<P: PlotIterator, A, B> {
    opt: RenderFrame,
    xticks: A,
    yticks: B,
    plots: P,
    boundx: DataBound<<P::L as Point>::X>,
    boundy: DataBound<<P::L as Point>::Y>,
}

impl<
        X: PlotNum,
        Y: PlotNum,
        L: Point<X = X, Y = Y>,
        P: PlotIterator<L = L>,
        A: TickDist<Num = X>,
        B: TickDist<Num = Y>,
    > Stage2<P, A, B>
{
    pub fn label<Fmt: BaseFmt>(self, fmt: Fmt) -> Stage3<P, A, B, Fmt> {
        Stage3 {
            data: self,
            base: fmt,
        }
    }

    pub fn boundx(&self) -> &DataBound<X> {
        &self.boundx
    }

    pub fn boundy(&self) -> &DataBound<Y> {
        &self.boundy
    }

    pub fn xticks(&self) -> &A {
        &self.xticks
    }
    pub fn yticks(&self) -> &B {
        &self.yticks
    }

    // pub fn map_xticks<X: TickDist<Num = P::X>, F: FnOnce(A) -> X>(
    //     self,
    //     func: F,
    // ) -> DataBuilt<P, X, B> {
    //     let k = func(self.xticks);
    //     DataBuilt {
    //         opt: self.opt,
    //         xticks: k,
    //         yticks: self.yticks,
    //         plots: self.plots,
    //         boundx: self.boundx,
    //         boundy: self.boundy,
    //     }
    // }

    // pub fn map_yticks<Y: TickDist<Num = P::Y>, F: FnOnce(B) -> Y>(
    //     self,
    //     func: F,
    // ) -> DataBuilt<P, A, Y> {
    //     let k = func(self.yticks);
    //     DataBuilt {
    //         opt: self.opt,
    //         xticks: self.xticks,
    //         yticks: k,
    //         plots: self.plots,
    //         boundx: self.boundx,
    //         boundy: self.boundy,
    //     }
    // }
}

pub struct Stage3<P: PlotIterator, A, B, BB> {
    data: Stage2<P, A, B>,
    base: BB,
}

impl<X: PlotNum, Y: PlotNum, L: Point<X = X, Y = Y>, P, A, B, BB> Stage3<P, A, B, BB>
where
    P: PlotIterator<L = L>,
    A: crate::ticks::TickDist<Num = X>,
    B: crate::ticks::TickDist<Num = Y>,
    BB: BaseFmt,
{
    pub fn append_to<E: Elem>(self, elem: E) -> Stage4<elem::Append<E, Self>> {
        Stage4(elem.append(self))
    }

    pub fn headless(self) -> Stage4<Self> {
        Stage4(self)
    }
}

use tagu::stack::*;
impl<X: PlotNum, Y: PlotNum, L: Point<X = X, Y = Y>, P, A, B, BB> ElemOuter for Stage3<P, A, B, BB>
where
    P: PlotIterator<L = L>,
    A: crate::ticks::TickDist<Num = X>,
    B: crate::ticks::TickDist<Num = Y>,
    BB: BaseFmt,
{
    fn render<'a>(
        mut self,
        mut writer: ElemStack<'a, Sentinel>,
    ) -> Result<ElemStack<'a, Sentinel>, fmt::Error> {
        writer.put(hbuild::single("circle").with(attrs!(
            ("r", "1e5"),
            ("class", "poloto_background"),
            ("fill", "white")
        )))?;

        let writer = render::render_plot::render_plot(
            writer,
            &self.data.boundx,
            &self.data.boundy,
            &self.data.opt,
            self.data.plots,
        )?;

        render::render_base::render_base(
            writer,
            self.data.xticks,
            self.data.yticks,
            &self.data.boundx,
            &self.data.boundy,
            &mut self.base,
            &self.data.opt,
        )
    }
}

impl<A, B, C> BaseFmt for (A, B, C)
where
    A: Display,
    B: Display,
    C: Display,
{
    fn write_title(&self, writer: &mut dyn fmt::Write) -> fmt::Result {
        write!(writer, "{}", self.0)
    }
    fn write_xname(&self, writer: &mut dyn fmt::Write) -> fmt::Result {
        write!(writer, "{}", self.1)
    }
    fn write_yname(&self, writer: &mut dyn fmt::Write) -> fmt::Result {
        write!(writer, "{}", self.2)
    }
}

pub struct Stage4<R>(R);
impl<R: Elem + Locked> Stage4<R> {
    pub fn render_stdout(self) {
        tagu::render(self.0, tagu::stdout_fmt()).unwrap()
    }

    pub fn render_fmt_write<T: fmt::Write>(self, w: T) -> fmt::Result {
        tagu::render(self.0, w)
    }

    pub fn render_io_write<T: std::io::Write>(self, w: T) -> std::fmt::Result {
        tagu::render(self.0, tagu::tools::upgrade_write(w))
    }

    pub fn render_string(self) -> Result<String, fmt::Error> {
        let mut s = String::new();
        tagu::render(self.0, &mut s)?;
        Ok(s)
    }
}

impl<R> Locked for Stage4<R> {}

impl<R: Elem> Elem for Stage4<R> {
    type Tail = R::Tail;

    fn render_head(self, w: elem::ElemWrite) -> Result<Self::Tail, fmt::Error> {
        self.0.render_head(w)
    }
}

///
/// Default svg header
///
#[derive(Copy, Clone)]
pub struct Header<A> {
    dim: [f64; 2],
    viewbox: [f64; 2],
    attr: A,
}
impl Default for Header<()> {
    fn default() -> Self {
        Self::new()
    }
}

use tagu::{attr::Attr, elem::Locked};
impl Header<()> {
    pub fn new() -> Self {
        let a = [800.0, 500.0];
        Header {
            dim: a,
            viewbox: a,
            attr: (),
        }
    }
}

impl<A: Attr> Header<A> {
    pub fn with<AA: Attr>(self, attr: AA) -> Header<AA> {
        Header {
            dim: self.dim,
            viewbox: self.viewbox,
            attr,
        }
    }

    pub fn with_viewbox_width(self, width: f64) -> Self {
        let [xx, yy] = self.dim;
        let vh = width * (yy / xx);
        Header {
            dim: self.dim,
            viewbox: [width, vh],
            attr: self.attr,
        }
    }

    pub fn get_viewbox(&self) -> [f64; 2] {
        self.viewbox
    }

    pub fn with_dim(self, dim: [f64; 2]) -> Self {
        Header {
            dim,
            viewbox: self.viewbox,
            attr: self.attr,
        }
    }
    pub fn with_viewbox(self, viewbox: [f64; 2]) -> Self {
        Header {
            dim: self.dim,
            viewbox,
            attr: self.attr,
        }
    }

    pub fn light_theme(self) -> elem::Append<Self, Theme<'static>> {
        self.append(Theme::light())
    }
    pub fn dark_theme(self) -> elem::Append<Self, Theme<'static>> {
        self.append(Theme::dark())
    }
}

impl<A> Locked for Header<A> {}
impl<A: Attr> Elem for Header<A> {
    type Tail = tagu::elem::ElementTail<&'static str>;
    fn render_head(self, w: elem::ElemWrite) -> Result<Self::Tail, fmt::Error> {
        let elem = tagu::build::elem("svg").with(attrs!(
            ("class", "poloto"),
            ("width", self.dim[0]),
            ("height", self.dim[1]),
            (
                "viewBox",
                format_move!("{} {} {} {}", 0, 0, self.viewbox[0], self.viewbox[1])
            ),
            ("xmlns", "http://www.w3.org/2000/svg"),
            self.attr
        ));

        elem.render_head(w)
    }
}

///
/// Default theme
///
#[derive(Copy, Clone)]
pub struct Theme<'a> {
    styles: &'a str,
}

impl Theme<'static> {
    pub const fn light() -> Theme<'static> {
        /// Default light theme

        const STYLE_CONFIG_LIGHT_DEFAULT: &str = ".poloto{
  stroke-linecap:round;
  stroke-linejoin:round;
  font-family:Roboto,sans-serif;
  font-size:16px;
}
.poloto_background{fill:AliceBlue;}
.poloto_scatter{stroke-width:7}
.poloto_line{stroke-width:2}
.poloto_text{fill: black;}
.poloto_name{font-size:24px;dominant-baseline:auto;text-anchor:middle;}
.poloto_where{dominant-baseline:middle;text-anchor:start}
.poloto_text.poloto_legend{font-size:20px;dominant-baseline:middle;text-anchor:start;}
.poloto_text.poloto_ticks.poloto_y{dominant-baseline:middle;text-anchor:end}
.poloto_text.poloto_ticks.poloto_x{dominant-baseline:auto;text-anchor:middle}
.poloto_imgs.poloto_ticks{stroke: black;stroke-width:3;fill:none;stroke-dasharray:none}
.poloto_grid{stroke:gray;stroke-width:0.5}

.poloto0.poloto_stroke{stroke:blue;}
.poloto1.poloto_stroke{stroke:red;}
.poloto2.poloto_stroke{stroke:green;}
.poloto3.poloto_stroke{stroke:gold;}
.poloto4.poloto_stroke{stroke:aqua;}
.poloto5.poloto_stroke{stroke:lime;}
.poloto6.poloto_stroke{stroke:orange;}
.poloto7.poloto_stroke{stroke:chocolate;}
.poloto0.poloto_fill{fill:blue;}
.poloto1.poloto_fill{fill:red;}
.poloto2.poloto_fill{fill:green;}
.poloto3.poloto_fill{fill:gold;}
.poloto4.poloto_fill{fill:aqua;}
.poloto5.poloto_fill{fill:lime;}
.poloto6.poloto_fill{fill:orange;}
.poloto7.poloto_fill{fill:chocolate;}";

        Theme {
            styles: STYLE_CONFIG_LIGHT_DEFAULT,
        }
    }
    pub const fn dark() -> Theme<'static> {
        const STYLE_CONFIG_DARK_DEFAULT: &str = ".poloto{
  stroke-linecap:round;
  stroke-linejoin:round;
  font-family:Roboto,sans-serif;
  font-size:16px;
}
.poloto_background{fill:#262626;}
.poloto_scatter{stroke-width:7}
.poloto_line{stroke-width:2}
.poloto_text{fill: white;}
.poloto_name{font-size:24px;dominant-baseline:auto;text-anchor:middle;}
.poloto_where{dominant-baseline:middle;text-anchor:start}
.poloto_text.poloto_legend{font-size:20px;dominant-baseline:middle;text-anchor:start;}
.poloto_text.poloto_ticks.poloto_y{dominant-baseline:middle;text-anchor:end}
.poloto_text.poloto_ticks.poloto_x{dominant-baseline:auto;text-anchor:middle}
.poloto_imgs.poloto_ticks{stroke: white;stroke-width:3;fill:none;stroke-dasharray:none}
.poloto_grid{stroke:gray;stroke-width:0.5}

.poloto0.poloto_stroke{stroke:blue;}
.poloto1.poloto_stroke{stroke:red;}
.poloto2.poloto_stroke{stroke:green;}
.poloto3.poloto_stroke{stroke:gold;}
.poloto4.poloto_stroke{stroke:aqua;}
.poloto5.poloto_stroke{stroke:lime;}
.poloto6.poloto_stroke{stroke:orange;}
.poloto7.poloto_stroke{stroke:chocolate;}
.poloto0.poloto_fill{fill:blue;}
.poloto1.poloto_fill{fill:red;}
.poloto2.poloto_fill{fill:green;}
.poloto3.poloto_fill{fill:gold;}
.poloto4.poloto_fill{fill:aqua;}
.poloto5.poloto_fill{fill:lime;}
.poloto6.poloto_fill{fill:orange;}
.poloto7.poloto_fill{fill:chocolate;}";
        Theme {
            styles: STYLE_CONFIG_DARK_DEFAULT,
        }
    }

    pub const fn get_str(&self) -> &'static str {
        self.styles
    }
}

impl<'a> Locked for Theme<'a> {}
impl<'a> Elem for Theme<'a> {
    type Tail = tagu::elem::ElementTail<&'static str>;
    fn render_head(self, w: elem::ElemWrite) -> Result<Self::Tail, fmt::Error> {
        let k = tagu::build::elem("style");
        let k = k.append(tagu::build::raw(self.styles));
        k.render_head(w)
    }
}

#[derive(Copy, Clone)]
pub struct FloatFmt {
    precision: usize,
}
impl FloatFmt {
    pub fn new(precision: usize) -> Self {
        FloatFmt { precision }
    }
    pub fn disp(&self, num: f64) -> impl Display {
        let precision = self.precision;
        util::disp_const(move |f| write!(f, "{:.*}", precision, num))
    }
}