/** * WordPress dependencies */ const { __ } = wp.i18n; const { Component, Fragment } = wp.element; const { ColorPalette } = wp.blockEditor || wp.editor; const { BaseControl, ExternalLink, PanelBody, SelectControl, TextControl } = wp.components; class SeriesSettings extends Component { constructor() { super( ...arguments ); } componentDidMount() { /** * We use deep-clean to remove all empty properties which causes a major issue with Series Settings. * So add a dummy property to make sure `series` object isn't empty. * Should be removed before saving the data. */ const settings = this.props.chart['visualizer-settings']; Object.keys( settings.series ) .map( i => { if ( settings.series[i] !== undefined ) { settings.series[i].temp = 1; } } ); this.props.edit( settings ); } render() { const type = this.props.chart['visualizer-chart-type']; const settings = this.props.chart['visualizer-settings']; const series = this.props.chart['visualizer-series']; return ( { Object.keys( settings.series ) .map( ( i, index ) => { i = parseInt( i ) + 1; let indexToFormat = parseInt( i ); let label = series[i].label || ''; let type = series[i].type || ''; let timer = 0; if ( 'tabular' !== type ) { indexToFormat = index; } i++; return ( { ( -1 >= [ 'tabular', 'pie' ].indexOf( type ) ) && ( { settings.series[index].visibleInLegend = e; this.props.edit( settings ); } } /> ) } { ( -1 >= [ 'tabular', 'candlestick', 'combo', 'column', 'bar' ].indexOf( type ) ) && ( { settings.series[index].lineWidth = e; this.props.edit( settings ); } } onKeyUp={ e => { clearTimeout( timer ); timer = setTimeout( () => { if ( '' != settings.series[index].lineWidth && 0 >= settings.series[index].lineWidth ) { settings.series[index].lineWidth = '0.1'; this.props.edit( settings ); } }, 700 ); } } /> { settings.series[index].pointSize = e; this.props.edit( settings ); } } /> ) } { ( -1 >= [ 'candlestick' ].indexOf( type ) ) && ( type && 'number' === type ) ? ( { settings.series[indexToFormat].format = e; this.props.edit( settings ); } } />

{ __( 'For number axis labels, this is a subset of the formatting ' ) } { __( 'ICU pattern set.' ) } { __( ' For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #%% percentage format then your values will be multiplied by 100.' ) }

) : ( 0 <= [ 'date', 'datetime', 'timeofday' ].indexOf( type ) ) && ( { settings.series[indexToFormat].format = e; this.props.edit( settings ); } } />

{ __( 'This is a subset of the date formatting ' ) } { __( 'ICU date and time format.' ) }

) } { ( 0 <= [ 'scatter', 'line' ].indexOf( type ) ) && ( { settings.series[index].curveType = e; this.props.edit( settings ); } } /> ) } { ( 0 <= [ 'area' ].indexOf( type ) ) && ( { settings.series[index].areaOpacity = e; this.props.edit( settings ); } } /> ) } { ( 0 <= [ 'combo' ].indexOf( type ) ) && ( { settings.series[index].type = e; this.props.edit( settings ); } } /> ) } { ( -1 >= [ 'tabular' ].indexOf( type ) ) && ( { settings.series[index].color = e; this.props.edit( settings ); } } /> ) }
); } ) }
); } } export default SeriesSettings;