rstk 0.3.0

A Rust binding for the Tk graphics toolkit. Tk is suitable for creating simple GUI programs or interactive graphical displays. This library supports a large portion of the Tk API, in a generally rust-like style.
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
//! Plotchart - common enums and methods for all charts.
//!

use std::fmt;

use crate::canvas;
use crate::font;
use crate::image;
use crate::widget;
use crate::wish;

/// Used to give either the number of series in a bar chart, or 
/// indicate they should be drawn in a stacked manner.
#[derive(Clone, Debug, PartialEq)]
pub enum BarSeries {
    Count(u64),
    Stacked,
}

impl fmt::Display for BarSeries {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            BarSeries::Count(n) => n.to_string(),
            BarSeries::Stacked => "stacked".to_string(),
        };
        write!(f, "{}", &value)
    }
}

/// Used to define type of whiskers to draw in a box plot.
#[derive(Clone, Debug, PartialEq)]
pub enum BoxWhiskers {
    Extremes,
    Iqr,
    None,
}

impl fmt::Display for BoxWhiskers {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            BoxWhiskers::Extremes => "extremes",
            BoxWhiskers::Iqr => "iqr",
            BoxWhiskers::None => "none",
        };
        write!(f, "{}", &value)
    }
}

/// Indicates whether a colour should become brighter or darker.
#[derive(Clone, Debug, PartialEq)]
pub enum Brightness {
    Bright,
    Dark,
}

impl fmt::Display for Brightness {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            Brightness::Bright => "bright",
            Brightness::Dark => "dark",
        };
        write!(f, "{}", &value)
    }
}

/// Type of line to use in drawing chart ticklines.
#[derive(Clone, Debug, PartialEq)]
pub enum ChartDash {
    Dots1,
    Dots2,
    Dots3,
    Dots4,
    Dots5,
    Lines,
}

impl fmt::Display for ChartDash {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            ChartDash::Dots1 => "dots1",
            ChartDash::Dots2 => "dots2",
            ChartDash::Dots3 => "dots3",
            ChartDash::Dots4 => "dots4",
            ChartDash::Dots5 => "dots5",
            ChartDash::Lines => "lines",
        };
        write!(f, "{}", &value)
    }
}

impl ChartDash {
    pub fn to_short_string(&self) -> String {
        let value = match self {
            ChartDash::Dots1 => ".",
            ChartDash::Dots2 => "..",
            ChartDash::Dots3 => "...",
            ChartDash::Dots4 => "....",
            ChartDash::Dots5 => ".....",
            ChartDash::Lines => "{}",
        };
        String::from(value)
    }
}

/// Specifies colour map scheme.
#[derive(Clone, Debug, PartialEq)]
pub enum ColourMap {
    Cool,
    Gray,
    Grey,
    Hot,
    Jet,
}

impl fmt::Display for ColourMap {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            ColourMap::Cool => "cool",
            ColourMap::Gray => "gray",
            ColourMap::Grey => "grey",
            ColourMap::Hot => "hot",
            ColourMap::Jet => "jet",
        };
        write!(f, "{}", &value)
    }
}

/// Specifies interpretation of coordinates.
#[derive(Clone, Debug, PartialEq)]
pub enum CoordinatesType {
    /// (x, y) coordinate
    Cartesian,
    /// Angles, with 0 to North, 90 to East
    Nautical,
    /// Angles, with 0 on x-axis, 90 on y-axis
    Polar,
}

impl fmt::Display for CoordinatesType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            CoordinatesType::Cartesian => "cartesian",
            CoordinatesType::Nautical => "nautical",
            CoordinatesType::Polar => "polar",
        };
        write!(f, "{}", &value)
    }
}

/// Defines direction of text against given point.
#[derive(Clone, Debug, PartialEq)]
pub enum Direction {
    North,
    NorthEast,
    East,
    SouthEast,
    South,
    SouthWest,
    West,
    NorthWest,
}

impl fmt::Display for Direction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            Direction::North => "north",
            Direction::NorthEast => "north-east",
            Direction::East => "east",
            Direction::SouthEast => "south-east",
            Direction::South => "south",
            Direction::SouthWest => "south-west",
            Direction::West => "west",
            Direction::NorthWest => "north-west",
        };
        write!(f, "{}", &value)
    }
}

impl Direction {
    pub(super) fn to_short_string(&self) -> String {
        let value = match self {
            Direction::North => "n",
            Direction::NorthEast => "ne",
            Direction::East => "e",
            Direction::SouthEast => "se",
            Direction::South => "s",
            Direction::SouthWest => "sw",
            Direction::West => "w",
            Direction::NorthWest => "nw",
        };
        String::from(value)
    }
}

/// Choice of displaying line/symbol or both when plotting a data series.
#[derive(Clone, Debug, PartialEq)]
pub enum DrawingMode {
    Both,
    Line,
    Symbol,
}

impl fmt::Display for DrawingMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            DrawingMode::Both => "both",
            DrawingMode::Line => "line",
            DrawingMode::Symbol => "symbol",
        };
        write!(f, "{}", &value)
    }
}

/// Specifies part of graph to fill.
#[derive(Clone, Debug, PartialEq)]
pub enum FillArea {
    AboveLine,
    BelowLine,
    None,
}

impl fmt::Display for FillArea {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            FillArea::AboveLine => "up",
            FillArea::BelowLine => "down",
            FillArea::None => "no",
        };
        write!(f, "{}", &value)
    }
}

/// Direction of colour gradient.
#[derive(Clone, Debug, PartialEq)]
pub enum GradientDirection {
    TopDown,
    BottomUp,
    LeftRight,
    RightLeft,
}

impl fmt::Display for GradientDirection {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            GradientDirection::TopDown => "top-down",
            GradientDirection::BottomUp => "bottom-up",
            GradientDirection::LeftRight => "left-right",
            GradientDirection::RightLeft => "right-left",
        };
        write!(f, "{}", &value)
    }
}

/// Defines display style of a histogram.
pub enum HistogramStyle {
    Filled,
    Plateau,
    Spike,
    Stair,
}

impl fmt::Display for HistogramStyle {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            HistogramStyle::Filled => "filled",
            HistogramStyle::Plateau => "plateau",
            HistogramStyle::Spike => "spike",
            HistogramStyle::Stair => "stair",
        };
        write!(f, "{}", &value)
    }
}

/// Defines type of legend.
#[derive(Clone, Debug, PartialEq)]
pub enum LegendType {
    Line,
    Rectangle,
}

impl fmt::Display for LegendType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            LegendType::Line => "line",
            LegendType::Rectangle => "rectangle",
        };
        write!(f, "{}", &value)
    }
}

/// Defines location of text against given point for label-dot.
#[derive(Clone, Debug, PartialEq)]
pub enum Location {
    North,
    East,
    South,
    West,
}

impl fmt::Display for Location {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            Location::North => "n",
            Location::East => "e",
            Location::South => "s",
            Location::West => "w",
        };
        write!(f, "{}", &value)
    }
}

/// Used to give direction of adding charts in [plot_pack](widget::plot_pack).
#[derive(Clone, Debug, PartialEq)]
pub enum PlotDirection {
    Bottom,
    Left,
    Right,
    Top,
}

impl fmt::Display for PlotDirection {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            PlotDirection::Bottom => "bottom",
            PlotDirection::Left => "left",
            PlotDirection::Right => "right",
            PlotDirection::Top => "top",
        };
        write!(f, "{}", &value)
    }
}

/// Defines position of legend with respect to plot.
#[derive(Clone, Debug, PartialEq)]
pub enum Position {
    TopLeft,
    TopRight,
    BottomLeft,
    BottomRight,
}

impl fmt::Display for Position {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            Position::TopLeft => "top-left",
            Position::TopRight => "top-right",
            Position::BottomLeft => "bottom-left",
            Position::BottomRight => "bottom-right",
        };
        write!(f, "{}", &value)
    }
}

/// Style of plot on a radial chart
#[derive(Clone, Debug, PartialEq)]
pub enum RadialStyle {
    Cumulative,
    Filled,
    Lines,
}

impl fmt::Display for RadialStyle {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            RadialStyle::Cumulative => "cumulative",
            RadialStyle::Filled => "filled",
            RadialStyle::Lines => "lines",
        };
        write!(f, "{}", &value)
    }
}

/// Used to give either the step size on the axes of an isometric plot, or
/// indicate there should be no axes drawn.
#[derive(Clone, Debug, PartialEq)]
pub enum StepSize {
    NoAxes,
    Value(u64),
}

impl fmt::Display for StepSize {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            StepSize::NoAxes => "noaxes".to_string(),
            StepSize::Value(n) => n.to_string(),
        };
        write!(f, "{}", &value)
    }
}

/// Type of symbol used when plotting data series.
#[derive(Clone, Debug, PartialEq)]
pub enum Symbol {
    Circle,
    Cross,
    /// Filled circle
    Dot,
    /// Triangle pointing down
    Down,
    DownFilled,
    Plus,
    /// Triangle pointing up
    Up,
    UpFilled,
}

impl fmt::Display for Symbol {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let value = match self {
            Symbol::Circle => "circle",
            Symbol::Cross => "cross",
            Symbol::Dot => "dot",
            Symbol::Down => "down",
            Symbol::DownFilled => "downfilled",
            Symbol::Plus => "plus",
            Symbol::Up => "up",
            Symbol::UpFilled => "upfilled",
        };
        write!(f, "{}", &value)
    }
}

/// Methods common to (_almost_) all chart types.
pub trait TkPlotchart {
    /// Returns the widget's id reference - used within tk
    fn id(&self) -> &str;

    /// Sets the background colour for the axes.
    fn background_axes_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} background axes {}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets a background gradient.
    fn background_gradient_colour(&self, colour: &str, 
                                  direction: GradientDirection, 
                                  brightness: Brightness) {
        let msg = format!("global {}; ${} background gradient {} {} {}",
                          self.id(), self.id(), colour, direction, brightness);
        wish::tell_wish(&msg);
    }

    /// Sets a background image.
    fn background_image(&self, image: &image::TkImage) {
        let msg = format!("global {}; ${} background image {}",
                          self.id(), self.id(), &image.id);
        wish::tell_wish(&msg);
    }

    /// Sets the background colour for the plot area.
    fn background_plot_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} background plot {}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Creates balloon text (does not work for 3D plots). 
    fn balloon(&self, (x, y): (f64, f64), text: &str, direction: Direction) {
        let msg = format!("global {}; ${} balloon {} {} {{{}}} {}",
                          self.id(), self.id(), 
                          x, y, text, direction);
        wish::tell_wish(&msg);
    }

    /// Sets arrow-length, in pixels, for balloon text.
    fn balloon_arrow_size(&self, value: u64) {
        let msg = format!("global {}; ${} balloonconfig -arrowsize {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets background colour of balloon text.
    fn balloon_background_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} balloonconfig -background {{{}}}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets font for balloon text.
    fn balloon_font(&self, font: &font::TkFont) {
        let msg = format!("global {}; ${} balloonconfig -font {{{}}}",
                          self.id(), self.id(), font);
        wish::tell_wish(&msg);
    }

    /// Sets justification for balloon text.
    fn balloon_justify(&self, value: widget::Justify) {
        let msg = format!("global {}; ${} balloonconfig -justify {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets outline colour of balloon text.
    fn balloon_outline_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} balloonconfig -outline {{{}}}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets width of margin, in pixels, around balloon text.
    fn balloon_margin(&self, value: u64) {
        let msg = format!("global {}; ${} balloonconfig -margin {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets margin size, in pixels, around balloon text.
    fn balloon_rim_width(&self, value: u64) {
        let msg = format!("global {}; ${} balloonconfig -rimwidth {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets colour of balloon text.
    fn balloon_text_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} balloonconfig -textcolour {{{}}}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Draws a horizontal light-grey band.
    fn draw_x_band(&self, y_min: f64, y_max: f64) {
        let msg = format!("global {}; ${} xband {} {}",
                          self.id(), self.id(), y_min, y_max);
        wish::tell_wish(&msg);
    }

    /// Draws a vertical light-grey band.
    fn draw_y_band(&self, y_min: f64, y_max: f64) {
        let msg = format!("global {}; ${} yband {} {}",
                          self.id(), self.id(), y_min, y_max);
        wish::tell_wish(&msg);
    }

    /// Erases this plot and all associated resources.
    fn erase(&self) {
        let msg = format!("::Plotchart::eraseplot ${}", self.id());
        wish::tell_wish(&msg);
    }

    /// Adds a line to legend for given data series.
    fn legend(&self, series: &str, text: &str) {
        let msg = format!("global {}; ${} legend {} {{{}}}",
                          self.id(), self.id(), 
                          series, text);
        wish::tell_wish(&msg);
    }

    /// Sets background colour for legend.
    fn legend_background(&self, colour: &str) {
        let msg = format!("global {}; ${} legendconfig -background {}",
                              self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets border colour for legend.
    fn legend_border(&self, colour: &str) {
        let msg = format!("global {}; ${} legendconfig -border {}",
                              self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets canvas on which to draw legend.
    fn legend_canvas(&self, canvas: &canvas::TkCanvas) {
        let msg = format!("global {}; ${} legendconfig -canvas {}",
                              self.id(), self.id(), &canvas.id);
        wish::tell_wish(&msg);
    }

    /// Sets font with which to draw legend.
    fn legend_font(&self, font: &font::TkFont) {
        let msg = format!("global {}; ${} legendconfig -font {{{}}}",
                              self.id(), self.id(), font);
        wish::tell_wish(&msg);
    }

    /// Position of legend on display.
    fn legend_position(&self, value: Position) {
        let msg = format!("global {}; ${} legendconfig -position {}",
                              self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Removes legend entry for given series.
    fn legend_remove(&self, series: &str) {
        let msg = format!("global {}; ${} removefromlegend {{{}}}",
                          self.id(), self.id(), series);
        wish::tell_wish(&msg);
    }

    /// Sets spacing between rows in legend.
    fn legend_spacing(&self, value: u64) {
        let msg = format!("global {}; ${} legendconfig -spacing {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Type of legend to display - series identified by line or colour rectangle.
    fn legend_type(&mut self, value: LegendType) {
        let msg = format!("global {}; ${} legendconfig -legendtype {}",
                              self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Starts definition of plain text (does not work for 3D plots). 
    fn plaintext(&self, (x, y): (f64, f64), text: &str, direction: Direction) {
        let msg = format!("global {}; ${} plaintext {} {} {{{}}} {}",
                          self.id(), self.id(), 
                          x, y, text, direction);
        wish::tell_wish(&msg);
    }

    /// Sets colour of plain text.
    fn plaintext_colour(&self, colour: &str) {
        let msg = format!("global {}; ${} plaintextconfig -textcolour {{{}}}",
                          self.id(), self.id(), colour);
        wish::tell_wish(&msg);
    }

    /// Sets font for plain text.
    fn plaintext_font(&self, font: &font::TkFont) {
        let msg = format!("global {}; ${} plaintextconfig -font {{{}}}",
                          self.id(), self.id(), font);
        wish::tell_wish(&msg);
    }

    /// Sets justification for plain text.
    fn plaintext_justify(&self, value: widget::Justify) {
        let msg = format!("global {}; ${} plaintextconfig -justify {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Saves chart to a file in postscript format.
    fn save(&self, filename: &str) {
        let msg = format!("global {}; ${} saveplot {{{}}} -plotregion window",
                          self.id(), self.id(), filename);
        wish::tell_wish(&msg);
    }

    /// Sets subtitle of chart.
    fn subtitle(&self, text: &str) {
        let msg = format!(
            "global {}; ${} subtitle {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Sets title of chart.
    fn title(&self, text: &str, placement: widget::Justify) {
        let msg = format!(
            "global {}; ${} title {{{}}} {}",
            self.id(),
            self.id(),
            text,
            placement
            );
        wish::tell_wish(&msg);
    }

    /// Sets subtitle of the (vertical) y-axis, and displays vertically 
    /// along axis.
    fn v_subtitle(&self, text: &str) {
        let msg = format!(
            "global {}; ${} vsubtext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Sets title of the (vertical) y-axis, and displays vertically 
    /// along axis.
    fn v_title(&self, text: &str) {
        let msg = format!(
            "global {}; ${} vtext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Sets tcl format string for numbers, see Tk
    /// [manual](https://www.tcl.tk/man/tcl8.5/TclCmd/format.htm)
    fn x_format(&self, format: &str) {
        let msg = format!("global {}; ${} xconfig -format {{{}}}",
                          self.id(), self.id(), format);
        wish::tell_wish(&msg);
    }

    /// Sets space in pixels between label and tickmark.
    fn x_label_offset(&self, value: f64) {
        let msg = format!("global {}; ${} xconfig -labeloffset {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets number of minor tick marks.
    fn x_minor_ticks(&self, value: u64) {
        let msg = format!("global {}; ${} xconfig -minorticks {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Changes x-axis definition to (min, max, step).
    fn x_scale(&self, (min, max, step): (f64, f64, f64)) {
        let msg = format!("global {}; ${} xconfig -scale {{{} {} {} }}",
                          self.id(), self.id(), min, max, step);
        wish::tell_wish(&msg);
    }

    /// Sets subtitle of the (horizontal) x-axis.
    fn x_subtitle(&self, text: &str) {
        let msg = format!(
            "global {}; ${} xsubtext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Turns on display of vertical ticklines at each tick location.
    fn x_tick_lines(&self, colour: &str, dash: ChartDash) {
        let msg = format!("global {}; ${} xticklines {} {}",
                          self.id(), self.id(), colour, dash);
        wish::tell_wish(&msg);
    }

    /// Sets length in pixels of tick lines.
    fn x_tick_length(&self, value: u64) {
        let msg = format!("global {}; ${} xconfig -ticklength {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets title of the (horizontal) x-axis.
    fn x_title(&self, text: &str) {
        let msg = format!(
            "global {}; ${} xtext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Sets tcl format string for numbers, see Tk
    /// [manual](https://www.tcl.tk/man/tcl8.5/TclCmd/format.htm)
    fn y_format(&self, format: &str) {
        let msg = format!("global {}; ${} yconfig -format {{{}}}",
                          self.id(), self.id(), format);
        wish::tell_wish(&msg);
    }

    /// Sets space in pixels between label and tickmark.
    fn y_label_offset(&self, value: f64) {
        let msg = format!("global {}; ${} yconfig -labeloffset {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets number of minor tick marks.
    fn y_minor_ticks(&self, value: u64) {
        let msg = format!("global {}; ${} yconfig -minorticks {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Changes y-axis definition to (min, max, step).
    fn y_scale(&self, (min, max, step): (f64, f64, f64)) {
        let msg = format!("global {}; ${} yconfig -scale {{{} {} {} }}",
                          self.id(), self.id(), min, max, step);
        wish::tell_wish(&msg);
    }

    /// Sets subtitle of the (vertical) y-axis.
    fn y_subtitle(&self, text: &str) {
        let msg = format!(
            "global {}; ${} ysubtext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

    /// Turns on display of vertical ticklines at each tick location.
    fn y_tick_lines(&self, colour: &str, dash: ChartDash) {
        let msg = format!("global {}; ${} yticklines {} {}",
                          self.id(), self.id(), colour, dash);
        wish::tell_wish(&msg);
    }

    /// Sets length in pixels of tick lines.
    fn y_tick_length(&self, value: u64) {
        let msg = format!("global {}; ${} yconfig -ticklength {}",
                          self.id(), self.id(), value);
        wish::tell_wish(&msg);
    }

    /// Sets title of the (vertical) y-axis.
    fn y_title(&self, text: &str) {
        let msg = format!(
            "global {}; ${} ytext {{{}}}",
            self.id(),
            self.id(),
            text,
            );
        wish::tell_wish(&msg);
    }

}

/// Methods for configuring the way that data series are displayed 
/// on some kinds of charts.
pub trait TkChartSeries: TkPlotchart {
    /// Sets colour for displaying data series
    fn series_colour(&self, series: &str, colour: &str) {
        let msg = format!("global {}; ${} dataconfig {} -colour {}",
                          self.id(), self.id(), series, colour);
        wish::tell_wish(&msg);
    }

    /// Sets drawing mode for displaying data series 
    /// (called "type" in tklib's plotchart documentation).
    fn series_drawing_mode(&self, series: &str, mode: DrawingMode) {
        let msg = format!("global {}; ${} dataconfig {} -type {}",
                          self.id(), self.id(), series, mode);
        wish::tell_wish(&msg);
    }

    /// Used to select whether to fill the area above or below the line of 
    /// data series.
    fn series_fill_area(&self, series: &str, area: FillArea) {
        let msg = format!("global {}; ${} dataconfig {} -filled {}",
                          self.id(), self.id(), series, area);
        wish::tell_wish(&msg);
    }

    /// Sets colour to use when drawing filled area.
    fn series_fill_colour(&self, series: &str, colour: &str) {
        let msg = format!("global {}; ${} dataconfig {} -fillcolour {}",
                          self.id(), self.id(), series, colour);
        wish::tell_wish(&msg);
    }

    /// Sets width of line for displaying data series 
    fn series_line_width(&self, series: &str, width: u64) {
        let msg = format!("global {}; ${} dataconfig {} -width {}",
                          self.id(), self.id(), series, width);
        wish::tell_wish(&msg);
    }

    /// Sets symbol type and radius for displaying data series 
    fn series_symbol(&self, series: &str, symbol: Symbol, radius: u64) {
        let msg = format!("global {}; ${} dataconfig {} -symbol {} -radius {}",
                          self.id(), self.id(), series, symbol, radius);
        wish::tell_wish(&msg);
    }

}

/// Configuration options for dots, used in xy_plots and polar plots.
pub trait TkChartDots: TkPlotchart {
    /// Sets colour of dots in given data series.
    fn dot_colour(&self, series: &str, colour: &str) {
        let msg = format!("global {}; ${} dotconfig {} -colour {}",
                          self.id(), self.id(), series, colour);
        wish::tell_wish(&msg);
    }

    /// Defines class limits and colours, e.g. [(0.0, "green"), (2.0, "red"), ...]
    fn dot_classes(&self, series: &str, values: &[(f64, &str)]) {
        let mut class_str = String::new();
        for (value, colour) in values {
            class_str.push_str(&format!("{} {} ", value, colour));
        }

        let msg = format!("global {}; ${} dotconfig {} -classes {{{}}}",
                          self.id(), self.id(), series, class_str);
        wish::tell_wish(&msg);
    }

    /// Sets a 3D effect for dots in given data series.
    fn dot_effect_3d(&self, series: &str, value: bool) {
        let msg = format!("global {}; ${} dotconfig {} -3deffect {}",
                          self.id(), self.id(), series, 
                          if value { "1" } else { "0" });
        wish::tell_wish(&msg);
    }

    /// Sets whether an outline should be displayed for dots in given 
    /// data series.
    fn dot_outline(&self, series: &str, value: bool) {
        let msg = format!("global {}; ${} dotconfig {} -outline {}",
                          self.id(), self.id(), series, 
                          if value { "1" } else { "0" });
        wish::tell_wish(&msg);
    }

    /// Sets radius for dots in given data series.
    fn dot_radius(&self, series: &str, value: f64) {
        let msg = format!("global {}; ${} dotconfig {} -radius {}",
                          self.id(), self.id(), series, value);
        wish::tell_wish(&msg);
    }

    /// Sets scale factor of radius to pixels for dots in given data series.
    fn dot_scale(&self, series: &str, value: f64) {
        let msg = format!("global {}; ${} dotconfig {} -scale {}",
                          self.id(), self.id(), series, value);
        wish::tell_wish(&msg);
    }

    /// Sets whether dots in given data series should all have the 
    /// same size (false) or be scaled by value (true).
    fn dot_scale_by_value(&self, series: &str, value: bool) {
        let msg = format!("global {}; ${} dotconfig {} -scalebyvalue {}",
                          self.id(), self.id(), series, 
                          if value { "1" } else { "0" });
        wish::tell_wish(&msg);
    }

}