1
1
import { getGroupId , getSpecId , SpecId } from '../utils/ids' ;
2
2
import { ScaleType } from '../utils/scales/scales' ;
3
- import { computeLegend } from './legend' ;
3
+ import { computeLegend , getSeriesColorLabel } from './legend' ;
4
4
import { DataSeriesColorsValues } from './series' ;
5
5
import { BasicSeriesSpec } from './specs' ;
6
6
@@ -22,6 +22,7 @@ const colorValues2b = {
22
22
} ;
23
23
const spec1 : BasicSeriesSpec = {
24
24
id : getSpecId ( 'spec1' ) ,
25
+ name : 'Spec 1 title' ,
25
26
groupId : getGroupId ( 'group' ) ,
26
27
seriesType : 'line' ,
27
28
yScaleType : ScaleType . Log ,
@@ -62,7 +63,7 @@ describe('Legends', () => {
62
63
const expected = [
63
64
{
64
65
color : 'red' ,
65
- label : 'spec1 ' ,
66
+ label : 'Spec 1 title ' ,
66
67
value : { colorValues : [ ] , specId : 'spec1' } ,
67
68
isVisible : true ,
68
69
key : 'colorSeries1a' ,
@@ -77,7 +78,7 @@ describe('Legends', () => {
77
78
const expected = [
78
79
{
79
80
color : 'red' ,
80
- label : 'spec1 ' ,
81
+ label : 'Spec 1 title ' ,
81
82
value : { colorValues : [ ] , specId : 'spec1' } ,
82
83
isVisible : true ,
83
84
key : 'colorSeries1a' ,
@@ -99,7 +100,7 @@ describe('Legends', () => {
99
100
const expected = [
100
101
{
101
102
color : 'red' ,
102
- label : 'spec1 ' ,
103
+ label : 'Spec 1 title ' ,
103
104
value : { colorValues : [ ] , specId : 'spec1' } ,
104
105
isVisible : true ,
105
106
key : 'colorSeries1a' ,
@@ -126,7 +127,7 @@ describe('Legends', () => {
126
127
const expected = [
127
128
{
128
129
color : 'violet' ,
129
- label : 'spec1 ' ,
130
+ label : 'Spec 1 title ' ,
130
131
value : { colorValues : [ ] , specId : 'spec1' } ,
131
132
isVisible : true ,
132
133
key : 'colorSeries1a' ,
@@ -163,4 +164,27 @@ describe('Legends', () => {
163
164
const visibility = [ ...legend . values ( ) ] . map ( ( item ) => item . isVisible ) ;
164
165
expect ( visibility ) . toEqual ( [ false , false , true , true ] ) ;
165
166
} ) ;
167
+ it ( 'returns the right series label for a color series' , ( ) => {
168
+ let label = getSeriesColorLabel ( [ ] , true ) ;
169
+ expect ( label ) . toBeUndefined ( ) ;
170
+ label = getSeriesColorLabel ( [ ] , true , spec1 ) ;
171
+ expect ( label ) . toBe ( 'Spec 1 title' ) ;
172
+ label = getSeriesColorLabel ( [ ] , true , spec2 ) ;
173
+ expect ( label ) . toBe ( 'spec2' ) ;
174
+ label = getSeriesColorLabel ( [ 'a' , 'b' ] , true , spec1 ) ;
175
+ expect ( label ) . toBe ( 'Spec 1 title' ) ;
176
+ label = getSeriesColorLabel ( [ 'a' , 'b' ] , true , spec2 ) ;
177
+ expect ( label ) . toBe ( 'spec2' ) ;
178
+
179
+ label = getSeriesColorLabel ( [ ] , false ) ;
180
+ expect ( label ) . toBeUndefined ( ) ;
181
+ label = getSeriesColorLabel ( [ ] , false , spec1 ) ;
182
+ expect ( label ) . toBe ( 'Spec 1 title' ) ;
183
+ label = getSeriesColorLabel ( [ ] , false , spec2 ) ;
184
+ expect ( label ) . toBe ( 'spec2' ) ;
185
+ label = getSeriesColorLabel ( [ 'a' , 'b' ] , false , spec1 ) ;
186
+ expect ( label ) . toBe ( 'a - b' ) ;
187
+ label = getSeriesColorLabel ( [ 'a' , 'b' ] , false , spec2 ) ;
188
+ expect ( label ) . toBe ( 'a - b' ) ;
189
+ } ) ;
166
190
} ) ;
0 commit comments