@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33import React , { Component } from 'react' ;
44import Field from './Field' ;
55import nestedProperty from 'plotly.js/src/lib/nested_property' ;
6- import { connectToContainer } from 'lib' ;
6+ import { connectToContainer , maybeAdjustSrc , maybeTransposeData } from 'lib' ;
77
88export function attributeIsData ( meta = { } ) {
99 return meta . valType === 'data_array' || meta . arrayOk ;
@@ -26,16 +26,24 @@ export class UnconnectedDataSelector extends Component {
2626 this . dataSourceOptions = context . dataSourceOptions || [ ] ;
2727
2828 this . srcAttr = props . attr + 'src' ;
29- this . srcProperty = nestedProperty ( props . container , this . srcAttr ) ;
30- this . fullValue = this . srcProperty . get ( ) ;
29+ this . srcProperty = nestedProperty ( props . container , this . srcAttr ) . get ( ) ;
30+ this . fullValue = this . context . srcConverters
31+ ? this . context . srcConverters . toSrc ( this . srcProperty , props . container . type )
32+ : this . srcProperty ;
3133
3234 this . is2D = false ;
3335 if ( props . container ) {
3436 this . is2D =
3537 ( props . attr === 'z' &&
36- [ 'contour' , 'heatmap' , 'surface' , 'heatmapgl' ] . includes (
37- props . container . type
38- ) ) ||
38+ [
39+ 'contour' ,
40+ 'contourgl' ,
41+ 'heatmap' ,
42+ 'heatmapgl' ,
43+ 'surface' ,
44+ 'carpet' ,
45+ 'contourcarpet' ,
46+ ] . includes ( props . container . type ) ) ||
3947 ( props . container . type === 'table' && props . attr !== 'columnorder' ) ;
4048 }
4149 }
@@ -44,39 +52,33 @@ export class UnconnectedDataSelector extends Component {
4452 if ( ! this . props . updateContainer ) {
4553 return ;
4654 }
55+
4756 const update = { } ;
57+ let data ;
4858
4959 if ( Array . isArray ( value ) ) {
50- update [ this . props . attr ] = value
60+ data = value
5161 . filter ( v => Array . isArray ( this . dataSources [ v ] ) )
5262 . map ( v => this . dataSources [ v ] ) ;
53-
54- // Table traces have many configuration options,
55- // The below attributes can be 2d or 1d and will affect the plot differently
56- // EX:
57- // header.values = ['Jan', 'Feb', 'Mar'] => will put data in a row
58- // header.values = [['Jan', 1], ['Feb', 2], ['Mar', 3]] => will create 3 columns
59- // 1d arrays affect columns
60- // 2d arrays affect rows within each column
61-
62- if (
63- this . props . container . type === 'table' &&
64- value . length === 1 &&
65- [
66- 'header.values' ,
67- 'header.font.color' ,
68- 'header.font.size' ,
69- 'header.fill.color' ,
70- 'columnwidth' ,
71- ] . includes ( this . props . attr )
72- ) {
73- update [ this . props . attr ] = update [ this . props . attr ] [ 0 ] ;
74- }
7563 } else {
76- update [ this . props . attr ] = this . dataSources [ value ] || null ;
64+ data = this . dataSources [ value ] || null ;
7765 }
78- update [ this . srcAttr ] = value ;
7966
67+ update [ this . props . attr ] = maybeTransposeData (
68+ data ,
69+ this . srcAttr ,
70+ this . props . container . type
71+ ) ;
72+ update [ this . srcAttr ] = maybeAdjustSrc (
73+ value ,
74+ this . srcAttr ,
75+ this . props . container . type ,
76+ {
77+ fromSrc : this . context . srcConverters
78+ ? this . context . srcConverters . fromSrc
79+ : null ,
80+ }
81+ ) ;
8082 this . props . updateContainer ( update ) ;
8183 }
8284
@@ -122,6 +124,10 @@ UnconnectedDataSelector.contextTypes = {
122124 dataSourceOptions : PropTypes . array ,
123125 dataSourceValueRenderer : PropTypes . func ,
124126 dataSourceOptionRenderer : PropTypes . func ,
127+ srcConverters : PropTypes . shape ( {
128+ toSrc : PropTypes . func . isRequired ,
129+ fromSrc : PropTypes . func . isRequired ,
130+ } ) ,
125131} ;
126132
127133function modifyPlotProps ( props , context , plotProps ) {
0 commit comments