@bicharts/chart-host 0.1.5
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 +202 -0
- package/NOTICE +50 -0
- package/README.md +167 -0
- package/dist/chunk-22B22PJU.mjs +70 -0
- package/dist/chunk-22B22PJU.mjs.map +7 -0
- package/dist/chunk-23GNNTXQ.mjs +9 -0
- package/dist/chunk-23GNNTXQ.mjs.map +7 -0
- package/dist/chunk-MHDS4Q5G.mjs +9 -0
- package/dist/chunk-MHDS4Q5G.mjs.map +7 -0
- package/dist/chunk-NWID6YOP.mjs +9 -0
- package/dist/chunk-NWID6YOP.mjs.map +7 -0
- package/dist/chunk-UNH36TGD.mjs +1185 -0
- package/dist/chunk-UNH36TGD.mjs.map +7 -0
- package/dist/geo.mjs +41 -0
- package/dist/geo.mjs.map +7 -0
- package/dist/geoNaRegions-SAINMZXG.mjs +12 -0
- package/dist/geoNaRegions-SAINMZXG.mjs.map +7 -0
- package/dist/geoUsStates.generated-2ZZRXWWJ.mjs +8 -0
- package/dist/geoUsStates.generated-2ZZRXWWJ.mjs.map +7 -0
- package/dist/geoUsZip3.generated-56OL4TTZ.mjs +8 -0
- package/dist/geoUsZip3.generated-56OL4TTZ.mjs.map +7 -0
- package/dist/geoWorld110m.generated-O2WOIRYY.mjs +8 -0
- package/dist/geoWorld110m.generated-O2WOIRYY.mjs.map +7 -0
- package/dist/index.mjs +70 -0
- package/dist/index.mjs.map +7 -0
- package/dist/react.mjs +97 -0
- package/dist/react.mjs.map +7 -0
- package/dist/types/contract.d.ts +69 -0
- package/dist/types/defaults.d.ts +5 -0
- package/dist/types/geo.d.ts +3 -0
- package/dist/types/geoLazy.d.ts +12 -0
- package/dist/types/geoNaRegions.d.ts +3 -0
- package/dist/types/geoUsStates.generated.d.ts +1 -0
- package/dist/types/geoUsZip3.generated.d.ts +1 -0
- package/dist/types/geoWorld110m.generated.d.ts +1 -0
- package/dist/types/host.d.ts +61 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/payload.d.ts +31 -0
- package/dist/types/react.d.ts +52 -0
- package/dist/types/selection.d.ts +15 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
BIC Charts — @bicharts/chart-host, @bicharts/shape-core
|
|
2
|
+
Copyright 2026 CodeX Framework / Business Intelligence Champions
|
|
3
|
+
|
|
4
|
+
This product includes software developed by CodeX Framework.
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
6
|
+
|
|
7
|
+
================================================================================
|
|
8
|
+
BUNDLED REFERENCE DATA — third-party, attribution required
|
|
9
|
+
================================================================================
|
|
10
|
+
|
|
11
|
+
This package embeds pre-processed geographic reference data. The data is
|
|
12
|
+
compiled into the distributed JavaScript bundles, so the attributions below
|
|
13
|
+
travel with any copy of this package and with any application that bundles it.
|
|
14
|
+
|
|
15
|
+
--------------------------------------------------------------------------------
|
|
16
|
+
1. City and administrative-region coordinates ***ATTRIBUTION REQUIRED***
|
|
17
|
+
--------------------------------------------------------------------------------
|
|
18
|
+
Source: GeoNames (https://www.geonames.org/) — cities15000 and admin1 datasets,
|
|
19
|
+
filtered to US/CA/MX places with population >= 25,000, reduced to
|
|
20
|
+
name/coordinate/population tuples.
|
|
21
|
+
License: Creative Commons Attribution 4.0 International (CC BY 4.0)
|
|
22
|
+
https://creativecommons.org/licenses/by/4.0/
|
|
23
|
+
Changes: Subset by country and population; fields dropped; coordinates rounded;
|
|
24
|
+
administrative centroids re-derived as population-weighted means.
|
|
25
|
+
|
|
26
|
+
"This work includes data from GeoNames (https://www.geonames.org/),
|
|
27
|
+
licensed under CC BY 4.0."
|
|
28
|
+
|
|
29
|
+
CC BY 4.0 requires that this attribution be preserved. If you redistribute this
|
|
30
|
+
package, or an application that bundles it, keep this NOTICE file (or reproduce
|
|
31
|
+
the attribution above somewhere a recipient can reasonably find it).
|
|
32
|
+
|
|
33
|
+
--------------------------------------------------------------------------------
|
|
34
|
+
2. World country polygons
|
|
35
|
+
--------------------------------------------------------------------------------
|
|
36
|
+
Source: Natural Earth (https://www.naturalearthdata.com/) 110m cultural vectors,
|
|
37
|
+
via the world-atlas TopoJSON distribution.
|
|
38
|
+
License: Public domain. Natural Earth asks — but does not require — that it be
|
|
39
|
+
credited. We are happy to: "Made with Natural Earth."
|
|
40
|
+
|
|
41
|
+
--------------------------------------------------------------------------------
|
|
42
|
+
3. United States state and ZIP-prefix boundaries
|
|
43
|
+
--------------------------------------------------------------------------------
|
|
44
|
+
Source: US Census Bureau / TIGER cartographic boundary files (states, DC and
|
|
45
|
+
territories; 3-digit ZCTA prefixes), via the us-atlas distribution.
|
|
46
|
+
License: Public domain (a work of the US federal government).
|
|
47
|
+
|
|
48
|
+
================================================================================
|
|
49
|
+
Nothing in this section limits the Apache 2.0 grant covering the SOURCE CODE of
|
|
50
|
+
this package. It applies only to the embedded reference data described above.
|
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# @bicharts/chart-host
|
|
2
|
+
|
|
3
|
+
Run a D3 chart generated by
|
|
4
|
+
[Business Intelligence Champions](https://bizintelligencechampions.com) (BIC) in any web page.
|
|
5
|
+
|
|
6
|
+
A BIC chart is *generated source you own* — a plain `render(container, data, options)` function
|
|
7
|
+
you commit to your repo. There is no API key at run time, no per-render cost, and no network
|
|
8
|
+
call. This package is the host side: the ~80 lines every integrator would otherwise write, and
|
|
9
|
+
the handful they would get subtly wrong.
|
|
10
|
+
|
|
11
|
+
It is the same contract the BIC Power BI visual implements, minus Power BI — so a chart looks
|
|
12
|
+
and behaves the same wherever it runs.
|
|
13
|
+
|
|
14
|
+
## What it does for you
|
|
15
|
+
|
|
16
|
+
- **Compiles** the generated code and injects your `d3`.
|
|
17
|
+
- **Applies the shared option defaults/clamps** — the same `resolveOptions` the visual uses.
|
|
18
|
+
- **Resolves mark clicks** — including *through* a chart's own tooltip overlay, and by geometry
|
|
19
|
+
when a row has no hittable shape.
|
|
20
|
+
- **Multi-select on Ctrl / Cmd / Shift** — the same gesture Power BI uses. Modifier-clicking
|
|
21
|
+
*toggles* each row, so clicking a selected mark again removes it.
|
|
22
|
+
- **Owns the selection affordance** — dims unselected marks via the `lch-*` class grammar.
|
|
23
|
+
- **Translates row indices** between cross-filtered charts (see the hazard below).
|
|
24
|
+
- **Pins typography** at the container boundary so your page's CSS can't slice chart labels.
|
|
25
|
+
- **Tears down** cleanly — StrictMode-safe, stops animation timers.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @bicharts/chart-host
|
|
31
|
+
npm install d3@7 # peer requirement of the CHART, not of this package
|
|
32
|
+
npm install -D @types/d3 # TypeScript only — d3 ships no types
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This package itself has **no runtime dependencies** — the shape profiler is bundled in, and the
|
|
36
|
+
map geometry loads on demand.
|
|
37
|
+
|
|
38
|
+
React is an **optional** peer — a vanilla host never resolves it.
|
|
39
|
+
|
|
40
|
+
## React
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import * as d3 from "d3";
|
|
44
|
+
import { BicChart, BicChartGroup } from "@bicharts/chart-host/react";
|
|
45
|
+
import code from "./charts/revenue/chart.js?raw"; // Vite; any raw-text import works
|
|
46
|
+
import payload from "./charts/revenue/data.sample.json";
|
|
47
|
+
|
|
48
|
+
// data.sample.json rows are POSITIONAL arrays; the group wants row OBJECTS.
|
|
49
|
+
const columns = payload.columns;
|
|
50
|
+
const rows = payload.rows.map(r =>
|
|
51
|
+
Object.fromEntries(columns.map((c, i) => [c.name, r[i]])));
|
|
52
|
+
|
|
53
|
+
<BicChartGroup columns={columns} rows={rows}>
|
|
54
|
+
<BicChart id="revenue" code={code} d3={d3} options={{ width, height }} />
|
|
55
|
+
<BicChart id="detail" code={detailCode} d3={d3} options={{ width, height }} />
|
|
56
|
+
</BicChartGroup>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Clicking a mark in one chart filters the other. The group owns the source table and the
|
|
60
|
+
payload→source row mapping — which is the part you must not hand-roll:
|
|
61
|
+
|
|
62
|
+
> **The row-index hazard.** `__rowIdx__` is a position *within the payload a chart received*,
|
|
63
|
+
> not an id in your table. Re-render a chart with filtered rows and its payload renumbers from
|
|
64
|
+
> zero, so the same integer now denotes a different record. Comparing indices across two charts
|
|
65
|
+
> does not throw — it quietly filters to the wrong thing.
|
|
66
|
+
|
|
67
|
+
## Vanilla
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { createChartHost } from "@bicharts/chart-host";
|
|
71
|
+
|
|
72
|
+
const host = createChartHost(el, { code, data, d3, options: { width: 800, height: 500 } });
|
|
73
|
+
host.render();
|
|
74
|
+
host.selection.onChange(rowIdxs => { /* cross-filter your other panels */ });
|
|
75
|
+
host.setOptions({ colorScaleLow: "#eee" }); // live restyle — never a regeneration
|
|
76
|
+
host.destroy(); // call on unmount
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Sizing is yours
|
|
80
|
+
|
|
81
|
+
`width`/`height` have **no defaults**. A chart draws once at whatever it is handed and does not
|
|
82
|
+
re-measure, so a container measured at 0 draws a 0px chart forever. Measure synchronously, and
|
|
83
|
+
use a `ResizeObserver` only for *later* resizes — gating the first paint on one costs seconds in
|
|
84
|
+
a background or headless tab, where frames are barely produced.
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
useLayoutEffect(() => setW(ref.current.getBoundingClientRect().width), []);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Maps
|
|
91
|
+
|
|
92
|
+
Geometry is **not** bundled into the entry — the three assets are ~1.3 MB raw, and a bar chart
|
|
93
|
+
should not pay for a basemap. Choose one:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
import { loadGeo } from "@bicharts/chart-host"; // per-asset dynamic import (own chunk)
|
|
97
|
+
await loadGeo("us-state-code");
|
|
98
|
+
createChartHost(el, { code, data, d3, geoKind: "us-state-code" });
|
|
99
|
+
|
|
100
|
+
import { geoForKind } from "@bicharts/chart-host/geo"; // or bundle it yourself
|
|
101
|
+
createChartHost(el, { code, data, d3, geoKind, geoProvider: geoForKind });
|
|
102
|
+
|
|
103
|
+
createChartHost(el, { code, data, d3, options: { geo } }); // or pass data.geo.json directly
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Setting `geoKind` with no geometry available warns and draws without a basemap.
|
|
107
|
+
|
|
108
|
+
## D3 plugins
|
|
109
|
+
|
|
110
|
+
Some charts call `d3.sankey()`, `d3.hexbin()` or the voronoi family. Those are separate packages
|
|
111
|
+
that **attach onto the d3 object** — install them and augment the *same* d3 you pass in:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import * as d3 from "d3";
|
|
115
|
+
import { sankey, sankeyLinkHorizontal } from "d3-sankey";
|
|
116
|
+
Object.assign(d3, { sankey, sankeyLinkHorizontal });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The integration contract returned by `generate_chart` names exactly which ones *your* chart
|
|
120
|
+
needs. If one is missing, the host throws a message naming the package instead of a bare
|
|
121
|
+
`d3.sankey is not a function`.
|
|
122
|
+
|
|
123
|
+
## Selection styling
|
|
124
|
+
|
|
125
|
+
Generated code emits marks and `data-row-idx`; it never styles "selected", because only the host
|
|
126
|
+
knows what is selected. This package injects the rules, using the same grammar as the Power BI
|
|
127
|
+
visual — override them if you want a different look:
|
|
128
|
+
|
|
129
|
+
```css
|
|
130
|
+
.bic-chart-host { --lch-dim-opacity: 0.25; }
|
|
131
|
+
.bic-chart-host.lch-has-selection .d3-mark:not(.lch-mark-selected) { opacity: var(--lch-dim-opacity); }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Versioning
|
|
135
|
+
|
|
136
|
+
`HOST_CONTRACT_VERSION` is the grammar version (mark classes, container slots, the cross-filter
|
|
137
|
+
event). `generate_chart` stamps it into every artifact it writes; this package warns if it runs
|
|
138
|
+
a chart from a different **major**. Package SemVer tracks the JS API; the contract version tracks
|
|
139
|
+
the DOM/interaction grammar, and they move independently.
|
|
140
|
+
|
|
141
|
+
## Licence and attribution
|
|
142
|
+
|
|
143
|
+
Apache-2.0 (see `LICENSE`).
|
|
144
|
+
|
|
145
|
+
The package embeds geographic reference data, and one source carries a **condition**, not a
|
|
146
|
+
courtesy: city and administrative-region coordinates come from
|
|
147
|
+
[GeoNames](https://www.geonames.org/) under **CC BY 4.0**, which requires attribution to travel
|
|
148
|
+
with any redistribution — including an application that bundles this package. The credit is in
|
|
149
|
+
`NOTICE` and in a banner comment at the top of every built file, so keeping either satisfies it.
|
|
150
|
+
Country polygons (Natural Earth) and US state/ZIP boundaries (US Census/TIGER) are public domain.
|
|
151
|
+
|
|
152
|
+
If your build strips comments and you do not ship `NOTICE`, reproduce this line somewhere a
|
|
153
|
+
recipient can find it:
|
|
154
|
+
|
|
155
|
+
> This work includes data from GeoNames (https://www.geonames.org/), licensed under CC BY 4.0.
|
|
156
|
+
|
|
157
|
+
## Building from source
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm install && npm run build # esbuild bundle (+ .d.ts) into dist/
|
|
161
|
+
npm test
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The build **inlines** `@bicharts/shape-core`, which lives outside this package root — that is
|
|
165
|
+
deliberate, so the repo keeps one copy of the geo detection logic and the published artifact
|
|
166
|
+
still stands alone. `npm pack` rebuilds first (`prepack`); do not publish a stale `dist/`.
|
|
167
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*! @bicharts/chart-host — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; Natural Earth and US Census/TIGER (public domain). Full text: NOTICE in this package. */
|
|
2
|
+
|
|
3
|
+
// src/geoNaRegions.ts
|
|
4
|
+
var NA_ISO3 = /* @__PURE__ */ new Set([
|
|
5
|
+
"USA",
|
|
6
|
+
"CAN",
|
|
7
|
+
"MEX",
|
|
8
|
+
// continental
|
|
9
|
+
"GTM",
|
|
10
|
+
"BLZ",
|
|
11
|
+
"SLV",
|
|
12
|
+
"HND",
|
|
13
|
+
"NIC",
|
|
14
|
+
"CRI",
|
|
15
|
+
"PAN",
|
|
16
|
+
// Central America
|
|
17
|
+
"CUB",
|
|
18
|
+
"JAM",
|
|
19
|
+
"HTI",
|
|
20
|
+
"DOM",
|
|
21
|
+
"BHS",
|
|
22
|
+
"PRI",
|
|
23
|
+
"TTO"
|
|
24
|
+
// Greater Antilles + Bahamas
|
|
25
|
+
]);
|
|
26
|
+
var NA_LAT_MAX = 75;
|
|
27
|
+
function clipRingToLat(ring, latMax) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const n = ring.length;
|
|
30
|
+
for (let i = 0; i < n; i++) {
|
|
31
|
+
const cur = ring[i];
|
|
32
|
+
const prev = ring[(i + n - 1) % n];
|
|
33
|
+
const curIn = cur[1] <= latMax;
|
|
34
|
+
const prevIn = prev[1] <= latMax;
|
|
35
|
+
if (curIn !== prevIn) {
|
|
36
|
+
const dy = cur[1] - prev[1];
|
|
37
|
+
const t = dy === 0 ? 0 : (latMax - prev[1]) / dy;
|
|
38
|
+
out.push([prev[0] + t * (cur[0] - prev[0]), latMax]);
|
|
39
|
+
}
|
|
40
|
+
if (curIn) out.push(cur);
|
|
41
|
+
}
|
|
42
|
+
if (out.length && (out[0][0] !== out[out.length - 1][0] || out[0][1] !== out[out.length - 1][1])) {
|
|
43
|
+
out.push(out[0]);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function clipFeatureToLat(feature, latMax) {
|
|
48
|
+
const g = feature && feature.geometry;
|
|
49
|
+
if (!g) return null;
|
|
50
|
+
const clipPolygon = (rings) => {
|
|
51
|
+
const kept = rings.map((r) => clipRingToLat(r, latMax)).filter((r) => r.length >= 4);
|
|
52
|
+
return kept.length && kept[0].length >= 4 ? kept : null;
|
|
53
|
+
};
|
|
54
|
+
if (g.type === "Polygon") {
|
|
55
|
+
const c = clipPolygon(g.coordinates);
|
|
56
|
+
return c ? { ...feature, geometry: { type: "Polygon", coordinates: c } } : null;
|
|
57
|
+
}
|
|
58
|
+
if (g.type === "MultiPolygon") {
|
|
59
|
+
const polys = g.coordinates.map(clipPolygon).filter((p) => p !== null);
|
|
60
|
+
return polys.length ? { ...feature, geometry: { type: "MultiPolygon", coordinates: polys } } : null;
|
|
61
|
+
}
|
|
62
|
+
return feature;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
NA_ISO3,
|
|
67
|
+
NA_LAT_MAX,
|
|
68
|
+
clipFeatureToLat
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=chunk-22B22PJU.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/geoNaRegions.ts"],
|
|
4
|
+
"sourcesContent": ["// What DEFINES the North America basemap: which regions belong on it, how far north it\n// extends, and the pure geometry op that enforces that. No asset imports \u2014 geo.ts statically\n// pulls ~1.3 MB of generated geometry, so anything that only needs these decisions (tests,\n// tooling, future callers) shouldn't have to load the world to read them.\n\n// GREENLAND (\"GRL\") IS DELIBERATELY ABSENT (2026-07-25). It is geographically North\n// American, but it is an enormous and almost always data-less slab, and the NA point-map\n// archetype fitExtent()s to this basemap's FULL extent \u2014 so including it stretched the fit\n// ~40 degrees further east (basemap lon max -12.2 with it, -52.6 without) and squeezed the\n// actual continent. This affects ONLY the basemap: WORLD_110M is untouched, so GRL remains\n// a perfectly good joinable region on the world choropleths, which is where a Greenland\n// data point belongs. Do not \"fix\" this by adding GRL back.\nexport const NA_ISO3 = new Set([\n \"USA\", \"CAN\", \"MEX\", // continental\n \"GTM\", \"BLZ\", \"SLV\", \"HND\", \"NIC\", \"CRI\", \"PAN\", // Central America\n \"CUB\", \"JAM\", \"HTI\", \"DOM\", \"BHS\", \"PRI\", \"TTO\", // Greater Antilles + Bahamas\n]);\n\n// NORTHERN CUTOFF (2026-07-25). Dropping Greenland reclaimed the eastern half of the\n// frame but barely moved the TOP edge \u2014 Canada's Ellesmere/Axel Heiberg islands already reach\n// ~83\u00B0N, so the map still spent its height on empty Arctic. 75\u00B0N keeps every populated region\n// (Alaska's north coast ~71\u00B0N, Canadian mainland ~72\u00B0N) and cuts the uninhabited island bulk.\n// Safe against geoNaturalEarth1 specifically: it is PSEUDOCYLINDRICAL, so parallels project to\n// straight horizontal lines and a constant-latitude cut renders as an exactly straight edge \u2014\n// no densification needed along the seam.\nexport const NA_LAT_MAX = 75;\n\n// Sutherland\u2013Hodgman against the single half-plane lat <= latMax. Exact in lon/lat space\n// (the boundary is a parallel, i.e. a straight line there), so the only approximation is the\n// projection's own, which for this projection family is none along a parallel.\nfunction clipRingToLat(ring: number[][], latMax: number): number[][] {\n const out: number[][] = [];\n const n = ring.length;\n for (let i = 0; i < n; i++) {\n const cur = ring[i];\n const prev = ring[(i + n - 1) % n];\n const curIn = cur[1] <= latMax;\n const prevIn = prev[1] <= latMax;\n if (curIn !== prevIn) {\n // Crossing: emit the point exactly on the parallel.\n const dy = cur[1] - prev[1];\n const t = dy === 0 ? 0 : (latMax - prev[1]) / dy;\n out.push([prev[0] + t * (cur[0] - prev[0]), latMax]);\n }\n if (curIn) out.push(cur);\n }\n if (out.length && (out[0][0] !== out[out.length - 1][0] || out[0][1] !== out[out.length - 1][1])) {\n out.push(out[0]); // keep the ring closed\n }\n return out;\n}\n\n// Returns the feature clipped to lat <= latMax, or null when nothing survives (a region\n// entirely above the cutoff simply leaves the basemap). Non-polygon geometry passes through\n// untouched \u2014 the NA basemap is polygons only, but this must not silently mangle anything else.\nexport function clipFeatureToLat(feature: any, latMax: number): any | null {\n const g = feature && feature.geometry;\n if (!g) return null;\n\n const clipPolygon = (rings: number[][][]): number[][][] | null => {\n const kept = rings\n .map(r => clipRingToLat(r, latMax))\n .filter(r => r.length >= 4); // a closed ring needs 3 distinct points + the repeat\n // If the OUTER ring is gone the whole polygon is gone, holes included.\n return kept.length && kept[0].length >= 4 ? kept : null;\n };\n\n if (g.type === \"Polygon\") {\n const c = clipPolygon(g.coordinates as number[][][]);\n return c ? { ...feature, geometry: { type: \"Polygon\", coordinates: c } } : null;\n }\n if (g.type === \"MultiPolygon\") {\n const polys = (g.coordinates as number[][][][])\n .map(clipPolygon)\n .filter((p): p is number[][][] => p !== null);\n return polys.length ? { ...feature, geometry: { type: \"MultiPolygon\", coordinates: polys } } : null;\n }\n return feature;\n}\n"],
|
|
5
|
+
"mappings": ";;;AAYO,IAAM,UAAU,oBAAI,IAAI;AAAA,EAC3B;AAAA,EAAO;AAAA,EAAO;AAAA;AAAA,EACd;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA;AAAA,EAC1C;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA;AAC9C,CAAC;AASM,IAAM,aAAa;AAK1B,SAAS,cAAc,MAAkB,QAA4B;AACjE,QAAM,MAAkB,CAAC;AACzB,QAAM,IAAI,KAAK;AACf,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AACxB,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,OAAO,MAAM,IAAI,IAAI,KAAK,CAAC;AACjC,UAAM,QAAQ,IAAI,CAAC,KAAK;AACxB,UAAM,SAAS,KAAK,CAAC,KAAK;AAC1B,QAAI,UAAU,QAAQ;AAElB,YAAM,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC;AAC1B,YAAM,IAAI,OAAO,IAAI,KAAK,SAAS,KAAK,CAAC,KAAK;AAC9C,UAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC;AAAA,IACvD;AACA,QAAI,MAAO,KAAI,KAAK,GAAG;AAAA,EAC3B;AACA,MAAI,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC,MAAM,IAAI,IAAI,SAAS,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,MAAM,IAAI,IAAI,SAAS,CAAC,EAAE,CAAC,IAAI;AAC9F,QAAI,KAAK,IAAI,CAAC,CAAC;AAAA,EACnB;AACA,SAAO;AACX;AAKO,SAAS,iBAAiB,SAAc,QAA4B;AACvE,QAAM,IAAI,WAAW,QAAQ;AAC7B,MAAI,CAAC,EAAG,QAAO;AAEf,QAAM,cAAc,CAAC,UAA6C;AAC9D,UAAM,OAAO,MACR,IAAI,OAAK,cAAc,GAAG,MAAM,CAAC,EACjC,OAAO,OAAK,EAAE,UAAU,CAAC;AAE9B,WAAO,KAAK,UAAU,KAAK,CAAC,EAAE,UAAU,IAAI,OAAO;AAAA,EACvD;AAEA,MAAI,EAAE,SAAS,WAAW;AACtB,UAAM,IAAI,YAAY,EAAE,WAA2B;AACnD,WAAO,IAAI,EAAE,GAAG,SAAS,UAAU,EAAE,MAAM,WAAW,aAAa,EAAE,EAAE,IAAI;AAAA,EAC/E;AACA,MAAI,EAAE,SAAS,gBAAgB;AAC3B,UAAM,QAAS,EAAE,YACZ,IAAI,WAAW,EACf,OAAO,CAAC,MAAyB,MAAM,IAAI;AAChD,WAAO,MAAM,SAAS,EAAE,GAAG,SAAS,UAAU,EAAE,MAAM,gBAAgB,aAAa,MAAM,EAAE,IAAI;AAAA,EACnG;AACA,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|