| 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 |
SelectControl, |
| 15 |
TextControl |
| 16 |
} = wp.components; |
| 17 |
|
| 18 |
class GeneralSettings extends Component { |
| 19 |
constructor() { |
| 20 |
super( ...arguments ); |
| 21 |
} |
| 22 |
|
| 23 |
render() { |
| 24 |
|
| 25 |
const type = this.props.chart['visualizer-chart-type']; |
| 26 |
|
| 27 |
const settings = this.props.chart['visualizer-settings']; |
| 28 |
|
| 29 |
const tooltipTriggers = [ { label: __( 'The tooltip will be displayed when the user hovers over an element' ), value: 'focus' } ]; |
| 30 |
|
| 31 |
if ( -1 >= [ 'timeline' ].indexOf( type ) ) { |
| 32 |
tooltipTriggers[1] = { label: __( 'The tooltip will be displayed when the user selects an element' ), value: 'selection' }; |
| 33 |
} |
| 34 |
|
| 35 |
tooltipTriggers[2] = { label: __( 'The tooltip will not be displayed' ), value: 'none' }; |
| 36 |
|
| 37 |
let positions = [ |
| 38 |
{ label: __( 'Left of the chart' ), value: 'left' }, |
| 39 |
{ label: __( 'Right of the chart' ), value: 'right' }, |
| 40 |
{ label: __( 'Above the chart' ), value: 'top' }, |
| 41 |
{ label: __( 'Below the chart' ), value: 'bottom' }, |
| 42 |
{ label: __( 'Omit the legend' ), value: 'none' } |
| 43 |
]; |
| 44 |
|
| 45 |
if ( 'pie' !== type ) { |
| 46 |
positions.push({ label: __( 'Inside the chart' ), value: 'in' }); |
| 47 |
} |
| 48 |
|
| 49 |
let titleHelp = __( 'Text to display above the chart.' ); |
| 50 |
if ( 0 <= [ 'tabular', 'dataTable', 'gauge', 'geo', 'timeline' ].indexOf( type ) ) { |
| 51 |
titleHelp = __( 'Text to display in the back-end admin area' ); |
| 52 |
} |
| 53 |
|
| 54 |
return ( |
| 55 |
<PanelBody |
| 56 |
title={ __( 'General Settings' ) } |
| 57 |
initialOpen={ false } |
| 58 |
className="visualizer-advanced-panel" |
| 59 |
> |
| 60 |
|
| 61 |
<PanelBody |
| 62 |
title={ __( 'Title' ) } |
| 63 |
className="visualizer-inner-sections" |
| 64 |
initialOpen={ false } |
| 65 |
> |
| 66 |
|
| 67 |
<TextControl |
| 68 |
label={ __( 'Chart Title' ) } |
| 69 |
help={ titleHelp } |
| 70 |
value={ settings.title } |
| 71 |
onChange={ e => { |
| 72 |
settings.title = e; |
| 73 |
this.props.edit( settings ); |
| 74 |
} } |
| 75 |
/> |
| 76 |
|
| 77 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'pie', 'timeline' ].indexOf( type ) ) && ( |
| 78 |
<SelectControl |
| 79 |
label={ __( 'Chart Title Position' ) } |
| 80 |
help={ __( 'Where to place the chart title, compared to the chart area.' ) } |
| 81 |
value={ settings.titlePosition ? settings.titlePosition : 'out' } |
| 82 |
options={ [ |
| 83 |
{ label: __( 'Inside the chart' ), value: 'in' }, |
| 84 |
{ label: __( 'Outside the chart' ), value: 'out' }, |
| 85 |
{ label: __( 'None' ), value: 'none' } |
| 86 |
] } |
| 87 |
onChange={ e => { |
| 88 |
settings.titlePosition = e; |
| 89 |
this.props.edit( settings ); |
| 90 |
} } |
| 91 |
/> |
| 92 |
) } |
| 93 |
|
| 94 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'timeline' ].indexOf( type ) ) && ( |
| 95 |
<BaseControl |
| 96 |
label={ __( 'Chart Title Color' ) } |
| 97 |
> |
| 98 |
<ColorPalette |
| 99 |
value={ settings.titleTextStyle.color } |
| 100 |
onChange={ e => { |
| 101 |
settings.titleTextStyle.color = e; |
| 102 |
this.props.edit( settings ); |
| 103 |
} } |
| 104 |
/> |
| 105 |
</BaseControl> |
| 106 |
) } |
| 107 |
|
| 108 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'pie', 'timeline' ].indexOf( type ) ) && ( |
| 109 |
<SelectControl |
| 110 |
label={ __( 'Axes Titles Position' ) } |
| 111 |
help={ __( 'Determines where to place the axis titles, compared to the chart area.' ) } |
| 112 |
value={ settings.axisTitlesPosition ? settings.axisTitlesPosition : 'out' } |
| 113 |
options={ [ |
| 114 |
{ label: __( 'Inside the chart' ), value: 'in' }, |
| 115 |
{ label: __( 'Outside the chart' ), value: 'out' }, |
| 116 |
{ label: __( 'None' ), value: 'none' } |
| 117 |
] } |
| 118 |
onChange={ e => { |
| 119 |
settings.axisTitlesPosition = e; |
| 120 |
this.props.edit( settings ); |
| 121 |
} } |
| 122 |
/> |
| 123 |
) } |
| 124 |
|
| 125 |
</PanelBody> |
| 126 |
|
| 127 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'pie', 'timeline' ].indexOf( type ) ) && ( |
| 128 |
<PanelBody |
| 129 |
title={ __( 'Font Styles' ) } |
| 130 |
className="visualizer-inner-sections" |
| 131 |
initialOpen={ false } |
| 132 |
> |
| 133 |
|
| 134 |
<SelectControl |
| 135 |
label={ __( 'Font Family' ) } |
| 136 |
help={ __( 'The default font family for all text in the chart.' ) } |
| 137 |
value={ settings.fontName ? settings.fontName : 'Arial' } |
| 138 |
options={ [ |
| 139 |
{ label: __( 'Arial' ), value: 'Arial' }, |
| 140 |
{ label: __( 'Sans Serif' ), value: 'Sans Serif' }, |
| 141 |
{ label: __( 'Serif' ), value: 'serif' }, |
| 142 |
{ label: __( 'Arial' ), value: 'Arial' }, |
| 143 |
{ label: __( 'Wide' ), value: 'Arial black' }, |
| 144 |
{ label: __( 'Narrow' ), value: 'Arial Narrow' }, |
| 145 |
{ label: __( 'Comic Sans MS' ), value: 'Comic Sans MS' }, |
| 146 |
{ label: __( 'Courier New' ), value: 'Courier New' }, |
| 147 |
{ label: __( 'Garamond' ), value: 'Garamond' }, |
| 148 |
{ label: __( 'Georgia' ), value: 'Georgia' }, |
| 149 |
{ label: __( 'Tahoma' ), value: 'Tahoma' }, |
| 150 |
{ label: __( 'Verdana' ), value: 'Verdana' } |
| 151 |
] } |
| 152 |
onChange={ e => { |
| 153 |
settings.fontName = e; |
| 154 |
this.props.edit( settings ); |
| 155 |
} } |
| 156 |
/> |
| 157 |
|
| 158 |
<SelectControl |
| 159 |
label={ __( 'Font Size' ) } |
| 160 |
help={ __( 'The default font size for all text in the chart.' ) } |
| 161 |
value={ settings.fontSize ? settings.fontSize : '15' } |
| 162 |
options={ [ |
| 163 |
{ label: '7', value: '7' }, |
| 164 |
{ label: '8', value: '8' }, |
| 165 |
{ label: '9', value: '9' }, |
| 166 |
{ label: '10', value: '10' }, |
| 167 |
{ label: '11', value: '11' }, |
| 168 |
{ label: '12', value: '12' }, |
| 169 |
{ label: '13', value: '13' }, |
| 170 |
{ label: '14', value: '14' }, |
| 171 |
{ label: '15', value: '15' }, |
| 172 |
{ label: '16', value: '16' }, |
| 173 |
{ label: '17', value: '17' }, |
| 174 |
{ label: '18', value: '18' }, |
| 175 |
{ label: '19', value: '19' }, |
| 176 |
{ label: '20', value: '20' } |
| 177 |
] } |
| 178 |
onChange={ e => { |
| 179 |
settings.fontSize = e; |
| 180 |
this.props.edit( settings ); |
| 181 |
} } |
| 182 |
/> |
| 183 |
|
| 184 |
</PanelBody> |
| 185 |
) } |
| 186 |
|
| 187 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'timeline' ].indexOf( type ) ) && ( |
| 188 |
<PanelBody |
| 189 |
title={ __( 'Legend' ) } |
| 190 |
className="visualizer-inner-sections" |
| 191 |
initialOpen={ false } |
| 192 |
> |
| 193 |
|
| 194 |
<SelectControl |
| 195 |
label={ __( 'Position' ) } |
| 196 |
help={ __( 'Determines where to place the legend, compared to the chart area.' ) } |
| 197 |
value={ settings.legend.position ? settings.legend.position : 'right' } |
| 198 |
options={ positions } |
| 199 |
onChange={ e => { |
| 200 |
if ( 'pie' !== type ) { |
| 201 |
let axis = 'left' === e ? 1 : 0; |
| 202 |
|
| 203 |
Object.keys( settings.series ).map( i => { |
| 204 |
settings.series[i].targetAxisIndex = axis; |
| 205 |
}); |
| 206 |
} |
| 207 |
|
| 208 |
settings.legend.position = e; |
| 209 |
this.props.edit( settings ); |
| 210 |
} } |
| 211 |
/> |
| 212 |
|
| 213 |
<SelectControl |
| 214 |
label={ __( 'Alignment' ) } |
| 215 |
help={ __( 'Determines the alignment of the legend.' ) } |
| 216 |
value={ settings.legend.alignment ? settings.legend.alignment : '15' } |
| 217 |
options={ [ |
| 218 |
{ label: __( 'Aligned to the start of the allocated area' ), value: 'start' }, |
| 219 |
{ label: __( 'Centered in the allocated area' ), value: 'center' }, |
| 220 |
{ label: __( 'Aligned to the end of the allocated area' ), value: 'end' } |
| 221 |
] } |
| 222 |
onChange={ e => { |
| 223 |
settings.legend.alignment = e; |
| 224 |
this.props.edit( settings ); |
| 225 |
} } |
| 226 |
/> |
| 227 |
|
| 228 |
<BaseControl |
| 229 |
label={ __( 'Font Color' ) } |
| 230 |
> |
| 231 |
<ColorPalette |
| 232 |
value={ settings.legend.textStyle.color } |
| 233 |
onChange={ e => { |
| 234 |
settings.legend.textStyle.color = e; |
| 235 |
this.props.edit( settings ); |
| 236 |
} } |
| 237 |
/> |
| 238 |
</BaseControl> |
| 239 |
|
| 240 |
</PanelBody> |
| 241 |
) } |
| 242 |
|
| 243 |
{ ( -1 >= [ 'tabular', 'gauge', 'geo', 'dataTable', 'timeline' ].indexOf( type ) ) && ( |
| 244 |
<PanelBody |
| 245 |
title={ __( 'Tooltip' ) } |
| 246 |
className="visualizer-inner-sections" |
| 247 |
initialOpen={ false } |
| 248 |
> |
| 249 |
|
| 250 |
<SelectControl |
| 251 |
label={ __( 'Trigger' ) } |
| 252 |
help={ __( 'Determines the user interaction that causes the tooltip to be displayed.' ) } |
| 253 |
value={ settings.tooltip.trigger ? settings.tooltip.trigger : 'focus' } |
| 254 |
options={ tooltipTriggers } |
| 255 |
onChange={ e => { |
| 256 |
settings.tooltip.trigger = e; |
| 257 |
this.props.edit( settings ); |
| 258 |
} } |
| 259 |
/> |
| 260 |
|
| 261 |
<SelectControl |
| 262 |
label={ __( 'Show Color Code' ) } |
| 263 |
help={ __( 'If set to yes, will show colored squares next to the slice information in the tooltip.' ) } |
| 264 |
value={ settings.tooltip.showColorCode ? settings.tooltip.showColorCode : '0' } |
| 265 |
options={ [ |
| 266 |
{ label: __( 'Yes' ), value: '1' }, |
| 267 |
{ label: __( 'No' ), value: '0' } |
| 268 |
] } |
| 269 |
onChange={ e => { |
| 270 |
settings.tooltip.showColorCode = e; |
| 271 |
this.props.edit( settings ); |
| 272 |
} } |
| 273 |
/> |
| 274 |
|
| 275 |
{ ( 0 <= [ 'pie' ].indexOf( type ) ) && ( |
| 276 |
<SelectControl |
| 277 |
label={ __( 'Text' ) } |
| 278 |
help={ __( 'Determines what information to display when the user hovers over a pie slice.' ) } |
| 279 |
value={ settings.tooltip.text ? settings.tooltip.text : 'both' } |
| 280 |
options={ [ |
| 281 |
{ label: __( 'Display both the absolute value of the slice and the percentage of the whole' ), value: 'both' }, |
| 282 |
{ label: __( 'Display only the absolute value of the slice' ), value: 'value' }, |
| 283 |
{ label: __( 'Display only the percentage of the whole represented by the slice' ), value: 'percentage' } |
| 284 |
] } |
| 285 |
onChange={ e => { |
| 286 |
settings.tooltip.text = e; |
| 287 |
this.props.edit( settings ); |
| 288 |
} } |
| 289 |
/> |
| 290 |
) } |
| 291 |
|
| 292 |
</PanelBody> |
| 293 |
) } |
| 294 |
|
| 295 |
{ ( -1 >= [ 'tabular', 'dataTable', 'gauge', 'geo', 'pie', 'timeline' ].indexOf( type ) ) && ( |
| 296 |
<PanelBody |
| 297 |
title={ __( 'Animation' ) } |
| 298 |
className="visualizer-inner-sections" |
| 299 |
initialOpen={ false } |
| 300 |
> |
| 301 |
|
| 302 |
<CheckboxControl |
| 303 |
label={ __( 'Animate on startup?' ) } |
| 304 |
help={ __( 'Determines if the chart will animate on the initial draw.' ) } |
| 305 |
checked={ Number( settings.animation.startup ) } |
| 306 |
onChange={ e => { |
| 307 |
settings.animation.startup = e ? '1' : '0'; |
| 308 |
this.props.edit( settings ); |
| 309 |
} } |
| 310 |
/> |
| 311 |
|
| 312 |
<TextControl |
| 313 |
label={ __( 'Duration' ) } |
| 314 |
help={ __( 'The duration of the animation, in milliseconds.' ) } |
| 315 |
type="number" |
| 316 |
value={ settings.animation.duration } |
| 317 |
onChange={ e => { |
| 318 |
settings.animation.duration = e; |
| 319 |
this.props.edit( settings ); |
| 320 |
} } |
| 321 |
/> |
| 322 |
|
| 323 |
<SelectControl |
| 324 |
label={ __( 'Easing' ) } |
| 325 |
help={ __( 'The easing function applied to the animation.' ) } |
| 326 |
value={ settings.animation.easing ? settings.animation.easing : 'linear' } |
| 327 |
options={ [ |
| 328 |
{ label: __( 'Constant speed' ), value: 'linear' }, |
| 329 |
{ label: __( 'Start slow and speed up' ), value: 'in' }, |
| 330 |
{ label: __( 'Start fast and slow down' ), value: 'out' }, |
| 331 |
{ label: __( 'Start slow, speed up, then slow down' ), value: 'inAndOut' } |
| 332 |
] } |
| 333 |
onChange={ e => { |
| 334 |
settings.animation.easing = e; |
| 335 |
this.props.edit( settings ); |
| 336 |
} } |
| 337 |
/> |
| 338 |
|
| 339 |
</PanelBody> |
| 340 |
) } |
| 341 |
|
| 342 |
</PanelBody> |
| 343 |
); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
export default GeneralSettings; |
| 348 |
|