@@ -21,6 +21,9 @@ import {
2121 ScaleType ,
2222 Settings ,
2323} from '../src/' ;
24+ import { DataSeriesColorsValues } from '../src/lib/series/series' ;
25+ import { CustomSeriesColorsMap } from '../src/lib/series/specs' ;
26+ import * as TestDatasets from '../src/lib/series/utils/test_dataset' ;
2427import { DEFAULT_MISSING_COLOR } from '../src/lib/themes/theme_commons' ;
2528
2629function range (
@@ -348,4 +351,62 @@ storiesOf('Stylings', module)
348351 />
349352 </ Chart >
350353 ) ;
354+ } )
355+ . add ( 'custom series colors through spec props' , ( ) => {
356+ const barCustomSeriesColors : CustomSeriesColorsMap = new Map ( ) ;
357+ const barDataSeriesColorValues : DataSeriesColorsValues = {
358+ colorValues : [ 'cloudflare.com' , 'direct-cdn' , 'y2' ] ,
359+ specId : getSpecId ( 'bars' ) ,
360+ } ;
361+
362+ const lineCustomSeriesColors : CustomSeriesColorsMap = new Map ( ) ;
363+ const lineDataSeriesColorValues : DataSeriesColorsValues = {
364+ colorValues : [ ] ,
365+ specId : getSpecId ( 'lines' ) ,
366+ } ;
367+
368+ const customBarColorKnob = color ( 'barDataSeriesColor' , '#000' ) ;
369+ const customLineColorKnob = color ( 'lineDataSeriesColor' , '#ff0' ) ;
370+ barCustomSeriesColors . set ( barDataSeriesColorValues , customBarColorKnob ) ;
371+ lineCustomSeriesColors . set ( lineDataSeriesColorValues , customLineColorKnob ) ;
372+
373+ return (
374+ < Chart renderer = "canvas" className = { 'story-chart' } >
375+ < Settings showLegend = { true } legendPosition = { Position . Right } />
376+ < Axis
377+ id = { getAxisId ( 'bottom' ) }
378+ position = { Position . Bottom }
379+ title = { 'Bottom axis' }
380+ showOverlappingTicks = { true }
381+ />
382+ < Axis
383+ id = { getAxisId ( 'left2' ) }
384+ title = { 'Left axis' }
385+ position = { Position . Left }
386+ tickFormat = { ( d ) => Number ( d ) . toFixed ( 2 ) }
387+ />
388+
389+ < BarSeries
390+ id = { getSpecId ( 'bars' ) }
391+ xScaleType = { ScaleType . Linear }
392+ yScaleType = { ScaleType . Linear }
393+ xAccessor = "x"
394+ yAccessors = { [ 'y1' , 'y2' ] }
395+ splitSeriesAccessors = { [ 'g1' , 'g2' ] }
396+ customSeriesColors = { barCustomSeriesColors }
397+ data = { TestDatasets . BARCHART_2Y2G }
398+ yScaleToDataExtent = { false }
399+ />
400+ < LineSeries
401+ id = { getSpecId ( 'lines' ) }
402+ xScaleType = { ScaleType . Linear }
403+ yScaleType = { ScaleType . Linear }
404+ xAccessor = "x"
405+ yAccessors = { [ 'y' ] }
406+ customSeriesColors = { lineCustomSeriesColors }
407+ data = { [ { x : 0 , y : 3 } , { x : 1 , y : 2 } , { x : 2 , y : 4 } , { x : 3 , y : 10 } ] }
408+ yScaleToDataExtent = { false }
409+ />
410+ </ Chart >
411+ ) ;
351412 } ) ;
0 commit comments