@@ -167,13 +167,14 @@ type ChartKind string
167
167
168
168
// available chart kinds
169
169
const (
170
- ChartKindUnknown ChartKind = ""
171
- ChartKindSingleStat ChartKind = "single_stat"
170
+ ChartKindUnknown ChartKind = ""
171
+ ChartKindSingleStat ChartKind = "single_stat"
172
+ ChartKindSingleStatPlusLine ChartKind = "single_stat_plus_line"
172
173
)
173
174
174
175
func (c ChartKind ) ok () bool {
175
176
switch c {
176
- case ChartKindSingleStat :
177
+ case ChartKindSingleStat , ChartKindSingleStatPlusLine :
177
178
return true
178
179
default :
179
180
return false
@@ -457,8 +458,10 @@ type chart struct {
457
458
DecimalPlaces int
458
459
EnforceDecimals bool
459
460
Shade bool
460
- Colors []* color
461
- Queries []query
461
+ Legend legend
462
+ Colors colors
463
+ Queries queries
464
+ Axes axes
462
465
463
466
XCol , YCol string
464
467
XPos , YPos int
@@ -478,8 +481,27 @@ func (c chart) properties() influxdb.ViewProperties {
478
481
},
479
482
Note : c .Note ,
480
483
ShowNoteWhenEmpty : c .NoteOnEmpty ,
481
- Queries : queries (c .Queries ).influxDashQueries (),
482
- ViewColors : colors (c .Colors ).influxViewColors (),
484
+ Queries : c .Queries .influxDashQueries (),
485
+ ViewColors : c .Colors .influxViewColors (),
486
+ }
487
+ case ChartKindSingleStatPlusLine :
488
+ return influxdb.LinePlusSingleStatProperties {
489
+ Type : "line-plus-single-stat" ,
490
+ Prefix : c .Prefix ,
491
+ Suffix : c .Suffix ,
492
+ DecimalPlaces : influxdb.DecimalPlaces {
493
+ IsEnforced : c .EnforceDecimals ,
494
+ Digits : int32 (c .DecimalPlaces ),
495
+ },
496
+ Note : c .Note ,
497
+ ShowNoteWhenEmpty : c .NoteOnEmpty ,
498
+ XColumn : c .XCol ,
499
+ YColumn : c .YCol ,
500
+ ShadeBelow : c .Shade ,
501
+ Legend : c .Legend .influxLegend (),
502
+ Queries : c .Queries .influxDashQueries (),
503
+ ViewColors : c .Colors .influxViewColors (),
504
+ Axes : c .Axes .influxAxes (),
483
505
}
484
506
default :
485
507
return nil
@@ -491,8 +513,8 @@ func (c chart) validProperties() []failure {
491
513
492
514
validatorFns := []func () []failure {
493
515
c .validBaseProps ,
494
- queries ( c .Queries ) .valid ,
495
- colors ( c .Colors ) .valid ,
516
+ c .Queries .valid ,
517
+ c .Colors .valid ,
496
518
}
497
519
for _ , validatorFn := range validatorFns {
498
520
fails = append (fails , validatorFn ()... )
@@ -501,14 +523,10 @@ func (c chart) validProperties() []failure {
501
523
// chart kind specific validations
502
524
switch c .Kind {
503
525
case ChartKindSingleStat :
504
- for i , clr := range c .Colors {
505
- if clr .Type != colorTypeText {
506
- fails = append (fails , failure {
507
- Field : fmt .Sprintf ("colors[%d].type" , i ),
508
- Msg : "single stat charts must have color type of \" text\" " ,
509
- })
510
- }
511
- }
526
+ fails = append (fails , c .Colors .hasTypes (colorTypeText )... )
527
+ case ChartKindSingleStatPlusLine :
528
+ fails = append (fails , c .Colors .hasTypes (colorTypeText , colorTypeScale )... )
529
+ fails = append (fails , c .Axes .hasAxes ("x" , "y" )... )
512
530
}
513
531
514
532
return fails
@@ -533,7 +551,8 @@ func (c chart) validBaseProps() []failure {
533
551
}
534
552
535
553
const (
536
- colorTypeText = "text"
554
+ colorTypeText = "text"
555
+ colorTypeScale = "scale"
537
556
)
538
557
539
558
type color struct {
@@ -565,6 +584,25 @@ func (c colors) influxViewColors() []influxdb.ViewColor {
565
584
return iColors
566
585
}
567
586
587
+ func (c colors ) hasTypes (types ... string ) []failure {
588
+ tMap := make (map [string ]bool )
589
+ for _ , cc := range c {
590
+ tMap [cc .Type ] = true
591
+ }
592
+
593
+ var failures []failure
594
+ for _ , t := range types {
595
+ if ! tMap [t ] {
596
+ failures = append (failures , failure {
597
+ Field : "colors" ,
598
+ Msg : fmt .Sprintf ("type not found: %q" , t ),
599
+ })
600
+ }
601
+ }
602
+
603
+ return failures
604
+ }
605
+
568
606
func (c colors ) valid () []failure {
569
607
var fails []failure
570
608
if len (c ) == 0 {
@@ -626,3 +664,60 @@ func (q queries) valid() []failure {
626
664
627
665
return fails
628
666
}
667
+
668
+ type axis struct {
669
+ Base string
670
+ Label string
671
+ Name string
672
+ Prefix string
673
+ Scale string
674
+ Suffix string
675
+ }
676
+
677
+ type axes []axis
678
+
679
+ func (a axes ) influxAxes () map [string ]influxdb.Axis {
680
+ m := make (map [string ]influxdb.Axis )
681
+ for _ , ax := range a {
682
+ m [ax .Name ] = influxdb.Axis {
683
+ Bounds : []string {},
684
+ Label : ax .Label ,
685
+ Prefix : ax .Prefix ,
686
+ Suffix : ax .Suffix ,
687
+ Base : ax .Base ,
688
+ Scale : ax .Scale ,
689
+ }
690
+ }
691
+ return m
692
+ }
693
+
694
+ func (a axes ) hasAxes (expectedAxes ... string ) []failure {
695
+ mAxes := make (map [string ]bool )
696
+ for _ , ax := range a {
697
+ mAxes [ax .Name ] = true
698
+ }
699
+
700
+ var failures []failure
701
+ for _ , expected := range expectedAxes {
702
+ if ! mAxes [expected ] {
703
+ failures = append (failures , failure {
704
+ Field : "axes" ,
705
+ Msg : fmt .Sprintf ("axis not found: %q" , expected ),
706
+ })
707
+ }
708
+ }
709
+
710
+ return failures
711
+ }
712
+
713
+ type legend struct {
714
+ Orientation string
715
+ Type string
716
+ }
717
+
718
+ func (l legend ) influxLegend () influxdb.Legend {
719
+ return influxdb.Legend {
720
+ Type : l .Type ,
721
+ Orientation : l .Orientation ,
722
+ }
723
+ }
0 commit comments