11import { getGroupId , getSpecId , SpecId } from '../utils/ids' ;
22import { ScaleType } from '../utils/scales/scales' ;
3- import { computeLegend } from './legend' ;
3+ import { computeLegend , getSeriesColorLabel } from './legend' ;
44import { DataSeriesColorsValues } from './series' ;
55import { BasicSeriesSpec } from './specs' ;
66
@@ -22,6 +22,7 @@ const colorValues2b = {
2222} ;
2323const spec1 : BasicSeriesSpec = {
2424 id : getSpecId ( 'spec1' ) ,
25+ name : 'Spec 1 title' ,
2526 groupId : getGroupId ( 'group' ) ,
2627 seriesType : 'line' ,
2728 yScaleType : ScaleType . Log ,
@@ -62,7 +63,7 @@ describe('Legends', () => {
6263 const expected = [
6364 {
6465 color : 'red' ,
65- label : 'spec1 ' ,
66+ label : 'Spec 1 title ' ,
6667 value : { colorValues : [ ] , specId : 'spec1' } ,
6768 isVisible : true ,
6869 key : 'colorSeries1a' ,
@@ -77,7 +78,7 @@ describe('Legends', () => {
7778 const expected = [
7879 {
7980 color : 'red' ,
80- label : 'spec1 ' ,
81+ label : 'Spec 1 title ' ,
8182 value : { colorValues : [ ] , specId : 'spec1' } ,
8283 isVisible : true ,
8384 key : 'colorSeries1a' ,
@@ -99,7 +100,7 @@ describe('Legends', () => {
99100 const expected = [
100101 {
101102 color : 'red' ,
102- label : 'spec1 ' ,
103+ label : 'Spec 1 title ' ,
103104 value : { colorValues : [ ] , specId : 'spec1' } ,
104105 isVisible : true ,
105106 key : 'colorSeries1a' ,
@@ -126,7 +127,7 @@ describe('Legends', () => {
126127 const expected = [
127128 {
128129 color : 'violet' ,
129- label : 'spec1 ' ,
130+ label : 'Spec 1 title ' ,
130131 value : { colorValues : [ ] , specId : 'spec1' } ,
131132 isVisible : true ,
132133 key : 'colorSeries1a' ,
@@ -163,4 +164,27 @@ describe('Legends', () => {
163164 const visibility = [ ...legend . values ( ) ] . map ( ( item ) => item . isVisible ) ;
164165 expect ( visibility ) . toEqual ( [ false , false , true , true ] ) ;
165166 } ) ;
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+ } ) ;
166190} ) ;
0 commit comments