@@ -13,8 +13,37 @@ import {
1313 ScaleType ,
1414 Settings ,
1515} from '..' ;
16+ import { PartialTheme } from '../lib/themes/theme' ;
1617import { LineSeries } from '../specs' ;
1718
19+ function createThemeAction ( title : string , min : number , max : number , value : number ) {
20+ return number ( title , value , {
21+ range : true ,
22+ min,
23+ max,
24+ step : 1 ,
25+ } , 'theme' ) ;
26+ }
27+
28+ function renderAxisWithOptions ( position : Position , seriesGroup : string , show : boolean ) {
29+ const axisTitle = `${ position } axis (${ seriesGroup } )` ;
30+
31+ const showAxis = boolean ( `show ${ axisTitle } axis` , show , `${ position } axes` ) ;
32+
33+ if ( ! showAxis ) {
34+ return null ;
35+ }
36+
37+ const axisProps = {
38+ id : getAxisId ( axisTitle ) ,
39+ position,
40+ title : axisTitle ,
41+ showOverlappingTicks : true ,
42+ } ;
43+
44+ return < Axis { ...axisProps } /> ;
45+ }
46+
1847storiesOf ( 'Axis' , module )
1948 . add ( 'basic' , ( ) => {
2049 return (
@@ -149,29 +178,37 @@ storiesOf('Axis', module)
149178 </ Chart >
150179 ) ;
151180 } )
152- . add ( 'with multi axis (TO FIX)' , ( ) => {
181+ . add ( 'with multi axis' , ( ) => {
182+ const theme : PartialTheme = {
183+ chart : {
184+ margins : {
185+ left : createThemeAction ( 'margin left' , 0 , 50 , 0 ) ,
186+ right : createThemeAction ( 'margin right' , 0 , 50 , 0 ) ,
187+ top : createThemeAction ( 'margin top' , 0 , 50 , 0 ) ,
188+ bottom : createThemeAction ( 'margin bottom' , 0 , 50 , 0 ) ,
189+ } ,
190+ paddings : {
191+ left : createThemeAction ( 'padding left' , 0 , 50 , 0 ) ,
192+ right : createThemeAction ( 'padding right' , 0 , 50 , 0 ) ,
193+ top : createThemeAction ( 'padding top' , 0 , 50 , 0 ) ,
194+ bottom : createThemeAction ( 'padding bottom' , 0 , 50 , 0 ) ,
195+ } ,
196+ } ,
197+ } ;
198+
199+ const seriesGroup1 = 'group1' ;
200+ const seriesGroup2 = 'group2' ;
153201 return (
154- < Chart renderer = "canvas" className = { 'story-chart' } >
155- < Settings showLegend = { false } />
156- < Axis
157- id = { getAxisId ( 'bottom' ) }
158- position = { Position . Bottom }
159- title = { 'Bottom axis' }
160- showOverlappingTicks = { true }
161- />
162- < Axis
163- id = { getAxisId ( 'left1' ) }
164- title = { 'First left axis' }
165- position = { Position . Left }
166- tickFormat = { ( d ) => Number ( d ) . toFixed ( 2 ) }
167- />
168- < Axis
169- id = { getAxisId ( 'left2' ) }
170- title = { 'Second left axis' }
171- groupId = { getGroupId ( 'group2' ) }
172- position = { Position . Left }
173- tickFormat = { ( d ) => Number ( d ) . toFixed ( 2 ) }
174- />
202+ < Chart renderer = "canvas" size = { [ 500 , 300 ] } className = { 'story-chart' } >
203+ < Settings showLegend = { false } theme = { theme } debug = { boolean ( 'debug' , true ) } />
204+ { renderAxisWithOptions ( Position . Top , seriesGroup1 , false ) }
205+ { renderAxisWithOptions ( Position . Top , seriesGroup2 , true ) }
206+ { renderAxisWithOptions ( Position . Left , seriesGroup1 , false ) }
207+ { renderAxisWithOptions ( Position . Left , seriesGroup2 , true ) }
208+ { renderAxisWithOptions ( Position . Bottom , seriesGroup1 , false ) }
209+ { renderAxisWithOptions ( Position . Bottom , seriesGroup2 , true ) }
210+ { renderAxisWithOptions ( Position . Right , seriesGroup1 , false ) }
211+ { renderAxisWithOptions ( Position . Right , seriesGroup2 , true ) }
175212 < BarSeries
176213 id = { getSpecId ( 'barseries1' ) }
177214 xScaleType = { ScaleType . Linear }
@@ -180,15 +217,6 @@ storiesOf('Axis', module)
180217 yAccessors = { [ 'y' ] }
181218 data = { [ { x : 0 , y : 1 } , { x : 1 , y : 2 } , { x : 2 , y : 3 } , { x : 3 , y : 4 } ] }
182219 />
183- < BarSeries
184- id = { getSpecId ( 'barseries2' ) }
185- groupId = { getGroupId ( 'group2' ) }
186- xScaleType = { ScaleType . Linear }
187- yScaleType = { ScaleType . Linear }
188- xAccessor = "x"
189- yAccessors = { [ 'y' ] }
190- data = { [ { x : 0 , y : 8 } , { x : 1 , y : 7 } , { x : 2 , y : 6 } , { x : 3 , y : 5 } ] }
191- />
192220 </ Chart >
193221 ) ;
194222 } )
0 commit comments