@@ -55,8 +55,6 @@ export function transformData(
5555 return transformedData ;
5656}
5757
58- const notAxisChartSet : Set < CharOptionCompType > = new Set ( [ "pie" ] as const ) ;
59- const notAxisChartSubtypeSet : Set < string > = new Set ( [ "polar" ] as const ) ;
6058export const echartsConfigOmitChildren = [
6159 "hidden" ,
6260 "selectedPoints" ,
@@ -65,81 +63,23 @@ export const echartsConfigOmitChildren = [
6563] as const ;
6664type EchartsConfigProps = Omit < ChartCompPropsType , typeof echartsConfigOmitChildren [ number ] > ;
6765
68-
69- export function isAxisChart ( type : CharOptionCompType , polar : boolean ) {
70- return ! notAxisChartSet . has ( type ) && ! polar ;
71- }
72-
7366export function getSeriesConfig ( props : EchartsConfigProps ) {
7467 let visibleSeries = props . series . filter ( ( s ) => ! s . getView ( ) . hide ) ;
75- if ( props . chartConfig . subtype === "waterfall" ) {
76- const seriesOn = visibleSeries [ 0 ] ;
77- const seriesPlaceholder = visibleSeries [ 0 ] ;
78- visibleSeries = [ seriesPlaceholder , seriesOn ] ;
79- }
8068 const seriesLength = visibleSeries . length ;
8169 return visibleSeries . map ( ( s , index ) => {
82- if ( isAxisChart ( props . chartConfig . type , props . chartConfig . polarData ?. polar ) ) {
83- let encodeX : string , encodeY : string ;
84- const horizontalX = props . xAxisDirection === "horizontal" ;
85- let itemStyle = props . chartConfig . itemStyle ;
86-
87- if ( horizontalX ) {
88- encodeX = props . xAxisKey ;
89- encodeY = s . getView ( ) . columnName ;
90- } else {
91- encodeX = s . getView ( ) . columnName ;
92- encodeY = props . xAxisKey ;
93- }
94- const markLineData = s . getView ( ) . markLines . map ( line => ( { type : line . getView ( ) . type } ) ) ;
95- const markAreaData = s . getView ( ) . markAreas . map ( area => ( [ { name : area . getView ( ) . name , [ horizontalX ?"xAxis" :"yAxis" ] : area . getView ( ) . from , label : {
96- position : horizontalX ?"top" :"right" ,
97- } } , { [ horizontalX ?"xAxis" :"yAxis" ] : area . getView ( ) . to } ] ) ) ;
98- return {
99- name : s . getView ( ) . seriesName ,
100- selectedMode : "single" ,
101- select : {
102- itemStyle : {
103- borderColor : "#000" ,
104- } ,
105- } ,
106- step : s . getView ( ) . step ,
107- encode : {
108- x : encodeX ,
109- y : encodeY ,
110- } ,
111- markLine : {
112- data : markLineData ,
113- } ,
114- markArea : {
115- itemStyle : {
116- color : 'rgba(255, 173, 177, 0.4)' ,
117- } ,
118- data : markAreaData ,
119- } ,
120- // each type of chart's config
121- ...props . chartConfig ,
122- itemStyle : itemStyle ,
123- label : {
124- ...props . chartConfig . label ,
125- ...( ! horizontalX && { position : "outside" } ) ,
126- } ,
127- } ;
128- } else {
129- // pie
130- const radiusAndCenter = getPieRadiusAndCenter ( seriesLength , index , props . chartConfig ) ;
131- return {
132- ...props . chartConfig ,
133- radius : radiusAndCenter . radius ,
134- center : radiusAndCenter . center ,
135- name : s . getView ( ) . seriesName ,
136- selectedMode : "single" ,
137- encode : {
138- itemName : props . xAxisKey ,
139- value : s . getView ( ) . columnName ,
140- } ,
141- } ;
142- }
70+ // pie
71+ const radiusAndCenter = getPieRadiusAndCenter ( seriesLength , index , props . chartConfig ) ;
72+ return {
73+ ...props . chartConfig ,
74+ radius : radiusAndCenter . radius ,
75+ center : radiusAndCenter . center ,
76+ name : s . getView ( ) . seriesName ,
77+ selectedMode : "single" ,
78+ encode : {
79+ itemName : props . xAxisKey ,
80+ value : s . getView ( ) . columnName ,
81+ } ,
82+ } ;
14383 } ) ;
14484}
14585
@@ -149,8 +89,6 @@ export function getEchartsConfig(
14989 chartSize ?: ChartSize ,
15090 theme ?: any ,
15191) : EChartsOptionWithMap {
152- // axisChart
153- const axisChart = isAxisChart ( props . chartConfig . type , props . chartConfig . polarData ?. polar ) ;
15492 const gridPos = {
15593 left : `${ props ?. left } %` ,
15694 right : `${ props ?. right } %` ,
@@ -189,38 +127,13 @@ export function getEchartsConfig(
189127 ...gridPos ,
190128 containLabel : true ,
191129 } ,
192- animationDuration : props . animationDuration ,
193130 } ;
194- if ( props . areaPieces . length > 0 ) {
195- config . visualMap = {
196- type : 'piecewise' ,
197- show : false ,
198- dimension : 0 ,
199- seriesIndex : 0 ,
200- pieces : props . areaPieces ?. filter ( p => p . getView ( ) . from && p . getView ( ) . to && p . getView ( ) . color ) ?. map ( p => (
201- {
202- ...( p . getView ( ) . from ?{ min : parseInt ( p . getView ( ) . from ) } :{ } ) ,
203- ...( p . getView ( ) . to ?{ max : parseInt ( p . getView ( ) . to ) } :{ } ) ,
204- ...( p . getView ( ) . color ?{ color : p . getView ( ) . color } :{ } ) ,
205- }
206- ) )
207- }
208- }
209- if ( props . chartConfig . race ) {
210- config = {
211- ...config ,
212- // Disable init animation.
213- animationDuration : 0 ,
214- animationDurationUpdate : 2000 ,
215- animationEasing : 'linear' ,
216- animationEasingUpdate : 'linear' ,
217- }
218- }
131+
219132 if ( props . data . length <= 0 ) {
220133 // no data
221134 return {
222135 ...config ,
223- ...( axisChart ? noDataAxisConfig : noDataPieChartConfig ) ,
136+ ...noDataPieChartConfig ,
224137 } ;
225138 }
226139 const yAxisConfig = props . yConfig ( ) ;
@@ -231,27 +144,6 @@ export function getEchartsConfig(
231144 let transformedData =
232145 yAxisConfig . type === "category" || yAxisConfig . type === "time" ? props . data : transformData ( props . data , props . xAxisKey , seriesColumnNames ) ;
233146
234- if ( props . chartConfig . polarData ?. polar ) {
235- config = {
236- ...config ,
237- polar : {
238- radius : [ props . chartConfig . polarData . polarRadiusStart , props . chartConfig . polarData . polarRadiusEnd ] ,
239- } ,
240- radiusAxis : {
241- type : props . chartConfig . polarData . polarIsTangent ?'category' :undefined ,
242- data : props . chartConfig . polarData . polarIsTangent && props . chartConfig . polarData . labelData . length !== 0 ?props . chartConfig . polarData . labelData :undefined ,
243- max : props . chartConfig . polarData . polarIsTangent ?undefined :props . chartConfig . polarData . radiusAxisMax || undefined ,
244- } ,
245- angleAxis : {
246- type : props . chartConfig . polarData . polarIsTangent ?undefined :'category' ,
247- data : ! props . chartConfig . polarData . polarIsTangent && props . chartConfig . polarData . labelData . length !== 0 ?props . chartConfig . polarData . labelData :undefined ,
248- max : props . chartConfig . polarData . polarIsTangent ?props . chartConfig . polarData . radiusAxisMax || undefined :undefined ,
249- startAngle : props . chartConfig . polarData . polarStartAngle ,
250- endAngle : props . chartConfig . polarData . polarEndAngle ,
251- } ,
252- }
253- }
254-
255147 config = {
256148 ...config ,
257149 dataset : [
@@ -273,70 +165,10 @@ export function getEchartsConfig(
273165 lineStyle : {
274166 ...chartStyleWrapper ( props ?. chartStyle , theme ?. chartStyle )
275167 } ,
276- data : transformedData . map ( ( i : any ) => i [ series . name ] )
277168 } ) ) ,
278169 } ;
279- if ( axisChart ) {
280- // pure chart's size except the margin around
281- let chartRealSize ;
282- if ( chartSize ) {
283- const rightSize =
284- typeof gridPos . right === "number"
285- ? gridPos . right
286- : ( chartSize . w * parseFloat ( gridPos . right ) ) / 100.0 ;
287- chartRealSize = {
288- // actually it's self-adaptive with the x-axis label on the left, not that accurate but work
289- w : chartSize . w - gridPos . left - rightSize ,
290- // also self-adaptive on the bottom
291- h : chartSize . h - gridPos . top - gridPos . bottom ,
292- right : rightSize ,
293- } ;
294- }
295- const finalXyConfig = calcXYConfig (
296- props . xConfig ,
297- yAxisConfig ,
298- props . xAxisDirection ,
299- transformedData . map ( ( d ) => d [ props . xAxisKey ] ) ,
300- chartRealSize
301- ) ;
302- config = {
303- ...config ,
304- // @ts -ignore
305- xAxis : {
306- ...finalXyConfig . xConfig ,
307- axisLabel : {
308- ...styleWrapper ( props ?. xAxisStyle , theme ?. xAxisStyle , 11 )
309- } ,
310- data : finalXyConfig . xConfig . type === "category" && ( props . xAxisData as [ ] ) . length !== 0 ?props ?. xAxisData :transformedData . map ( ( i : any ) => i [ props . xAxisKey ] ) ,
311- } ,
312- // @ts -ignore
313- yAxis : {
314- ...finalXyConfig . yConfig ,
315- axisLabel : {
316- ...styleWrapper ( props ?. yAxisStyle , theme ?. yAxisStyle , 11 )
317- } ,
318- data : finalXyConfig . yConfig . type === "category" && ( props . xAxisData as [ ] ) . length !== 0 ?props ?. xAxisData :transformedData . map ( ( i : any ) => i [ props . xAxisKey ] ) ,
319- } ,
320- } ;
321-
322- if ( props . chartConfig . race ) {
323- config = {
324- ...config ,
325- xAxis : {
326- ...config . xAxis ,
327- animationDuration : 300 ,
328- animationDurationUpdate : 300
329- } ,
330- yAxis : {
331- ...config . yAxis ,
332- animationDuration : 300 ,
333- animationDurationUpdate : 300
334- } ,
335- }
336- }
337- }
338170
339- // log .log("Echarts transformedData and config", transformedData, config);
171+ // console .log("Echarts transformedData and config", transformedData, config);
340172 return config ;
341173}
342174
0 commit comments