@cfasim-ui/charts 0.7.8 → 0.8.1
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/dist/BarChart/BarChart.d.ts +9 -26
- package/dist/ChartMenu/ChartMenu.d.ts +3 -2
- package/dist/ChartTooltip/ChartTooltip.d.ts +9 -12
- package/dist/ChoroplethMap/ChoroplethMap.d.ts +42 -190
- package/dist/ChoroplethMap/ChoroplethTooltip.d.ts +20 -27
- package/dist/ChoroplethMap/canvasLayer.d.ts +23 -6
- package/dist/ChoroplethMap/cityLayout.d.ts +3 -2
- package/dist/ChoroplethMap/mixedGeo.d.ts +74 -0
- package/dist/ChoroplethMap/mixedGeo.test.d.ts +1 -0
- package/dist/DataTable/DataTable.d.ts +3 -2
- package/dist/LineChart/LineChart.d.ts +9 -26
- package/dist/_shared/ChartAnnotations.d.ts +3 -2
- package/dist/_shared/ChartZoomControls.d.ts +3 -2
- package/dist/_shared/index.d.ts +2 -1
- package/dist/_shared/mapTheme.d.ts +159 -0
- package/dist/_shared/mapTheme.test.d.ts +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1821 -1462
- package/docs/BarChart.md +776 -0
- package/docs/ChoroplethMap.md +1394 -0
- package/docs/DataTable.md +386 -0
- package/docs/LineChart.md +1267 -0
- package/docs/index.json +56 -0
- package/package.json +25 -21
- package/src/BarChart/BarChart.md +743 -0
- package/src/BarChart/BarChart.vue +1901 -0
- package/src/ChartMenu/ChartMenu.vue +220 -0
- package/src/ChartMenu/download.ts +120 -0
- package/src/ChartTooltip/ChartTooltip.vue +97 -0
- package/src/ChoroplethMap/ChoroplethMap.md +1354 -0
- package/src/ChoroplethMap/ChoroplethMap.vue +3778 -0
- package/src/ChoroplethMap/ChoroplethTooltip.vue +103 -0
- package/src/ChoroplethMap/canvasLayer.ts +373 -0
- package/src/ChoroplethMap/cityLayout.ts +262 -0
- package/src/ChoroplethMap/hsaMapping.ts +4116 -0
- package/src/ChoroplethMap/mixedGeo.ts +201 -0
- package/src/DataTable/DataTable.md +372 -0
- package/src/DataTable/DataTable.vue +406 -0
- package/src/LineChart/LineChart.md +1225 -0
- package/src/LineChart/LineChart.vue +1555 -0
- package/src/_shared/ChartAnnotations.vue +420 -0
- package/src/_shared/ChartZoomControls.vue +138 -0
- package/src/_shared/annotations.ts +106 -0
- package/src/_shared/axes.ts +69 -0
- package/src/_shared/chartProps.ts +201 -0
- package/src/_shared/computeTicks.ts +42 -0
- package/src/_shared/contrast.ts +100 -0
- package/src/_shared/dateAxis.ts +501 -0
- package/src/_shared/index.ts +78 -0
- package/src/_shared/mapTheme.ts +551 -0
- package/src/_shared/scale.ts +86 -0
- package/src/_shared/seriesCsv.ts +68 -0
- package/src/_shared/touch.ts +8 -0
- package/src/_shared/useChartFoundation.ts +175 -0
- package/src/_shared/useChartFullscreen.ts +254 -0
- package/src/_shared/useChartMenu.ts +111 -0
- package/src/_shared/useChartPadding.ts +235 -0
- package/src/_shared/useChartSize.ts +58 -0
- package/src/_shared/useChartTooltip.ts +205 -0
- package/src/env.d.ts +4 -0
- package/src/hsa-mapping.ts +1 -0
- package/src/index.ts +41 -0
- package/src/tooltip-position.ts +55 -0
- package/src/us-cities/data.ts +1371 -0
- package/src/us-cities/index.ts +122 -0
- package/src/us-cities.ts +7 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { CityMarker } from "../ChoroplethMap/cityLayout.js";
|
|
2
|
+
import { usCities } from "./data.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A US city record from the bundled Natural Earth dataset. `population` is an
|
|
6
|
+
* approximate estimate used only for ranking; it is never displayed.
|
|
7
|
+
*/
|
|
8
|
+
export interface UsCity {
|
|
9
|
+
/** City name, e.g. `"Austin"`. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** `[longitude, latitude]`. */
|
|
12
|
+
coordinates: [number, number];
|
|
13
|
+
/** Approximate population (Natural Earth `POP_MAX`), used for ranking. */
|
|
14
|
+
population: number;
|
|
15
|
+
/** 2-digit state FIPS code, e.g. `"48"` for Texas. */
|
|
16
|
+
stateFips: string;
|
|
17
|
+
/** 2-letter USPS abbreviation, e.g. `"TX"`. */
|
|
18
|
+
stateAbbr: string;
|
|
19
|
+
/** True for a state capital (or the national capital). */
|
|
20
|
+
capital: boolean;
|
|
21
|
+
/** True only for Washington, DC. */
|
|
22
|
+
nationalCapital: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { usCities };
|
|
26
|
+
|
|
27
|
+
/** Options shared by the marker selectors. */
|
|
28
|
+
export interface CityMarkerOptions {
|
|
29
|
+
/** Maximum number of non-capital cities to include. */
|
|
30
|
+
limit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Assign a per-city `minZoom` by population rank (default `true`) so cities
|
|
33
|
+
* reveal progressively as you zoom in. Set `false` for a flat layer where
|
|
34
|
+
* every city shares the map's `citiesMinZoom`.
|
|
35
|
+
*/
|
|
36
|
+
tiered?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Progressive level-of-detail: bigger cities (lower 0-based population rank)
|
|
40
|
+
// get a smaller minZoom, so they appear first and more reveal as you zoom in.
|
|
41
|
+
// Thresholds line up with the map's double-click zoom levels (k = 1, 2, 4, 8).
|
|
42
|
+
function rankMinZoom(rank: number): number {
|
|
43
|
+
if (rank < 6) return 1; // biggest — visible at the base overview
|
|
44
|
+
if (rank < 20) return 2; // one zoom level in
|
|
45
|
+
if (rank < 45) return 4; // two levels
|
|
46
|
+
return 8; // three levels
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const byPopulation = (a: UsCity, b: UsCity) => b.population - a.population;
|
|
50
|
+
|
|
51
|
+
// Build markers from `capitals` (always shown) followed by `rest` (ordered by
|
|
52
|
+
// population). When tiered, capitals get minZoom 1 and each non-capital gets a
|
|
53
|
+
// tier from its *own* 0-based rank among the non-capitals — not its index in
|
|
54
|
+
// the combined list, which would be shifted by the prepended capitals.
|
|
55
|
+
function toMarkers(
|
|
56
|
+
capitals: UsCity[],
|
|
57
|
+
rest: UsCity[],
|
|
58
|
+
tiered: boolean,
|
|
59
|
+
): CityMarker[] {
|
|
60
|
+
const cap = capitals.map((c) => {
|
|
61
|
+
const m: CityMarker = {
|
|
62
|
+
name: c.name,
|
|
63
|
+
coordinates: c.coordinates,
|
|
64
|
+
capital: true,
|
|
65
|
+
};
|
|
66
|
+
if (tiered) m.minZoom = 1;
|
|
67
|
+
return m;
|
|
68
|
+
});
|
|
69
|
+
const others = rest.map((c, rank) => {
|
|
70
|
+
const m: CityMarker = {
|
|
71
|
+
name: c.name,
|
|
72
|
+
coordinates: c.coordinates,
|
|
73
|
+
capital: false,
|
|
74
|
+
};
|
|
75
|
+
if (tiered) m.minZoom = rankMinZoom(rank);
|
|
76
|
+
return m;
|
|
77
|
+
});
|
|
78
|
+
return [...cap, ...others];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Markers for the national map: Washington, DC (starred) plus the `limit`
|
|
83
|
+
* most-populous US cities as plain dots — state capitals are *not* starred at
|
|
84
|
+
* the national level, only DC is. Pass directly to `<ChoroplethMap :cities>`.
|
|
85
|
+
*
|
|
86
|
+
* By default (`tiered`) each city also gets a `minZoom` by population rank, so
|
|
87
|
+
* on a zoomable map the biggest cities show first and more reveal as you zoom
|
|
88
|
+
* in (the capital always shows). Pass `{ tiered: false }` for a flat layer.
|
|
89
|
+
*/
|
|
90
|
+
export function nationalCityMarkers(
|
|
91
|
+
options: CityMarkerOptions = {},
|
|
92
|
+
): CityMarker[] {
|
|
93
|
+
const { limit = 100, tiered = true } = options;
|
|
94
|
+
const dc = usCities.filter((c) => c.nationalCapital);
|
|
95
|
+
const rest = usCities
|
|
96
|
+
.filter((c) => !c.nationalCapital)
|
|
97
|
+
.sort(byPopulation)
|
|
98
|
+
.slice(0, limit);
|
|
99
|
+
// Nationally only the national capital gets a star; everything else is a dot.
|
|
100
|
+
return toMarkers(dc, rest, tiered);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Markers for a single-state map: that state's capital (starred) plus its
|
|
105
|
+
* most-populous cities, capital first. `stateFips` is the 2-digit FIPS code.
|
|
106
|
+
* Tiered by population like `nationalCityMarkers` (the capital always shows);
|
|
107
|
+
* pass `{ tiered: false }` to opt out.
|
|
108
|
+
*/
|
|
109
|
+
export function stateCityMarkers(
|
|
110
|
+
stateFips: string,
|
|
111
|
+
options: CityMarkerOptions = {},
|
|
112
|
+
): CityMarker[] {
|
|
113
|
+
const { limit = 25, tiered = true } = options;
|
|
114
|
+
const fips = String(stateFips).padStart(2, "0");
|
|
115
|
+
const inState = usCities.filter((c) => c.stateFips === fips);
|
|
116
|
+
const capitals = inState.filter((c) => c.capital);
|
|
117
|
+
const rest = inState
|
|
118
|
+
.filter((c) => !c.capital)
|
|
119
|
+
.sort(byPopulation)
|
|
120
|
+
.slice(0, limit);
|
|
121
|
+
return toMarkers(capitals, rest, tiered);
|
|
122
|
+
}
|