Skip to content

Commit 8d6fe5d

Browse files
author
Little Mike
authored
🤖 Merge PR DefinitelyTyped#48963 [plotly.js] Update to include sunburst specific properties and sunburstclick event by @LittleMikeDev
1 parent e02af7c commit 8d6fe5d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

‎types/plotly.js/index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,30 @@ export interface SliderEndEvent {
208208
step: SliderStep;
209209
}
210210

211+
export interface SunburstClickEvent {
212+
event: MouseEvent;
213+
nextLevel: string;
214+
points: SunburstPlotDatum[];
215+
}
216+
217+
export interface SunburstPlotDatum {
218+
color: number;
219+
curveNumber: number;
220+
data: Data;
221+
entry: string;
222+
fullData: Data;
223+
hovertext: string;
224+
id: string;
225+
label: string;
226+
parent: string;
227+
percentEntry: number;
228+
percentParent: number;
229+
percentRoot: number;
230+
pointNumber: number;
231+
root: string;
232+
value: number;
233+
}
234+
211235
export interface BeforePlotEvent {
212236
data: Data[];
213237
layout: Partial<Layout>;
@@ -225,6 +249,7 @@ export interface PlotlyHTMLElement extends HTMLElement {
225249
on(event: 'plotly_sliderchange', callback: (event: SliderChangeEvent) => void): void;
226250
on(event: 'plotly_sliderend', callback: (event: SliderEndEvent) => void): void;
227251
on(event: 'plotly_sliderstart', callback: (event: SliderStartEvent) => void): void;
252+
on(event: 'plotly_sunburstclick', callback: (event: SunburstClickEvent) => void): void;
228253
on(event: 'plotly_event', callback: (data: any) => void): void;
229254
on(event: 'plotly_beforeplot', callback: (event: BeforePlotEvent) => boolean): void;
230255
on(
@@ -1244,6 +1269,8 @@ export interface PlotData {
12441269
}>;
12451270
title: Partial<DataTitle>;
12461271
branchvalues: 'total' | 'remainder';
1272+
ids: string[];
1273+
level: string;
12471274
}
12481275

12491276
/**

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,31 @@ function rand() {
723723

724724
myPlot.removeAllListeners('plotly_restyle');
725725
})();
726+
//////////////////////////////////////////////////////////////////////
727+
728+
//////////////////////////////////////////////////////////////////////
729+
// Sunburst specific properties and events
730+
(async () => {
731+
const sunburst = await newPlot(graphDiv, [
732+
{
733+
type: "sunburst",
734+
ids: ["root", "child1", "child2"],
735+
branchvalues: "total",
736+
level: "child1",
737+
parents: ["", "root", "root"],
738+
},
739+
]);
740+
741+
sunburst.on('plotly_sunburstclick', (event) => {
742+
console.log(`Clicked button ${event.event.button} to navigate to ${event.nextLevel}`);
743+
744+
const point = event.points[0];
745+
console.log(`Clicked id ${point.id} with label ${point.label} and parent label ${point.parent}`);
746+
console.log(`Point is number ${point.pointNumber} on trace ${point.curveNumber}`);
747+
console.log(`Click happened while at level *labelled* ${point.entry}, and root *labelled* ${point.root}`);
748+
console.log(`Point has value ${point.value}`);
749+
console.log(`Point takes up proportions of (previous level, parent, root): (${point.percentEntry}, ${point.percentParent}, ${point.percentRoot})`);
750+
console.log(`Colored ${point.color} and hover ${point.hovertext}`);
751+
console.log(`Can access trace data ${point.data.name} and full data ${point.fullData.name}`);
752+
});
753+
})();

0 commit comments

Comments
 (0)