Skip to content

Commit 9b4624e

Browse files
authored
🤖 Merge PR DefinitelyTyped#72358 Add missing top-level methods to Plotly namespace by @ianroberts
1 parent 5eea144 commit 9b4624e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,32 @@ export function animate(
406406
opts?: Partial<AnimationOpts>,
407407
): Promise<void>;
408408

409+
export interface ValidateResult {
410+
code: string;
411+
container: "data" | "layout";
412+
trace: number | null;
413+
path: string | (string | number)[];
414+
astr: string;
415+
msg: string;
416+
}
417+
export function validate(data: Data[], layout: Partial<Layout>): ValidateResult[];
418+
export function setPlotConfig(config: Partial<Config>): void;
419+
420+
export type TemplateFigure = Root | { data: Data[]; layout: Partial<Layout> };
421+
export function makeTemplate(figure: TemplateFigure): Template;
422+
423+
export interface ValidateTemplateResult {
424+
code: string;
425+
index?: number;
426+
traceType?: string;
427+
templateCount?: number;
428+
dataCount?: number;
429+
path?: string;
430+
templateitemname?: string;
431+
msg: string;
432+
}
433+
export function validateTemplate(figure: TemplateFigure, template: Template): ValidateTemplateResult[];
434+
409435
// Layout
410436
export interface Layout {
411437
colorway: string[];

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,51 @@ function rand() {
815815
})();
816816
//////////////////////////////////////////////////////////////////////
817817

818+
//////////////////////////////////////////////////////////////////////
819+
// Plotly.validate
820+
(() => {
821+
const validateResult = Plotly.validate(data, layout);
822+
for (let res of validateResult) {
823+
console.log(res.code, res.msg);
824+
}
825+
})();
826+
//////////////////////////////////////////////////////////////////////
827+
828+
//////////////////////////////////////////////////////////////////////
829+
// Plotly.setPlotConfig
830+
(() => {
831+
Plotly.setPlotConfig({
832+
locale: "en",
833+
logging: 1,
834+
});
835+
})();
836+
//////////////////////////////////////////////////////////////////////
837+
838+
//////////////////////////////////////////////////////////////////////
839+
// Plotly.makeTemplate with div ID
840+
(() => {
841+
Plotly.makeTemplate(graphDiv);
842+
})();
843+
//////////////////////////////////////////////////////////////////////
844+
845+
//////////////////////////////////////////////////////////////////////
846+
// Plotly.makeTemplate with {data, layout}
847+
(() => {
848+
Plotly.makeTemplate({ data: data, layout: layout });
849+
})();
850+
//////////////////////////////////////////////////////////////////////
851+
852+
//////////////////////////////////////////////////////////////////////
853+
// Plotly.validateTemplate
854+
(() => {
855+
const tmpl = Plotly.makeTemplate({ data: data, layout: layout });
856+
const validateResult = Plotly.validateTemplate(graphDiv, tmpl);
857+
for (const res of validateResult) {
858+
console.log(res.code, res.msg);
859+
}
860+
})();
861+
//////////////////////////////////////////////////////////////////////
862+
818863
//////////////////////////////////////////////////////////////////////
819864
// Using events
820865
(async () => {

0 commit comments

Comments
 (0)