@@ -43,6 +43,26 @@ export const isMonthArray = (array: any[]): boolean => {
43
43
return false ;
44
44
} ;
45
45
46
+ function getTitles ( layout : any ) {
47
+ const titles = {
48
+ chartTitle :
49
+ typeof layout . title === 'string' ? layout . title : typeof layout . title ?. text === 'string' ? layout . title . text : '' ,
50
+ xAxisTitle :
51
+ typeof layout ?. xaxis ?. title === 'string'
52
+ ? layout ?. xaxis ?. title
53
+ : typeof layout ?. xaxis ?. title ?. text === 'string'
54
+ ? layout ?. xaxis ?. title ?. text
55
+ : '' ,
56
+ yAxisTitle :
57
+ typeof layout ?. yaxis ?. title === 'string'
58
+ ? layout ?. yaxis ?. title
59
+ : typeof layout ?. yaxis ?. title ?. text === 'string'
60
+ ? layout ?. yaxis ?. title ?. text
61
+ : '' ,
62
+ } ;
63
+ return titles ;
64
+ }
65
+
46
66
export const updateXValues = ( xValues : any [ ] ) : any [ ] => {
47
67
const presentYear = new Date ( ) . getFullYear ( ) ;
48
68
const dates = xValues . map ( possiblyMonthValue => {
@@ -115,9 +135,11 @@ export const transformPlotlyJsonToDonutProps = (
115
135
} ,
116
136
} ;
117
137
138
+ const { chartTitle } = getTitles ( layout ) ;
139
+
118
140
return {
119
141
data : {
120
- chartTitle : layout ?. title ,
142
+ chartTitle,
121
143
chartData : donutData ,
122
144
} ,
123
145
hideLegend : layout ?. showlegend === false ? true : false ,
@@ -165,13 +187,17 @@ export const transformPlotlyJsonToVSBCProps = (
165
187
} ) ;
166
188
} ) ;
167
189
190
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
191
+
168
192
return {
169
193
data : Object . values ( mapXToDataPoints ) ,
170
- chartTitle : layout ?. title ,
171
194
// width: layout?.width,
172
195
// height: layout?.height,
173
196
barWidth : 'auto' ,
174
197
yMaxValue,
198
+ chartTitle,
199
+ xAxisTitle,
200
+ yAxisTitle,
175
201
} ;
176
202
} ;
177
203
@@ -203,12 +229,16 @@ export const transformPlotlyJsonToGVBCProps = (
203
229
} ) ;
204
230
} ) ;
205
231
232
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
233
+
206
234
return {
207
235
data : Object . values ( mapXToDataPoints ) ,
208
- chartTitle : layout ?. title ,
209
236
// width: layout?.width,
210
237
// height: layout?.height,
211
238
barwidth : 'auto' ,
239
+ chartTitle,
240
+ xAxisTitle,
241
+ yAxisTitle,
212
242
} ;
213
243
} ;
214
244
@@ -288,13 +318,17 @@ export const transformPlotlyJsonToVBCProps = (
288
318
} ) ;
289
319
} ) ;
290
320
321
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
322
+
291
323
return {
292
324
data : vbcData ,
293
- chartTitle : typeof layout ?. title === 'string' ? layout ?. title : '' ,
294
325
// width: layout?.width,
295
326
// height: layout?.height,
296
327
barWidth : 24 ,
297
328
supportNegativeData : true ,
329
+ chartTitle,
330
+ xAxisTitle,
331
+ yAxisTitle,
298
332
} ;
299
333
} ;
300
334
@@ -324,20 +358,26 @@ export const transformPlotlyJsonToScatterChartProps = (
324
358
} ;
325
359
} ) ;
326
360
361
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
362
+
327
363
const chartProps : IChartProps = {
328
- chartTitle : typeof layout . title === 'string' ? layout . title : '' ,
364
+ chartTitle,
329
365
lineChartData : chartData ,
330
366
} ;
331
367
332
368
if ( isAreaChart ) {
333
369
return {
334
370
data : chartProps ,
335
371
supportNegativeData : true ,
372
+ xAxisTitle,
373
+ yAxisTitle,
336
374
} as IAreaChartProps ;
337
375
} else {
338
376
return {
339
377
data : chartProps ,
340
378
supportNegativeData : true ,
379
+ xAxisTitle,
380
+ yAxisTitle,
341
381
} as ILineChartProps ;
342
382
}
343
383
} ;
@@ -372,9 +412,15 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (
372
412
const gapFactor = 1 / ( 1 + scalingFactor * numberOfBars ) ;
373
413
const barHeight = availableHeight / ( numberOfBars * ( 1 + gapFactor ) ) ;
374
414
415
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
416
+
375
417
return {
376
418
data : chartData ,
377
- chartTitle : typeof layout . title === 'string' ? layout . title : '' ,
419
+ chartTitle,
420
+ xAxisTitle,
421
+ yAxisTitle,
422
+ secondaryYAxistitle :
423
+ typeof layout ?. yaxis2 ?. title === 'string' ? layout ?. yaxis2 ?. title : layout ?. yaxis2 ?. title ?. text || '' ,
378
424
barHeight,
379
425
showYAxisLables : true ,
380
426
styles : {
@@ -419,13 +465,17 @@ export const transformPlotlyJsonToHeatmapProps = (jsonObj: any): IHeatMapChartPr
419
465
? firstData . colorscale . map ( ( arr : any ) => arr [ 0 ] * ( zMax - zMin ) + zMin )
420
466
: [ ] ;
421
467
const rangeValuesForColorScale : string [ ] = firstData . colorscale ? firstData . colorscale . map ( ( arr : any ) => arr [ 1 ] ) : [ ] ;
468
+ const { chartTitle, xAxisTitle, yAxisTitle } = getTitles ( layout ) ;
422
469
423
470
return {
424
471
data : [ heatmapData ] ,
425
472
domainValuesForColorScale,
426
473
rangeValuesForColorScale,
427
474
hideLegend : true ,
428
475
showYAxisLables : true ,
476
+ chartTitle,
477
+ xAxisTitle,
478
+ yAxisTitle,
429
479
sortOrder : 'none' ,
430
480
} ;
431
481
} ;
@@ -473,9 +523,12 @@ export const transformPlotlyJsonToSankeyProps = (
473
523
} ,
474
524
} ;
475
525
const shouldResize : number = width + height ;
526
+
527
+ const { chartTitle } = getTitles ( layout ) ;
528
+
476
529
return {
477
530
data : {
478
- chartTitle : typeof layout ?. title === 'string' ? layout ?. title : '' ,
531
+ chartTitle,
479
532
SankeyChartData : sankeyChartData ,
480
533
} ,
481
534
width,
@@ -538,10 +591,12 @@ export const transformPlotlyJsonToGaugeProps = (
538
591
} ,
539
592
} ;
540
593
594
+ const { chartTitle } = getTitles ( layout ) ;
595
+
541
596
return {
542
597
segments,
543
598
chartValue : typeof firstData . value === 'number' ? firstData . value : 0 ,
544
- chartTitle : typeof firstData . title ?. text === 'string' ? firstData . title ?. text : '' ,
599
+ chartTitle,
545
600
sublabel,
546
601
// range values can be null
547
602
minValue : typeof firstData . gauge ?. axis ?. range ?. [ 0 ] === 'number' ? firstData . gauge ?. axis ?. range ?. [ 0 ] : undefined ,
0 commit comments