1- import { getGroupId , getSpecId , SpecId } from '../utils/ids' ;
1+ import { AxisId , getAxisId , getGroupId , getSpecId , SpecId } from '../utils/ids' ;
22import { ScaleType } from '../utils/scales/scales' ;
33import { computeLegend , getSeriesColorLabel } from './legend' ;
44import { DataSeriesColorsValues } from './series' ;
5- import { BasicSeriesSpec } from './specs' ;
5+ import { AxisSpec , BasicSeriesSpec , Position } from './specs' ;
66
77const colorValues1a = {
88 specId : getSpecId ( 'spec1' ) ,
@@ -46,6 +46,22 @@ const spec2: BasicSeriesSpec = {
4646 hideInLegend : false ,
4747} ;
4848
49+ const axesSpecs = new Map < AxisId , AxisSpec > ( ) ;
50+ const axisSpec : AxisSpec = {
51+ id : getAxisId ( 'axis1' ) ,
52+ groupId : getGroupId ( 'group1' ) ,
53+ hide : false ,
54+ showOverlappingTicks : false ,
55+ showOverlappingLabels : false ,
56+ position : Position . Left ,
57+ tickSize : 10 ,
58+ tickPadding : 10 ,
59+ tickFormat : ( value : any ) => {
60+ return `${ value } ` ;
61+ } ,
62+ } ;
63+ axesSpecs . set ( axisSpec . id , axisSpec ) ;
64+
4965describe ( 'Legends' , ( ) => {
5066 const seriesColor = new Map < string , DataSeriesColorsValues > ( ) ;
5167 const seriesColorMap = new Map < string , string > ( ) ;
@@ -61,7 +77,7 @@ describe('Legends', () => {
6177 } ) ;
6278 it ( 'compute legend for a single series' , ( ) => {
6379 seriesColor . set ( 'colorSeries1a' , colorValues1a ) ;
64- const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' ) ;
80+ const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' , axesSpecs ) ;
6581 const expected = [
6682 {
6783 color : 'red' ,
@@ -70,14 +86,15 @@ describe('Legends', () => {
7086 isSeriesVisible : true ,
7187 isLegendItemVisible : true ,
7288 key : 'colorSeries1a' ,
89+ displayValue : { } ,
7390 } ,
7491 ] ;
7592 expect ( Array . from ( legend . values ( ) ) ) . toEqual ( expected ) ;
7693 } ) ;
7794 it ( 'compute legend for a single spec but with multiple series' , ( ) => {
7895 seriesColor . set ( 'colorSeries1a' , colorValues1a ) ;
7996 seriesColor . set ( 'colorSeries1b' , colorValues1b ) ;
80- const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' ) ;
97+ const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' , axesSpecs ) ;
8198 const expected = [
8299 {
83100 color : 'red' ,
@@ -86,6 +103,7 @@ describe('Legends', () => {
86103 isSeriesVisible : true ,
87104 isLegendItemVisible : true ,
88105 key : 'colorSeries1a' ,
106+ displayValue : { } ,
89107 } ,
90108 {
91109 color : 'blue' ,
@@ -94,14 +112,15 @@ describe('Legends', () => {
94112 isSeriesVisible : true ,
95113 isLegendItemVisible : true ,
96114 key : 'colorSeries1b' ,
115+ displayValue : { } ,
97116 } ,
98117 ] ;
99118 expect ( Array . from ( legend . values ( ) ) ) . toEqual ( expected ) ;
100119 } ) ;
101120 it ( 'compute legend for multiple specs' , ( ) => {
102121 seriesColor . set ( 'colorSeries1a' , colorValues1a ) ;
103122 seriesColor . set ( 'colorSeries2a' , colorValues2a ) ;
104- const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' ) ;
123+ const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' , axesSpecs ) ;
105124 const expected = [
106125 {
107126 color : 'red' ,
@@ -110,6 +129,7 @@ describe('Legends', () => {
110129 isSeriesVisible : true ,
111130 isLegendItemVisible : true ,
112131 key : 'colorSeries1a' ,
132+ displayValue : { } ,
113133 } ,
114134 {
115135 color : 'green' ,
@@ -118,19 +138,20 @@ describe('Legends', () => {
118138 isSeriesVisible : true ,
119139 isLegendItemVisible : true ,
120140 key : 'colorSeries2a' ,
141+ displayValue : { } ,
121142 } ,
122143 ] ;
123144 expect ( Array . from ( legend . values ( ) ) ) . toEqual ( expected ) ;
124145 } ) ;
125146 it ( 'empty legend for missing spec' , ( ) => {
126147 seriesColor . set ( 'colorSeries2b' , colorValues2b ) ;
127- const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' ) ;
148+ const legend = computeLegend ( seriesColor , seriesColorMap , specs , 'violet' , axesSpecs ) ;
128149 expect ( legend . size ) . toEqual ( 0 ) ;
129150 } ) ;
130151 it ( 'compute legend with default color for missing series color' , ( ) => {
131152 seriesColor . set ( 'colorSeries1a' , colorValues1a ) ;
132153 const emptyColorMap = new Map < string , string > ( ) ;
133- const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' ) ;
154+ const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' , axesSpecs ) ;
134155 const expected = [
135156 {
136157 color : 'violet' ,
@@ -139,6 +160,7 @@ describe('Legends', () => {
139160 isSeriesVisible : true ,
140161 isLegendItemVisible : true ,
141162 key : 'colorSeries1a' ,
163+ displayValue : { } ,
142164 } ,
143165 ] ;
144166 expect ( Array . from ( legend . values ( ) ) ) . toEqual ( expected ) ;
@@ -152,7 +174,7 @@ describe('Legends', () => {
152174 const emptyColorMap = new Map < string , string > ( ) ;
153175 const deselectedDataSeries = null ;
154176
155- const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' , deselectedDataSeries ) ;
177+ const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' , axesSpecs , deselectedDataSeries ) ;
156178
157179 const visibility = [ ...legend . values ( ) ] . map ( ( item ) => item . isSeriesVisible ) ;
158180
@@ -167,7 +189,7 @@ describe('Legends', () => {
167189 const emptyColorMap = new Map < string , string > ( ) ;
168190 const deselectedDataSeries = [ colorValues1a , colorValues1b ] ;
169191
170- const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' , deselectedDataSeries ) ;
192+ const legend = computeLegend ( seriesColor , emptyColorMap , specs , 'violet' , axesSpecs , deselectedDataSeries ) ;
171193
172194 const visibility = [ ...legend . values ( ) ] . map ( ( item ) => item . isSeriesVisible ) ;
173195 expect ( visibility ) . toEqual ( [ false , false , true ] ) ;
0 commit comments