File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1
1
export * from "./dash/resize.js" ;
2
+ export * from "./dash/bigNumber.js" ;
Original file line number Diff line number Diff line change
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts -ignore
3
+ import * as d3 from "npm:d3" ;
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts -ignore
6
+ import { html } from "npm:htl" ;
7
+
8
+ export function BigNumber (
9
+ number ,
10
+ {
11
+ href,
12
+ target = "_blank" ,
13
+ title,
14
+ format = ",.2~f" ,
15
+ trend,
16
+ trendFormat = "+.1~%" ,
17
+ trendColor = trend == null ? "" : trend > 0 ? "green" : trend < 0 ? "red" : "orange" ,
18
+ trendArrow = trend == null ? "" : trend > 0 ? "↗︎" : trend < 0 ? "↘︎" : "→" ,
19
+ trendTitle,
20
+ plot
21
+ } : {
22
+ href ?: string ;
23
+ target ?: string ;
24
+ title ?: string ;
25
+ format ?: string | ( ( x : any ) => string ) ;
26
+ trend ?: number ;
27
+ trendFormat ?: string | ( ( x : any ) => string ) ;
28
+ trendColor ?: string ;
29
+ trendArrow ?: string ;
30
+ trendTitle ?: string ;
31
+ plot ?: Node ;
32
+ } = { }
33
+ ) {
34
+ if ( typeof format !== "function" ) format = typeof number === "string" ? String : d3 . format ( format ) ;
35
+ if ( typeof trendFormat !== "function" ) trendFormat = d3 . format ( trendFormat ) ;
36
+ const div = html `< div style ="display: flex; flex-direction: column; font-family: var(--sans-serif); ">
37
+ < div style ="text-transform: uppercase; font-size: 12px; "> ${ title } </ div >
38
+ < div style ="display: flex; flex-wrap: wrap; column-gap: 10px; align-items: baseline; ">
39
+ < div style ="font-size: 32px; font-weight: bold; line-height: 1; "> ${ ( format as ( x : any ) => string ) ( number ) } </ div >
40
+ ${
41
+ trend == null
42
+ ? null
43
+ : html `< div style ="font-size: 14px; color: ${ trendColor } ; " ${ { title : trendTitle } } > ${ (
44
+ trendFormat as ( x : any ) => string
45
+ ) ( trend ) } ${ trendArrow } </ div > `
46
+ }
47
+ </ div >
48
+ ${ plot }
49
+ </ div > ` ;
50
+ return href == null ? div : html `< a href =${ href } target =${ target } style="color: inherit;"> ${ div } </ a > ` ;
51
+ }
You can’t perform that action at this time.
0 commit comments