@@ -29,6 +29,7 @@ import {
2929 EuiHorizontalRule ,
3030 EuiTitle ,
3131} from '@elastic/eui' ;
32+ import { EuiFieldNumber } from '@elastic/eui' ;
3233import {
3334 VisualizationLayerWidgetProps ,
3435 VisualizationDimensionEditorProps ,
@@ -83,6 +84,27 @@ const legendOptions: Array<{ id: string; value: 'auto' | 'show' | 'hide'; label:
8384 } ,
8485] ;
8586
87+ const valueLabelsPositioningOptions : Array < {
88+ id : string ;
89+ value : 'inside' | 'outside' ;
90+ label : string ;
91+ } > = [
92+ {
93+ id : 'xy_valueLabels_inside' ,
94+ value : 'inside' ,
95+ label : i18n . translate ( 'xpack.lens.xyChart.valueLabels.labelsPositioning.inside' , {
96+ defaultMessage : 'inside' ,
97+ } ) ,
98+ } ,
99+ {
100+ id : 'xy_valueLabels_outside' ,
101+ value : 'outside' ,
102+ label : i18n . translate ( 'xpack.lens.xyChart.valueLabels.labelsPositioning.outside' , {
103+ defaultMessage : 'outside' ,
104+ } ) ,
105+ } ,
106+ ] ;
107+
86108export function LayerContextMenu ( props : VisualizationLayerWidgetProps < State > ) {
87109 const { state, layerId } = props ;
88110 const horizontalOnly = isHorizontalChart ( state . layers ) ;
@@ -235,6 +257,20 @@ export function XyToolbar(props: VisualizationToolbarProps<State>) {
235257 } ) ;
236258 } ;
237259
260+ const onValueDisplayVisibilitySettingsChange = ( enabled : boolean ) : void => {
261+ setState ( {
262+ ...state ,
263+ displayValues : {
264+ ...state . displayValues ,
265+ showLabels : enabled ,
266+ } ,
267+ } ) ;
268+ } ;
269+
270+ const shouldEnableValueLabels = state ?. layers . some ( ( layer ) => layer . seriesType . includes ( 'bar' ) ) ;
271+ const showValueLabels = Boolean ( shouldEnableValueLabels && state ?. displayValues ?. showLabels ) ;
272+ const valueLabelsPositioning = state ?. displayValues ?. position || 'inside' ;
273+
238274 const legendMode =
239275 state ?. legend . isVisible && ! state ?. legend . showSingleSeries
240276 ? 'auto'
@@ -365,6 +401,80 @@ export function XyToolbar(props: VisualizationToolbarProps<State>) {
365401 />
366402 </ EuiFormRow >
367403 < EuiHorizontalRule margin = "s" />
404+ < EuiFormRow
405+ display = "columnCompressedSwitch"
406+ fullWidth
407+ label = { i18n . translate ( 'xpack.lens.xyChart.valueLabels.showlabels.label' , {
408+ defaultMessage : 'Value Labels Display' ,
409+ } ) }
410+ >
411+ < EuiSwitch
412+ data-test-subj = "lnsshowShowValueLabelsSwitch"
413+ showLabel = { false }
414+ label = { i18n . translate ( 'xpack.lens.xyChart.valueLabels.showlabels' , {
415+ defaultMessage : 'Value Labels Display' ,
416+ } ) }
417+ onChange = { ( { target } ) => onValueDisplayVisibilitySettingsChange ( target . checked ) }
418+ checked = { showValueLabels }
419+ disabled = { ! shouldEnableValueLabels }
420+ />
421+ </ EuiFormRow >
422+ < EuiFormRow
423+ display = "columnCompressed"
424+ fullWidth
425+ label = { i18n . translate ( 'xpack.lens.xyChart.valueLabels.labelsFontSize.label' , {
426+ defaultMessage : 'Value Labels size' ,
427+ } ) }
428+ >
429+ < EuiFieldNumber
430+ value = { state ?. displayValues ?. fontSize || 10 }
431+ onChange = { ( { target } ) =>
432+ setState ( {
433+ ...state ,
434+ displayValues : {
435+ ...state . displayValues ,
436+ showLabels : true ,
437+ fontSize : Number ( target . value ) ,
438+ } ,
439+ } )
440+ }
441+ disabled = { ! shouldEnableValueLabels }
442+ />
443+ </ EuiFormRow >
444+ < EuiFormRow
445+ display = "columnCompressed"
446+ label = { i18n . translate ( 'xpack.lens.xyChart.valueLabels.labelsPositioning.label' , {
447+ defaultMessage : 'Value labels position' ,
448+ } ) }
449+ >
450+ < EuiButtonGroup
451+ isFullWidth
452+ legend = { i18n . translate ( 'xpack.lens.xyChart.legendVisibilityLabel' , {
453+ defaultMessage : 'Value labels position' ,
454+ } ) }
455+ name = "valueLabelsPositioning"
456+ buttonSize = "compressed"
457+ options = { valueLabelsPositioningOptions }
458+ idSelected = {
459+ valueLabelsPositioningOptions . find ( ( { value } ) => value === valueLabelsPositioning ) !
460+ . id
461+ }
462+ isDisabled = { ! shouldEnableValueLabels || ! showValueLabels }
463+ onChange = { ( optionId ) => {
464+ const newMode = valueLabelsPositioningOptions . find ( ( { id } ) => id === optionId ) !
465+ . value ;
466+ setState ( {
467+ ...state ,
468+ displayValues : {
469+ ...state . displayValues ,
470+ showLabels : true ,
471+ position : newMode ,
472+ } ,
473+ } ) ;
474+ } }
475+ />
476+ </ EuiFormRow >
477+ < EuiHorizontalRule margin = "s" />
368478 < EuiFormRow
369479 display = "columnCompressed"
370480 label = { i18n . translate ( 'xpack.lens.xyChart.TickLabels' , {
@@ -488,11 +598,10 @@ const idPrefix = htmlIdGenerator()();
488598
489599export function DimensionEditor ( props : VisualizationDimensionEditorProps < State > ) {
490600 const { state, setState, layerId, accessor } = props ;
491- const horizontalOnly = isHorizontalChart ( state . layers ) ;
492- const chartHasMoreThanOneSeries =
493- state . layers . length > 1 ||
494- state . layers . some ( ( { accessors } ) => accessors . length > 1 ) ||
495- state . layers . some ( ( { splitAccessor } ) => splitAccessor ) ;
601+ // const horizontalOnly = isHorizontalChart(state.layers);
602+ // const chartHasMoreThanOneSeries =
603+ // state.layers.length > 1 || state.layers.some(({ splitAccessor }) => splitAccessor);
604+ const shouldEnableValueLabels = state ?. layers . some ( ( layer ) => layer . seriesType . includes ( 'bar' ) ) ;
496605
497606 const index = state . layers . findIndex ( ( l ) => l . layerId === layerId ) ;
498607 const layer = state . layers [ index ] ;
@@ -501,9 +610,8 @@ export function DimensionEditor(props: VisualizationDimensionEditorProps<State>)
501610 forAccessor : accessor ,
502611 } ;
503612 const axisMode = layerConfig ?. axisMode || 'auto' ;
504- const shouldShowValueLabels = horizontalOnly && ! chartHasMoreThanOneSeries ;
505613
506- const showValueLabels = ( shouldShowValueLabels && layerConfig ?. showValueLabels ) ?? false ;
614+ const showValueLabels = ( shouldEnableValueLabels && layerConfig ?. showValueLabels ) ?? false ;
507615
508616 const createNewYAxisConfigsWithValue = useCallback (
509617 < K extends keyof YConfig , V extends YConfig [ K ] > ( prop : K , newValue : V ) => {
@@ -570,31 +678,30 @@ export function DimensionEditor(props: VisualizationDimensionEditorProps<State>)
570678 } }
571679 />
572680 </ EuiFormRow >
573- { shouldShowValueLabels && (
574- < EuiFormRow
575- display = "columnCompressedSwitch"
576- fullWidth
681+ < EuiFormRow
682+ display = "columnCompressedSwitch"
683+ fullWidth
684+ label = { i18n . translate ( 'xpack.lens.xyChart.showValueLabels.label' , {
685+ defaultMessage : 'Show Value Labels' ,
686+ } ) }
687+ >
688+ < EuiSwitch
689+ data-test-subj = "lnsshowShowValueLabelsSwitch"
690+ showLabel = { false }
577691 label = { i18n . translate ( 'xpack.lens.xyChart.showValueLabels.label' , {
578692 defaultMessage : 'Show Value Labels' ,
579693 } ) }
580- >
581- < EuiSwitch
582- data-test-subj = "lnsshowShowValueLabelsSwitch"
583- showLabel = { false }
584- label = { i18n . translate ( 'xpack.lens.xyChart.showValueLabels.label' , {
585- defaultMessage : 'Show Value Labels' ,
586- } ) }
587- onChange = { ( { target } ) => {
588- const newYAxisConfigs = createNewYAxisConfigsWithValue (
589- 'showValueLabels' ,
590- target . checked
591- ) ;
592- setState ( updateLayer ( state , { ...layer , yConfig : newYAxisConfigs } , index ) ) ;
593- } }
594- checked = { showValueLabels }
595- />
596- </ EuiFormRow >
597- ) }
694+ onChange = { ( { target } ) => {
695+ const newYAxisConfigs = createNewYAxisConfigsWithValue (
696+ 'showValueLabels' ,
697+ target . checked
698+ ) ;
699+ setState ( updateLayer ( state , { ...layer , yConfig : newYAxisConfigs } , index ) ) ;
700+ } }
701+ checked = { showValueLabels }
702+ disabled = { ! shouldEnableValueLabels }
703+ />
704+ </ EuiFormRow >
598705 </ EuiForm >
599706 ) ;
600707}
0 commit comments