Skip to content

Commit a6d652b

Browse files
authored
Merge pull request #666 from plotly/hoveron-options
correct hoveron options for each trace type
2 parents 5cdcb2d + 0df8907 commit a6d652b

File tree

6 files changed

+78
-68
lines changed

6 files changed

+78
-68
lines changed

dev/percy/panelTest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"shape": "spline",
8181
"color": "rgb(31, 119, 180)"
8282
},
83-
"hoveron": "fills+points",
83+
"hoveron": "points+fills",
8484
"uid": "3102ee"
8585
},
8686
{
@@ -145,7 +145,7 @@
145145
"shape": "spline",
146146
"color": "rgb(31, 119, 180)"
147147
},
148-
"hoveron": "fills+points",
148+
"hoveron": "points+fills",
149149
"uid": "f4d7ad"
150150
}
151151
],

src/components/fields/derived.js

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,12 @@ export const HoverInfo = connectToContainer(UnconnectedFlaglist, {
539539
].includes(container.type)
540540
) {
541541
options.push({label: _('Z'), value: 'z'});
542-
}
543-
544-
if (container.type === 'choropleth') {
542+
} else if (container.type === 'choropleth') {
545543
options = [
546544
{label: _('Location'), value: 'location'},
547545
{label: _('Values'), value: 'z'},
548546
];
549-
}
550-
551-
if (container.type === 'scattergeo') {
547+
} else if (container.type === 'scattergeo') {
552548
if (container.locations) {
553549
options = [{label: _('Location'), value: 'location'}];
554550
} else if (container.lat || container.lon) {
@@ -557,40 +553,30 @@ export const HoverInfo = connectToContainer(UnconnectedFlaglist, {
557553
{label: _('Latitude'), value: 'lat'},
558554
];
559555
}
560-
}
561-
562-
if (container.type === 'scattermapbox') {
556+
} else if (container.type === 'scattermapbox') {
563557
options = [
564558
{label: _('Longitude'), value: 'loc'},
565559
{label: _('Latitude'), value: 'lat'},
566560
];
567-
}
568-
569-
if (container.type === 'scatterternary') {
561+
} else if (container.type === 'scatterternary') {
570562
options = [
571563
{label: _('A'), value: 'a'},
572564
{label: _('B'), value: 'b'},
573565
{label: _('C'), value: 'c'},
574566
];
575-
}
576-
577-
if (container.type === 'table') {
578-
plotProps.isVisible = false;
579-
}
580-
581-
if (['scatterpolar', 'scatterpolargl'].includes(container.type)) {
567+
} else if (['scatterpolar', 'scatterpolargl'].includes(container.type)) {
582568
options = [
583569
{label: _('R'), value: 'r'},
584570
{label: _('Theta'), value: 'theta'},
585571
];
586-
}
587-
588-
if (container.type === 'pie') {
572+
} else if (container.type === 'pie') {
589573
options = [
590574
{label: _('Label'), value: 'label'},
591575
{label: _('Value'), value: 'value'},
592576
{label: _('Percent'), value: 'percent'},
593577
];
578+
} else if (container.type === 'table') {
579+
plotProps.isVisible = false;
594580
}
595581

596582
if (container.text) {
@@ -625,9 +611,7 @@ export const FillDropdown = connectToContainer(UnconnectedDropdown, {
625611
{label: _('To Self'), value: 'toself'},
626612
{label: _('To Next'), value: 'tonext'},
627613
];
628-
}
629-
630-
if (
614+
} else if (
631615
context.container.type === 'scattergeo' ||
632616
context.container.type === 'scattermapbox'
633617
) {
@@ -641,3 +625,55 @@ export const FillDropdown = connectToContainer(UnconnectedDropdown, {
641625
plotProps.clearable = false;
642626
},
643627
});
628+
629+
export const HoveronDropdown = connectToContainer(UnconnectedDropdown, {
630+
modifyPlotProps: (props, context, plotProps) => {
631+
const {localize: _} = context;
632+
633+
let options;
634+
if (context.container.type === 'box') {
635+
options = [
636+
{label: _('Boxes'), value: 'boxes'},
637+
{label: _('Points'), value: 'points'},
638+
{label: _('Boxes and Points'), value: 'boxes+points'},
639+
];
640+
} else if (context.container.type === 'violin') {
641+
options = [
642+
{label: _('Violins'), value: 'violins'},
643+
{label: _('Points'), value: 'points'},
644+
{label: _('KDE'), value: 'kde'},
645+
{label: _('Violins and Points'), value: 'violins+points'},
646+
{label: _('Violins, Points and KDE'), value: 'violins+points+kde'},
647+
];
648+
} else {
649+
options = [
650+
{label: _('Points'), value: 'points'},
651+
{label: _('Fills'), value: 'fills'},
652+
{label: _('Points and Fills'), value: 'points+fills'},
653+
];
654+
}
655+
656+
plotProps.options = options;
657+
plotProps.clearable = false;
658+
},
659+
});
660+
661+
export const HovermodeDropdown = connectToContainer(UnconnectedDropdown, {
662+
modifyPlotProps: (props, context, plotProps) => {
663+
const {localize: _} = context;
664+
665+
plotProps.options =
666+
context.container.xaxis && Object.keys(context.container.xaxis).length > 0
667+
? [
668+
{label: _('Closest'), value: 'closest'},
669+
{label: _('X Axis'), value: 'x'},
670+
{label: _('Y Axis'), value: 'y'},
671+
{label: _('Disable'), value: false},
672+
]
673+
: [
674+
{label: _('Closest'), value: 'closest'},
675+
{label: _('Disable'), value: false},
676+
];
677+
plotProps.clearable = false;
678+
},
679+
});

src/components/fields/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import {
4848
AxisSide,
4949
TextPosition,
5050
ShowInLegend,
51+
HoveronDropdown,
52+
HovermodeDropdown,
5153
} from './derived';
5254
import {LineDashSelector, LineShapeSelector} from './LineSelectors';
5355

@@ -104,4 +106,6 @@ export {
104106
VisibilitySelect,
105107
RectanglePositioner,
106108
LocationSelector,
109+
HoveronDropdown,
110+
HovermodeDropdown,
107111
};

src/components/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
VisibilitySelect,
5151
RectanglePositioner,
5252
LocationSelector,
53+
HoveronDropdown,
54+
HovermodeDropdown,
5355
} from './fields';
5456

5557
import {
@@ -157,4 +159,6 @@ export {
157159
VisibilitySelect,
158160
RectanglePositioner,
159161
LocationSelector,
162+
HoveronDropdown,
163+
HovermodeDropdown,
160164
};

src/default_panels/StyleLayoutPanel.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PlotlySection,
1111
TraceRequiredPanel,
1212
VisibilitySelect,
13+
HovermodeDropdown,
1314
} from '../components';
1415

1516
const StyleLayoutPanel = (props, {localize: _}) => (
@@ -31,17 +32,7 @@ const StyleLayoutPanel = (props, {localize: _}) => (
3132
<ColorPicker label={_('Plot Background')} attr="plot_bgcolor" />
3233
<ColorPicker label={_('Plot Background')} attr="polar.bgcolor" />
3334
<ColorPicker label={_('Margin Color')} attr="paper_bgcolor" />
34-
<Dropdown
35-
label={_('Hover Interaction')}
36-
attr="hovermode"
37-
options={[
38-
{label: _('Closest'), value: 'closest'},
39-
{label: _('X Axis'), value: 'x'},
40-
{label: _('Y Axis'), value: 'y'},
41-
{label: _('Disable'), value: false},
42-
]}
43-
clearable={false}
44-
/>
35+
<HovermodeDropdown label={_('Hover Interaction')} attr="hovermode" />
4536
<Dropdown
4637
label={_('Drag Interaction')}
4738
attr="dragmode"

src/default_panels/StyleTracesPanel.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
NumericReciprocal,
3737
ShowInLegend,
3838
TextInfo,
39+
HoveronDropdown,
3940
} from '../components/fields/derived';
4041

4142
const StyleTracesPanel = (props, {localize: _}) => (
@@ -584,36 +585,10 @@ const StyleTracesPanel = (props, {localize: _}) => (
584585
<Numeric label={_('Contour Width')} attr="contour.width" />
585586
</VisibilitySelect>
586587
</PlotlySection>
587-
<TraceTypeSection name={_('Hover Action')} traceTypes={['box']}>
588-
<Flaglist
589-
attr="hoveron"
590-
label={_('Hover on')}
591-
options={[
592-
{label: _('Boxes'), value: 'boxes'},
593-
{label: _('Points'), value: 'points'},
594-
]}
595-
/>
596-
</TraceTypeSection>
597-
<TraceTypeSection
598-
name={_('Hover Action')}
599-
traceTypes={[
600-
'scatter',
601-
'scatterternary',
602-
'scatterpolar',
603-
'scatterpolargl',
604-
]}
605-
>
606-
<Dropdown
607-
attr="hoveron"
608-
label={_('Hover on')}
609-
options={[
610-
{label: _('Fills'), value: 'fills'},
611-
{label: _('Points'), value: 'points'},
612-
{label: _('Fills & Points'), value: 'fills+points'},
613-
]}
614-
clearable={false}
615-
/>
616-
</TraceTypeSection>
588+
589+
<PlotlySection name={_('Hover Action')}>
590+
<HoveronDropdown attr="hoveron" label={_('Hover on')} />
591+
</PlotlySection>
617592

618593
<TraceTypeSection
619594
name={_('Error Bars X')}

0 commit comments

Comments
 (0)