@@ -4,8 +4,10 @@ import {
44 DataZoom ,
55 Graphic ,
66 Legend ,
7+ LineChart ,
78 Polar ,
89 Title ,
10+ Toolbox ,
911 Tooltip ,
1012 echarts ,
1113} from '@fanciers/echarts-react' ;
@@ -491,3 +493,110 @@ export const BarGradient: Story = {
491493 ) ;
492494 } ,
493495} ;
496+
497+ const barLabelRotationAlign = [ 'left' , 'center' , 'right' ] as const ;
498+ const barLabelRotationVerticalAlign = [ 'top' , 'middle' , 'bottom' ] as const ;
499+ const barLabelRotationPosition = [
500+ 'left' ,
501+ 'right' ,
502+ 'top' ,
503+ 'bottom' ,
504+ 'inside' ,
505+ 'insideTop' ,
506+ 'insideLeft' ,
507+ 'insideRight' ,
508+ 'insideBottom' ,
509+ 'insideTopLeft' ,
510+ 'insideTopRight' ,
511+ 'insideBottomLeft' ,
512+ 'insideBottomRight' ,
513+ ] as const ;
514+ const barLabelRotationMeta = {
515+ component : ( _props : {
516+ rotate : number ;
517+ align : ( typeof barLabelRotationAlign ) [ number ] ;
518+ verticalAlign : ( typeof barLabelRotationVerticalAlign ) [ number ] ;
519+ position : ( typeof barLabelRotationPosition ) [ number ] ;
520+ distance : number ;
521+ } ) => null ,
522+ argTypes : {
523+ rotate : { control : { type : 'number' , min : - 90 , max : 90 } } ,
524+ align : { control : { type : 'inline-radio' } , options : barLabelRotationAlign } ,
525+ verticalAlign : { control : { type : 'inline-radio' } , options : barLabelRotationVerticalAlign } ,
526+ position : { control : { type : 'inline-radio' } , options : barLabelRotationPosition } ,
527+ distance : { control : { type : 'number' , min : 0 , max : 100 } } ,
528+ } ,
529+ } satisfies Meta ;
530+
531+ export const BarLabelRotation : StoryObj < typeof barLabelRotationMeta > = {
532+ name : 'Bar Label Rotation' ,
533+ argTypes : barLabelRotationMeta . argTypes ,
534+ args : { rotate : 90 , align : 'left' , verticalAlign : 'middle' , position : 'insideBottom' , distance : 15 } ,
535+ render ( args ) {
536+ const labelOption : BarSeriesLabelOption = {
537+ ...args ,
538+ show : true ,
539+ formatter : '{c} {name|{a}}' ,
540+ fontSize : 16 ,
541+ rich : { name : { } } ,
542+ } ;
543+
544+ return (
545+ < BarChart
546+ style = { { width : 480 , height : 300 } }
547+ compose = { [ LineChart ] }
548+ xAxis = { [ { type : 'category' , axisTick : { show : false } , data : [ '2012' , '2013' , '2014' , '2015' , '2016' ] } ] }
549+ yAxis = { [ { type : 'value' } ] }
550+ series = { [
551+ {
552+ name : 'Forest' ,
553+ type : 'bar' ,
554+ barGap : 0 ,
555+ label : labelOption ,
556+ emphasis : { focus : 'series' } ,
557+ data : [ 320 , 332 , 301 , 334 , 390 ] ,
558+ } ,
559+ {
560+ name : 'Steppe' ,
561+ type : 'bar' ,
562+ label : labelOption ,
563+ emphasis : { focus : 'series' } ,
564+ data : [ 220 , 182 , 191 , 234 , 290 ] ,
565+ } ,
566+ {
567+ name : 'Desert' ,
568+ type : 'bar' ,
569+ label : labelOption ,
570+ emphasis : { focus : 'series' } ,
571+ data : [ 150 , 232 , 201 , 154 , 190 ] ,
572+ } ,
573+ {
574+ name : 'Wetland' ,
575+ type : 'bar' ,
576+ label : labelOption ,
577+ emphasis : { focus : 'series' } ,
578+ data : [ 98 , 77 , 101 , 99 , 40 ] ,
579+ } ,
580+ ] }
581+ >
582+ < Tooltip tooltip = { { trigger : 'axis' , axisPointer : { type : 'shadow' } } } />
583+ < Legend legend = { { data : [ 'Forest' , 'Steppe' , 'Desert' , 'Wetland' ] } } />
584+ < Toolbox
585+ toolbox = { {
586+ show : true ,
587+ orient : 'vertical' ,
588+ left : 'right' ,
589+ top : 'center' ,
590+ feature : {
591+ mark : { show : true } ,
592+ dataView : { show : true , readOnly : false } ,
593+ magicType : { show : true , type : [ 'line' , 'bar' , 'stack' ] } ,
594+ restore : { show : true } ,
595+ saveAsImage : { show : true } ,
596+ } ,
597+ } }
598+ />
599+ </ BarChart >
600+ ) ;
601+ } ,
602+ } ;
0 commit comments