qvac-charts 0.0.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +198 -0
- package/NOTICE.md +13 -0
- package/README.md +69 -0
- package/dist-lib/index.d.ts +100 -0
- package/dist-lib/index.js +28 -0
- package/dist-lib/lib/charts/index.d.ts +3 -0
- package/dist-lib/lib/charts/index.js +21 -0
- package/dist-lib/lib/charts/maps.d.ts +4 -0
- package/dist-lib/lib/charts/maps.js +197 -0
- package/dist-lib/lib/charts/parts.d.ts +6 -0
- package/dist-lib/lib/charts/parts.js +244 -0
- package/dist-lib/lib/charts/ranking.d.ts +3 -0
- package/dist-lib/lib/charts/ranking.js +62 -0
- package/dist-lib/lib/charts/slope.d.ts +2 -0
- package/dist-lib/lib/charts/slope.js +57 -0
- package/dist-lib/lib/charts/time.d.ts +4 -0
- package/dist-lib/lib/charts/time.js +112 -0
- package/dist-lib/lib/format.d.ts +3 -0
- package/dist-lib/lib/format.js +9 -0
- package/dist-lib/lib/frame.d.ts +35 -0
- package/dist-lib/lib/frame.js +56 -0
- package/dist-lib/lib/geometry.d.ts +50 -0
- package/dist-lib/lib/geometry.js +166 -0
- package/dist-lib/lib/maps/aliases.d.ts +1 -0
- package/dist-lib/lib/maps/aliases.js +77 -0
- package/dist-lib/lib/maps/brazil.d.ts +2 -0
- package/dist-lib/lib/maps/brazil.js +29 -0
- package/dist-lib/lib/maps/world.d.ts +10 -0
- package/dist-lib/lib/maps/world.js +1 -0
- package/dist-lib/lib/normalize.d.ts +7 -0
- package/dist-lib/lib/normalize.js +247 -0
- package/dist-lib/lib/pick.d.ts +3 -0
- package/dist-lib/lib/pick.js +62 -0
- package/dist-lib/lib/places.d.ts +30 -0
- package/dist-lib/lib/places.js +45 -0
- package/dist-lib/lib/render.d.ts +8 -0
- package/dist-lib/lib/render.js +12 -0
- package/dist-lib/lib/schema.d.ts +85 -0
- package/dist-lib/lib/schema.js +65 -0
- package/dist-lib/lib/spec.d.ts +58 -0
- package/dist-lib/lib/spec.js +1 -0
- package/dist-lib/lib/svg.d.ts +21 -0
- package/dist-lib/lib/svg.js +43 -0
- package/dist-lib/lib/themes.d.ts +28 -0
- package/dist-lib/lib/themes.js +71 -0
- package/dist-lib/maps.d.ts +3 -0
- package/dist-lib/maps.js +7 -0
- package/package.json +63 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Row } from './spec.ts';
|
|
2
|
+
export interface Theme {
|
|
3
|
+
bg: string;
|
|
4
|
+
text: string;
|
|
5
|
+
muted: string;
|
|
6
|
+
faint: string;
|
|
7
|
+
accent: string;
|
|
8
|
+
base: string;
|
|
9
|
+
palette: ReadonlyArray<string>;
|
|
10
|
+
}
|
|
11
|
+
export type ThemeName = 'dark' | 'light';
|
|
12
|
+
export declare const themes: Readonly<Record<ThemeName, Theme>>;
|
|
13
|
+
export interface Palette {
|
|
14
|
+
t: Theme;
|
|
15
|
+
highlight: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface ColorKey {
|
|
18
|
+
label?: string | undefined;
|
|
19
|
+
group?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export declare function colors(items: ReadonlyArray<ColorKey>, { t, highlight }: Palette): (d: ColorKey) => string;
|
|
22
|
+
export interface Ramp {
|
|
23
|
+
shade: (v: number) => string;
|
|
24
|
+
lo: number;
|
|
25
|
+
hi: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function ramp(data: ReadonlyArray<Row>, t: Theme): Ramp;
|
|
28
|
+
export declare function contrast(fill: string, t: Theme): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const themes = {
|
|
2
|
+
dark: {
|
|
3
|
+
bg: '#0c1824',
|
|
4
|
+
text: '#f4efe6',
|
|
5
|
+
muted: '#8fa3b8',
|
|
6
|
+
faint: 'rgba(244,239,230,0.10)',
|
|
7
|
+
accent: '#ffb703',
|
|
8
|
+
base: '#3a5a7a',
|
|
9
|
+
palette: [
|
|
10
|
+
'#ffb703',
|
|
11
|
+
'#fb8500',
|
|
12
|
+
'#2a9d8f',
|
|
13
|
+
'#8ecae6',
|
|
14
|
+
'#e63946',
|
|
15
|
+
'#219ebc',
|
|
16
|
+
'#cdb4db',
|
|
17
|
+
'#a7c957'
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
light: {
|
|
21
|
+
bg: '#f5efe3',
|
|
22
|
+
text: '#14213d',
|
|
23
|
+
muted: '#5c677d',
|
|
24
|
+
faint: 'rgba(20,33,61,0.10)',
|
|
25
|
+
accent: '#e63946',
|
|
26
|
+
base: '#9aa9bd',
|
|
27
|
+
palette: [
|
|
28
|
+
'#e63946',
|
|
29
|
+
'#f4a261',
|
|
30
|
+
'#2a9d8f',
|
|
31
|
+
'#457b9d',
|
|
32
|
+
'#1d3557',
|
|
33
|
+
'#e9c46a',
|
|
34
|
+
'#8d99ae',
|
|
35
|
+
'#6d597a'
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export function colors(items, { t, highlight }) {
|
|
40
|
+
const groups = [...new Set(items.map((d) => d.group).filter(Boolean))];
|
|
41
|
+
return (d) => {
|
|
42
|
+
if (d.label && d.label === highlight)
|
|
43
|
+
return t.accent;
|
|
44
|
+
if (d.group && groups.length > 1) {
|
|
45
|
+
return t.palette[(groups.indexOf(d.group) + 1) % t.palette.length];
|
|
46
|
+
}
|
|
47
|
+
return t.palette[(items.indexOf(d) + 1) % t.palette.length];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function ramp(data, t) {
|
|
51
|
+
const values = data.map((d) => d.value);
|
|
52
|
+
const lo = Math.min(...values);
|
|
53
|
+
const hi = Math.max(...values);
|
|
54
|
+
const shade = (v) => mix(t.bg, { to: t.accent, f: 0.28 + 0.72 * (hi === lo ? 1 : (v - lo) / (hi - lo)) });
|
|
55
|
+
return { shade, lo, hi };
|
|
56
|
+
}
|
|
57
|
+
function mix(from, { to, f }) {
|
|
58
|
+
const [x, y] = [from, to].map((h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)));
|
|
59
|
+
return ('#' +
|
|
60
|
+
x
|
|
61
|
+
.map((v, i) => Math.round(v + (y[i] - v) * f)
|
|
62
|
+
.toString(16)
|
|
63
|
+
.padStart(2, '0'))
|
|
64
|
+
.join(''));
|
|
65
|
+
}
|
|
66
|
+
const luma = (hex) => [1, 3, 5].reduce((s, i, k) => s + parseInt(hex.slice(i, i + 2), 16) * [0.299, 0.587, 0.114][k], 0);
|
|
67
|
+
export function contrast(fill, t) {
|
|
68
|
+
if (luma(fill) < 150)
|
|
69
|
+
return '#ffffff';
|
|
70
|
+
return luma(t.bg) < luma(t.text) ? t.bg : t.text;
|
|
71
|
+
}
|
package/dist-lib/maps.js
ADDED
package/package.json
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "qvac-charts",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Renders a small JSON chart spec into an SVG, on Bare and Node",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist-lib/index.d.ts",
|
|
10
|
+
"default": "./dist-lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./maps": {
|
|
13
|
+
"types": "./dist-lib/maps.d.ts",
|
|
14
|
+
"default": "./dist-lib/maps.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"package.json",
|
|
19
|
+
"dist-lib",
|
|
20
|
+
"NOTICE.md"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"bare": ">=1.33.4",
|
|
24
|
+
"node": "^22.21.0 || >=24.9.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"format": "prettier . --write",
|
|
28
|
+
"lint": "prettier . --check && lunte && tsc --noEmit",
|
|
29
|
+
"test": "npm run test:node && npm run test:bare",
|
|
30
|
+
"test:node": "brittle-node test/all.mjs",
|
|
31
|
+
"test:bare": "brittle-bare test/all.mjs",
|
|
32
|
+
"test:generate": "brittle-make-test test/all.mjs test/*.ts",
|
|
33
|
+
"build:lib": "node scripts/build-lib.mjs",
|
|
34
|
+
"build:world": "node scripts/project-world.mjs lib/maps/world.ts",
|
|
35
|
+
"snapshots:update": "node scripts/snapshots.mjs"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"bare-runtime": "1.36.0",
|
|
39
|
+
"brittle": "^4.5.0",
|
|
40
|
+
"d3-geo": "3.1.1",
|
|
41
|
+
"holepunch-types": "^0.2.3",
|
|
42
|
+
"lunte": "^1.8.6",
|
|
43
|
+
"lunte-plugin-qvac": "^0.2.0",
|
|
44
|
+
"prettier": "^3.9.6",
|
|
45
|
+
"prettier-config-holepunch": "^2.0.0",
|
|
46
|
+
"topojson-client": "3.1.0",
|
|
47
|
+
"typescript": "^7.0.2",
|
|
48
|
+
"world-atlas": "2.0.2"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/tetherto/qvac-charts.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Tether Inc",
|
|
58
|
+
"license": "Apache-2.0",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/tetherto/qvac-charts/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/tetherto/qvac-charts"
|
|
63
|
+
}
|