@@ -21,6 +21,7 @@ import { useEnterEscape } from '../../../public/useEnterEscape';
2121import { ChartLabelInput } from './ChartLabelInput' ;
2222import { ChartColorInputs } from './ChartColorInputs' ;
2323import { Alert } from '../base/Alert' ;
24+ import { RadioGroupInput } from '../forms/input/RadioGroupInput' ;
2425
2526function changedIntValue ( strVal : string , currentVal : number ) : [ value : number , changed : boolean ] {
2627 strVal = strVal . trim ( ) ;
@@ -279,6 +280,7 @@ export const ChartSettingsPanel: FC<Props> = memo(props => {
279280 setChartConfig,
280281 setChartModel,
281282 } = props ;
283+ const legendPos = chartConfig . legendPos ;
282284 const showTrendline = hasTrendline ( chartType ) ;
283285 const fields = chartType . fields . filter ( f => f . name !== 'trendline' ) ;
284286
@@ -326,6 +328,20 @@ export const ChartSettingsPanel: FC<Props> = memo(props => {
326328 [ setChartConfig ]
327329 ) ;
328330
331+ const legendOptions = useMemo ( ( ) => {
332+ return [
333+ { label : 'Right' , selected : ! legendPos || legendPos === 'right' , value : 'right' } ,
334+ { label : 'Bottom' , selected : legendPos === 'bottom' , value : 'bottom' } ,
335+ ] ;
336+ } , [ legendPos ] ) ;
337+
338+ const onLegendPosChange = useCallback (
339+ value => setChartConfig ( current => ( { ...current , legendPos : value } ) ) ,
340+ [ setChartConfig ]
341+ ) ;
342+
343+ const showLegendPos = chartType . name !== 'pie_chart' ;
344+
329345 return (
330346 < div className = "chart-settings" >
331347 { error && < Alert > { error } </ Alert > }
@@ -392,6 +408,22 @@ export const ChartSettingsPanel: FC<Props> = memo(props => {
392408 value = { chartConfig ?. labels ?. subtitle }
393409 />
394410 < SizeInputs height = { chartConfig . height } setChartConfig = { setChartConfig } width = { chartConfig . width } />
411+
412+ { showLegendPos && (
413+ < div className = "chart-settings__legend-pos" >
414+ < label > Legend Position</ label >
415+
416+ < div className = "chart-settings__legend-pos-values" >
417+ < RadioGroupInput
418+ formsy = { false }
419+ name = "legendPos"
420+ onValueChange = { onLegendPosChange }
421+ options = { legendOptions }
422+ />
423+ </ div >
424+ </ div >
425+ ) }
426+
395427 < ChartColorInputs chartConfig = { chartConfig } model = { model } setChartConfig = { setChartConfig } />
396428 </ div >
397429 ) ;
0 commit comments