Skip to content

Commit 332f155

Browse files
committed
plotly.js: allow mixing predefined and custom modebar-buttons
Also test that passing both predefined button strings and custom button structs works
1 parent 7d3d2b4 commit 332f155

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

types/plotly.js/index.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ export interface ModeBar {
875875
uirevision: number | string;
876876
}
877877

878+
export type ModeBarButtonAny = ModeBarDefaultButtons | ModeBarButton;
879+
878880
export type ModeBarDefaultButtons =
879881
| 'lasso2d'
880882
| 'select2d'
@@ -1617,15 +1619,15 @@ export interface Config {
16171619
modeBarButtonsToRemove: ModeBarDefaultButtons[];
16181620

16191621
/** add mode bar button using config objects (see ./components/modebar/buttons.js for list of arguments) */
1620-
modeBarButtonsToAdd: ModeBarDefaultButtons[] | ModeBarButton[];
1622+
modeBarButtonsToAdd: ModeBarButtonAny[];
16211623

16221624
/**
16231625
* fully custom mode bar buttons as nested array, where the outer
16241626
* arrays represents button groups, and the inner arrays have
16251627
* buttons config objects or names of default buttons
16261628
* (see ./components/modebar/buttons.js for more info)
16271629
*/
1628-
modeBarButtons: Array<Array<ModeBarDefaultButtons | ModeBarButton>> | false;
1630+
modeBarButtons: ModeBarButtonAny[][] | false;
16291631

16301632
/** add the plotly logo on the end of the mode bar */
16311633
displaylogo: boolean;

types/plotly.js/test/index-tests.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,28 @@ const graphDiv = '#test';
325325
],
326326
['toImage'],
327327
],
328+
// mix strings from ModeBarDefaultButtons and custom button added as ModeBarButton interface
328329
modeBarButtonsToAdd: [
329330
'togglespikelines',
330331
'togglehover',
331332
'hovercompare',
332333
'hoverclosest',
333-
'v1hovermode'
334+
'v1hovermode',
335+
{
336+
name: 'save',
337+
title: 'Download plot data',
338+
icon: {
339+
width: 857.1,
340+
height: 1000,
341+
path:
342+
'm214-7h429v214h-429v-214z m500 0h72v500q0 8-6 21t-11 20l-157 156q-5 6-19 12t-22 5v-232q0-22-15-38t-38-16h-322q-22 0-37 16t-16 38v232h-72v-714h72v232q0 22 16 38t37 ' +
343+
'16h465q22 0 38-16t15-38v-232z m-214 518v178q0 8-5 13t-13 5h-107q-7 0-13-5t-5-13v-178q0-8 5-13t13-5h107q7 0 13 5t5 13z m357-18v-518q0-22-15-38t-38-16h-750q-23 0-38 ' +
344+
'16t-16 38v750q0 22 16 38t38 16h517q23 0 50-12t42-26l156-157q16-15 27-42t11-49z',
345+
ascent: 850,
346+
transform: 'matrix(1 0 0 -1 0 850)',
347+
},
348+
click: (gd, ev) => console.log('Download data'),
349+
}
334350
],
335351
setBackground: 'transparent',
336352
watermark: false,

0 commit comments

Comments
 (0)