Skip to content

Commit 4843e40

Browse files
committed
replace trend by secondary, color variables that default to a subset of observable10
1 parent 3dabcf6 commit 4843e40

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/client/stdlib/dash/bigNumber.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,48 @@ export function BigNumber(
88
target = "_blank",
99
title,
1010
format = ",.2~f",
11-
trend,
12-
trendFormat = "+.1~%",
13-
trendColor = trend == null ? "" : trend > 0 ? "green" : trend < 0 ? "red" : "orange",
14-
trendArrow = trend == null ? "" : trend > 0 ? "↗︎" : trend < 0 ? "↘︎" : "→",
15-
trendTitle,
16-
plot
11+
secondary,
12+
secondaryFormat = format,
13+
secondaryColor = secondary == null
14+
? ""
15+
: secondary > 0
16+
? "var(--theme-color-positive)"
17+
: secondary < 0
18+
? "var(--theme-color-negative)"
19+
: "var(--theme-color-neutral)",
20+
secondaryArrow = secondary == null ? "" : secondary > 0 ? "↗︎" : secondary < 0 ? "↘︎" : "→",
21+
secondaryTitle,
22+
styles = {display: "flex", flexDirection: "column", fontFamily: "var(--sans-serif)"},
23+
children
1724
}: {
1825
href?: string;
1926
target?: string;
2027
title?: string;
2128
format?: string | ((x: any) => string);
22-
trend?: number;
23-
trendFormat?: string | ((x: any) => string);
24-
trendColor?: string;
25-
trendArrow?: string;
26-
trendTitle?: string;
27-
plot?: Node;
29+
secondary?: number;
30+
secondaryFormat?: string | ((x: any) => string);
31+
secondaryColor?: string;
32+
secondaryArrow?: string;
33+
secondaryTitle?: string;
34+
styles?: {[key: string]: string};
35+
children?: Node | Iterable<Node>;
2836
} = {}
2937
) {
3038
if (typeof format !== "function") format = typeof number === "string" ? String : d3.format(format);
31-
if (typeof trendFormat !== "function") trendFormat = d3.format(trendFormat);
32-
const div = html`<div style="display: flex; flex-direction: column; font-family: var(--sans-serif);">
39+
if (typeof secondaryFormat !== "function") secondaryFormat = d3.format(secondaryFormat);
40+
const div = html`<div style="${styles}">
3341
<div style="text-transform: uppercase; font-size: 12px;">${title}</div>
3442
<div style="display: flex; flex-wrap: wrap; column-gap: 10px; align-items: baseline;">
3543
<div style="font-size: 32px; font-weight: bold; line-height: 1;">${(format as (x: any) => string)(number)}</div>
3644
${
37-
trend == null
45+
secondary == null
3846
? null
39-
: html`<div style="font-size: 14px; color: ${trendColor};" ${{title: trendTitle}}>${(
40-
trendFormat as (x: any) => string
41-
)(trend)} ${trendArrow}</div>`
47+
: html`<div style="font-size: 14px; color: ${secondaryColor};" ${{title: secondaryTitle}}>${(
48+
secondaryFormat as (x: any) => string
49+
)(secondary)} ${secondaryArrow}</div>`
4250
}
4351
</div>
44-
${plot}
52+
${children}
4553
</div>`;
4654
return href == null ? div : html`<a href=${href} target=${target} style="color: inherit;">${div}</a>`;
4755
}

src/style/theme-dark.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
--theme-foreground-fainter: color-mix(in srgb, var(--theme-foreground) 30%, var(--theme-background));
1111
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
1212
--theme-foreground-focus: oklch(0.712564 0.257662 265.758);
13+
--theme-color-positive: #3ca951; /* green */
14+
--theme-color-negative: #ff725c; /* red */
15+
--theme-color-neutral: #efb118; /* orange/yellow */
1316
color-scheme: dark;
1417
}

src/style/theme-light.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
--theme-foreground-fainter: color-mix(in srgb, var(--theme-foreground) 30%, var(--theme-background));
1111
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
1212
--theme-foreground-focus: #3b5fc0;
13+
--theme-color-positive: #3ca951; /* green */
14+
--theme-color-negative: #ff725c; /* red */
15+
--theme-color-neutral: #efb118; /* orange/yellow */
1316
color-scheme: light;
1417
}

0 commit comments

Comments
 (0)