| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
const { __ } = wp.i18n; |
| 5 |
|
| 6 |
const { Component } = wp.element; |
| 7 |
|
| 8 |
const { ColorPalette } = wp.blockEditor || wp.editor; |
| 9 |
|
| 10 |
const { |
| 11 |
BaseControl, |
| 12 |
CheckboxControl, |
| 13 |
PanelBody |
| 14 |
} = wp.components; |
| 15 |
|
| 16 |
class TimelineSettings extends Component { |
| 17 |
constructor() { |
| 18 |
super( ...arguments ); |
| 19 |
|
| 20 |
this.mapValues = this.mapValues.bind( this ); |
| 21 |
} |
| 22 |
|
| 23 |
mapValues( settings, objName ) { |
| 24 |
if ( settings.timeline === undefined ) { |
| 25 |
return settings[ objName ]; |
| 26 |
} |
| 27 |
return settings.timeline[ objName ]; |
| 28 |
} |
| 29 |
|
| 30 |
render() { |
| 31 |
|
| 32 |
const settings = this.props.chart['visualizer-settings']; |
| 33 |
this.mapValues( settings, 'showRowLabels' ); |
| 34 |
|
| 35 |
return ( |
| 36 |
<PanelBody |
| 37 |
title={ __( 'Timeline Settings' ) } |
| 38 |
initialOpen={ false } |
| 39 |
className="visualizer-advanced-panel" |
| 40 |
> |
| 41 |
|
| 42 |
<CheckboxControl |
| 43 |
label={ __( 'Show Row Label' ) } |
| 44 |
help={ __( 'If checked, shows the category/row label.' ) } |
| 45 |
checked={ Number( this.mapValues( settings, 'showRowLabels' ) ) } |
| 46 |
onChange={ e => { |
| 47 |
if ( settings.timeline === undefined ) { |
| 48 |
settings.timeline = {}; |
| 49 |
} |
| 50 |
settings.timeline.showRowLabels = ! Number( this.mapValues( settings, 'showRowLabels' ) ); |
| 51 |
this.props.edit( settings ); |
| 52 |
} } |
| 53 |
/> |
| 54 |
|
| 55 |
<CheckboxControl |
| 56 |
label={ __( 'Group by Row Label' ) } |
| 57 |
help={ __( 'If checked, groups the bars on the basis of the category/row label.' ) } |
| 58 |
checked={ Number( this.mapValues( settings, 'groupByRowLabel' ) ) } |
| 59 |
onChange={ e => { |
| 60 |
if ( settings.timeline === undefined ) { |
| 61 |
settings.timeline = {}; |
| 62 |
} |
| 63 |
settings.timeline.groupByRowLabel = ! Number( this.mapValues( settings, 'groupByRowLabel' ) ); |
| 64 |
this.props.edit( settings ); |
| 65 |
} } |
| 66 |
/> |
| 67 |
|
| 68 |
<CheckboxControl |
| 69 |
label={ __( 'Color by Row Label' ) } |
| 70 |
help={ __( 'If checked, colors every bar on the row the same.' ) } |
| 71 |
checked={ Number( this.mapValues( settings, 'colorByRowLabel' ) ) } |
| 72 |
onChange={ e => { |
| 73 |
if ( settings.timeline === undefined ) { |
| 74 |
settings.timeline = {}; |
| 75 |
} |
| 76 |
settings.timeline.colorByRowLabel = ! Number( this.mapValues( settings, 'colorByRowLabel' ) ); |
| 77 |
this.props.edit( settings ); |
| 78 |
} } |
| 79 |
/> |
| 80 |
|
| 81 |
<BaseControl |
| 82 |
label={ __( 'Single Color' ) } |
| 83 |
> |
| 84 |
<ColorPalette |
| 85 |
value={ this.mapValues( settings, 'singleColor' ) } |
| 86 |
onChange={ e => { |
| 87 |
if ( settings.timeline === undefined ) { |
| 88 |
settings.timeline = {}; |
| 89 |
} |
| 90 |
settings.timeline.singleColor = e; |
| 91 |
this.props.edit( settings ); |
| 92 |
} } |
| 93 |
/> |
| 94 |
</BaseControl> |
| 95 |
|
| 96 |
</PanelBody> |
| 97 |
); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
export default TimelineSettings; |
| 102 |
|