Skip to content

Commit b43b29d

Browse files
authored
🤖 Merge PR DefinitelyTyped#73533 feat(plotly.js): update Font Interface by @hkleungai
1 parent 5ee273a commit b43b29d

File tree

4 files changed

+86
-39
lines changed

4 files changed

+86
-39
lines changed

types/plotly.js/index.d.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,8 @@ export interface Font {
19381938
*/
19391939
family: string;
19401940
/**
1941-
* Sets the shape and color of the shadow behind text. "auto" places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
1941+
* Sets the shape and color of the shadow behind text. "auto" places minimal shadow and applies contrast text font color.
1942+
* See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
19421943
* @default "none"
19431944
*/
19441945
shadow: string;
@@ -1950,9 +1951,9 @@ export interface Font {
19501951
/**
19511952
* Sets the weight (or boldness) of the font.
19521953
* number between or equal to 1 and 1000
1953-
* @default normal
1954+
* @default "normal"
19541955
*/
1955-
weight: number;
1956+
weight: number | "normal" | "bold";
19561957
/**
19571958
* Sets whether a font should be styled with a normal or italic face from its family.
19581959
* @default "normal"
@@ -1972,7 +1973,23 @@ export interface Font {
19721973
* Sets the kind of decoration line(s) with text, such as an "under", "over" or "through" as well as combinations e.g. "under+over".
19731974
* @default "none"
19741975
*/
1975-
lineposition: "under" | "over" | "through" | "under+over" | "under+over+through" | "none";
1976+
lineposition:
1977+
| "none"
1978+
| "under"
1979+
| "over"
1980+
| "through"
1981+
| "under+over"
1982+
| "over+under"
1983+
| "over+through"
1984+
| "through+over"
1985+
| "through+under"
1986+
| "under+through"
1987+
| "under+over+through"
1988+
| "under+through+over"
1989+
| "over+under+through"
1990+
| "over+through+under"
1991+
| "through+under+over"
1992+
| "through+over+under";
19761993
}
19771994

19781995
export interface Edits {
@@ -2900,7 +2917,7 @@ export interface Slider {
29002917
/**
29012918
* Sets the font of the slider step labels.
29022919
*/
2903-
font: Font;
2920+
font: Partial<Font>;
29042921
/**
29052922
* Sets the background color of the slider grip
29062923
* while dragging.

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import * as Plotly from "plotly.js";
2-
import { Config, Datum, Layout, newPlot, PlotData, Template, XAxisName, YAxisName } from "plotly.js";
2+
import { Config, Datum, Font, Layout, newPlot, PlotData, Template, XAxisName, YAxisName } from "plotly.js";
33

44
const graphDiv = "#test";
55

6+
const font: Font = {
7+
color: "#fff",
8+
family: "Arial, sans-serif",
9+
lineposition: "under",
10+
shadow: "auto",
11+
size: 15,
12+
style: "italic",
13+
textcase: "word caps",
14+
variant: "all-petite-caps",
15+
weight: "bold",
16+
};
17+
618
const config: Partial<Config> = {
719
staticPlot: false,
820
typesetMath: true,
@@ -407,15 +419,15 @@ const config: Partial<Config> = {
407419
bgcolor: "#ffffff",
408420
bordercolor: "#444444",
409421
borderwidth: 1,
410-
font: { size: 15, style: "italic" },
422+
font,
411423
groupclick: "togglegroup",
412-
grouptitlefont: { size: 15 },
424+
grouptitlefont: font,
413425
itemclick: "toggleothers",
414426
itemdoubleclick: "toggle",
415427
itemsizing: "constant",
416428
itemwidth: 50,
417429
orientation: "h",
418-
title: { font: { size: 15 }, side: "top right", text: "Legend Title" },
430+
title: { font, side: "top right", text: "Legend Title" },
419431
tracegroupgap: 15,
420432
traceorder: "reversed+grouped",
421433
valign: "bottom",
@@ -498,7 +510,7 @@ const config: Partial<Config> = {
498510
colorbar: {
499511
title: {
500512
text: "Test",
501-
font: { size: 20, color: "#666", textcase: "lower" },
513+
font,
502514
side: "top",
503515
},
504516
orientation: "v",
@@ -534,7 +546,7 @@ const config: Partial<Config> = {
534546
ticklabelstep: 1,
535547
showticklabels: true,
536548
labelalias: "labelalias",
537-
tickfont: { size: 10, color: "#666" },
549+
tickfont: font,
538550
tickangle: "auto",
539551
tickformat: "",
540552
tickformatstops: [],
@@ -574,7 +586,7 @@ const config: Partial<Config> = {
574586
visible: true,
575587
prefix: "Date:",
576588
xanchor: "right",
577-
font: { size: 20, color: "#666", variant: "all-small-caps" },
589+
font,
578590
},
579591
steps: [
580592
{
@@ -724,10 +736,7 @@ const config: Partial<Config> = {
724736
const update = {
725737
title: {
726738
text: "some new title",
727-
font: {
728-
size: 1.2,
729-
lineposition: "through",
730-
},
739+
font,
731740
x: 0.9,
732741
pad: {
733742
t: 20,
@@ -1147,10 +1156,7 @@ function rand() {
11471156
type: "contour",
11481157
contours: {
11491158
coloring: "lines",
1150-
labelfont: {
1151-
color: "black",
1152-
family: "monospace",
1153-
},
1159+
labelfont: font,
11541160
showlabels: true,
11551161
},
11561162
autocontour: true,

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ export interface Font {
19881988
*/
19891989
family: string;
19901990
/**
1991-
* Sets the shape and color of the shadow behind text. "auto" places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
1991+
* Sets the shape and color of the shadow behind text. "auto" places minimal shadow and applies contrast text font color.
1992+
* See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
19921993
* @default "none"
19931994
*/
19941995
shadow: string;
@@ -2000,9 +2001,9 @@ export interface Font {
20002001
/**
20012002
* Sets the weight (or boldness) of the font.
20022003
* number between or equal to 1 and 1000
2003-
* @default normal
2004+
* @default "normal"
20042005
*/
2005-
weight: number;
2006+
weight: number | "normal" | "bold";
20062007
/**
20072008
* Sets whether a font should be styled with a normal or italic face from its family.
20082009
* @default "normal"
@@ -2022,7 +2023,23 @@ export interface Font {
20222023
* Sets the kind of decoration line(s) with text, such as an "under", "over" or "through" as well as combinations e.g. "under+over".
20232024
* @default "none"
20242025
*/
2025-
lineposition: "under" | "over" | "through" | "under+over" | "under+over+through" | "none";
2026+
lineposition:
2027+
| "none"
2028+
| "under"
2029+
| "over"
2030+
| "through"
2031+
| "under+over"
2032+
| "over+under"
2033+
| "over+through"
2034+
| "through+over"
2035+
| "through+under"
2036+
| "under+through"
2037+
| "under+over+through"
2038+
| "under+through+over"
2039+
| "over+under+through"
2040+
| "over+through+under"
2041+
| "through+under+over"
2042+
| "through+over+under";
20262043
}
20272044

20282045
export interface Edits {
@@ -2950,7 +2967,7 @@ export interface Slider {
29502967
/**
29512968
* Sets the font of the slider step labels.
29522969
*/
2953-
font: Font;
2970+
font: Partial<Font>;
29542971
/**
29552972
* Sets the background color of the slider grip
29562973
* while dragging.

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import * as Plotly from "plotly.js";
2-
import { Config, Datum, Layout, newPlot, PlotData, Template, XAxisName, YAxisName } from "plotly.js";
2+
import { Config, Datum, Font, Layout, newPlot, PlotData, Template, XAxisName, YAxisName } from "plotly.js";
33

44
const graphDiv = "#test";
55

6+
const font: Font = {
7+
color: "#fff",
8+
family: "Arial, sans-serif",
9+
lineposition: "under",
10+
shadow: "auto",
11+
size: 15,
12+
style: "italic",
13+
textcase: "word caps",
14+
variant: "all-petite-caps",
15+
weight: "bold",
16+
};
17+
618
const config: Partial<Config> = {
719
staticPlot: false,
820
typesetMath: true,
@@ -428,15 +440,15 @@ const config: Partial<Config> = {
428440
bgcolor: "#ffffff",
429441
bordercolor: "#444444",
430442
borderwidth: 1,
431-
font: { size: 15, style: "italic" },
443+
font,
432444
groupclick: "togglegroup",
433-
grouptitlefont: { size: 15 },
445+
grouptitlefont: font,
434446
itemclick: "toggleothers",
435447
itemdoubleclick: "toggle",
436448
itemsizing: "constant",
437449
itemwidth: 50,
438450
orientation: "h",
439-
title: { font: { size: 15 }, side: "top right", text: "Legend Title" },
451+
title: { font, side: "top right", text: "Legend Title" },
440452
tracegroupgap: 15,
441453
traceorder: "reversed+grouped",
442454
valign: "bottom",
@@ -511,7 +523,7 @@ const config: Partial<Config> = {
511523
colorbar: {
512524
title: {
513525
text: "Test",
514-
font: { size: 20, color: "#666", textcase: "lower" },
526+
font,
515527
side: "top",
516528
},
517529
orientation: "v",
@@ -547,7 +559,7 @@ const config: Partial<Config> = {
547559
ticklabelstep: 1,
548560
showticklabels: true,
549561
labelalias: "labelalias",
550-
tickfont: { size: 10, color: "#666" },
562+
tickfont: font,
551563
tickangle: "auto",
552564
tickformat: "",
553565
tickformatstops: [],
@@ -585,7 +597,7 @@ const config: Partial<Config> = {
585597
visible: true,
586598
prefix: "Date:",
587599
xanchor: "right",
588-
font: { size: 20, color: "#666", lineposition: "through" },
600+
font,
589601
},
590602
steps: [
591603
{
@@ -731,9 +743,7 @@ const config: Partial<Config> = {
731743
const update = {
732744
title: {
733745
text: "some new title",
734-
font: {
735-
size: 1.2,
736-
},
746+
font,
737747
x: 0.9,
738748
pad: {
739749
t: 20,
@@ -1151,10 +1161,7 @@ function rand() {
11511161
type: "contour",
11521162
contours: {
11531163
coloring: "lines",
1154-
labelfont: {
1155-
color: "black",
1156-
family: "monospace",
1157-
},
1164+
labelfont: font,
11581165
showlabels: true,
11591166
},
11601167
autocontour: true,

0 commit comments

Comments
 (0)