Repository navigation
Expand file tree
/
Copy pathdataLayers.js
More file actions
309 lines (294 loc) · 10.7 KB
/
Copy pathdataLayers.js
File metadata and controls
309 lines (294 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import { GRADUATED_COLORS, TARIFF_NAME_CODES } from './constants.js';
export const GRADUATED_SIZES = [5, 9, 15, 24, 34];
// ---------------------------------------------------------------------------
// Layer specs — one entry per tariff CODE (must match TARIFF_NAME_CODES values)
//
// `subject` completes the sentence "Estimated % of <who> directly exposed to ___"
// `breaks` are the choropleth/centroid class breaks. Percent suffixes (_1/_2/_3)
// are FRACTIONS (0.05 = 5%); count suffixes (_B/_E/_C) are raw counts.
//
// ScenAfter = 'after September 29' ∪ nonCUSMA
// ScenBefore = 'before September 29' ∪ nonCUSMA
// The bare 'after September 29' / 'before September 29' columns still exist in the
// pmtiles but are NOT scenario totals — they exclude non-CUSMA exposure. They are
// deliberately absent from this file so they can't be selected.
//
// Section 338 is three codes, not one:
// S338_Tar = codes actually subject to the Section 338 tariff (652 HS codes)
// S338_Exc = codes carved out / exempt from it (24 HS codes)
// S338_Tot = Tariffed + Excluded, the full Section 338 universe (676 HS codes)
// S338_Tot equals Dairy ∪ Alcohol ∪ Motor exactly, and Motor dominates it, so
// Tot/Tar breaks are sized off Motor rather than off the broad Total/Scen scale
// the old single 'Section 338' spec was (incorrectly) copied from.
// ---------------------------------------------------------------------------
const LAYER_SPECS = [
{
code: 'Total',
subject: "all types of U.S. Administration's Tariffs on Canada",
breaks: {
_1: [0.05, 0.1, 0.2, 0.3],
_2: [0.04, 0.1, 0.2, 0.4],
_3: [0.05, 0.1, 0.2, 0.5],
_B: [10, 50, 100, 200],
_E: [500, 1000, 2500, 5000],
_C: [400, 700, 1000, 1500],
},
},
{
code: 'ScenAfter',
subject: 'all tariffs in effect after September 29, 2026',
breaks: {
_1: [0.05, 0.1, 0.2, 0.3],
_2: [0.04, 0.1, 0.2, 0.4],
_3: [0.05, 0.1, 0.2, 0.5],
_B: [10, 50, 100, 200],
_E: [500, 1000, 2500, 5000],
_C: [400, 700, 1000, 1500],
},
},
{
code: 'ScenBefore',
subject: 'all tariffs in effect prior to September 29, 2026',
breaks: {
_1: [0.05, 0.1, 0.2, 0.3],
_2: [0.05, 0.1, 0.2, 0.4],
_3: [0.05, 0.1, 0.2, 0.5],
_B: [10, 50, 100, 200],
_E: [500, 1000, 2500, 5000],
_C: [400, 700, 1000, 1500],
},
},
{
code: 'CUSMA',
subject: "U.S. Administration's non-CUSMA Compliant Tariffs on Canada",
breaks: {
_1: [0.05, 0.1, 0.2, 0.3],
_2: [0.05, 0.1, 0.2, 0.4],
_3: [0.05, 0.1, 0.2, 0.5],
_B: [10, 50, 100, 200],
_E: [500, 1000, 2500, 5000],
_C: [400, 700, 1000, 1500],
},
},
{
code: 'S338_Tot',
subject: 'Section 338 tariffs (goods tariffed and excluded combined)',
breaks: {
_1: [0.01, 0.04, 0.08, 0.2],
_2: [0.01, 0.04, 0.08, 0.2],
_3: [0.01, 0.04, 0.08, 0.2],
_B: [10, 50, 100, 200],
_E: [200, 500, 1000, 2000],
_C: [200, 500, 1000, 2000],
},
},
{
code: 'S338_Tar',
subject: 'goods subject to Section 338 tariffs',
breaks: {
_1: [0.01, 0.04, 0.08, 0.2],
_2: [0.01, 0.04, 0.08, 0.2],
_3: [0.01, 0.04, 0.08, 0.2],
_B: [10, 50, 100, 200],
_E: [200, 500, 1000, 2000],
_C: [200, 500, 1000, 2000],
},
},
{
code: 'S338_Exc',
subject: 'goods excluded from Section 338 tariffs',
breaks: {
_1: [0.002, 0.005, 0.01, 0.02],
_2: [0.002, 0.005, 0.01, 0.02],
_3: [0.002, 0.005, 0.01, 0.02],
_B: [1, 2, 5, 10],
_E: [10, 50, 100, 250],
_C: [10, 50, 100, 250],
},
},
{
code: 'Motor',
subject: "U.S. Administration's Motor Vehicle Tariffs on Canada",
breaks: {
_1: [0.01, 0.04, 0.08, 0.2],
_2: [0.01, 0.04, 0.08, 0.2],
_3: [0.01, 0.04, 0.08, 0.2],
_B: [10, 50, 100, 200],
_E: [200, 500, 1000, 2000],
_C: [200, 500, 1000, 2000],
},
},
{
code: 'Dairy',
subject: "U.S. Administration's Dairy Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.04],
_2: [0.01, 0.02, 0.03, 0.04],
_3: [0.01, 0.02, 0.03, 0.04],
_B: [2, 5, 10, 20],
_E: [25, 100, 250, 500],
_C: [25, 100, 200, 500],
},
},
{
code: 'Alcohol',
subject: "U.S. Administration's Alcohol Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.04],
_2: [0.01, 0.02, 0.03, 0.04],
_3: [0.01, 0.02, 0.03, 0.04],
_B: [2, 5, 10, 20],
_E: [25, 100, 250, 500],
_C: [25, 100, 200, 500],
},
},
{
code: 'Auto',
subject: "U.S. Administration's Automobile Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.06],
_2: [0.01, 0.04, 0.08, 0.2],
_3: [0.01, 0.02, 0.05, 0.2],
_B: [5, 10, 20, 50],
_E: [200, 500, 1000, 2000],
_C: [50, 100, 250, 500],
},
},
{
code: 'Alum',
subject: "U.S. Administration's Aluminum Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.05],
_2: [0.01, 0.05, 0.1, 0.2],
_3: [0.01, 0.03, 0.07, 0.2],
_B: [5, 10, 20, 50],
_E: [200, 500, 1000, 2000],
_C: [50, 100, 250, 500],
},
},
{
code: 'Steel',
subject: "U.S. Administration's Steel Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.07],
_2: [0.01, 0.05, 0.1, 0.3],
_3: [0.01, 0.05, 0.1, 0.25],
_B: [5, 10, 20, 50],
_E: [200, 500, 1000, 2000],
_C: [50, 100, 250, 500],
},
},
{
code: 'Cop',
subject: "U.S. Administration's Copper Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.04],
_2: [0.01, 0.02, 0.04, 0.08],
_3: [0.01, 0.02, 0.03, 0.04],
_B: [2, 5, 10, 20],
_E: [200, 500, 1000, 2000],
_C: [10, 25, 50, 100],
},
},
{
code: 'LumOld',
subject: "U.S. Administration's Lumber Tariffs on Canada (before Oct 14, 2025)",
breaks: {
_1: [0.01, 0.02, 0.07, 0.15],
_2: [0.01, 0.05, 0.1, 0.2],
_3: [0.01, 0.03, 0.08, 0.2],
_B: [2, 5, 10, 20],
_E: [25, 100, 250, 500],
_C: [25, 100, 200, 500],
},
},
{
code: 'LumNew',
subject: "U.S. Administration's Lumber Tariffs on Canada (after Oct 14, 2025)",
breaks: {
_1: [0.01, 0.02, 0.07, 0.15],
_2: [0.01, 0.05, 0.1, 0.2],
_3: [0.01, 0.03, 0.08, 0.2],
_B: [2, 5, 10, 20],
_E: [25, 100, 250, 500],
_C: [25, 100, 200, 500],
},
},
{
code: 'MHDV',
subject: "U.S. Administration's Medium Heavy Duty Vehicles Tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.04],
_2: [0.01, 0.02, 0.03, 0.04],
_3: [0.01, 0.02, 0.03, 0.04],
_B: [2, 5, 10, 20],
_E: [50, 100, 250, 500],
_C: [25, 100, 200, 500],
},
},
{
code: 'Ene',
subject: "U.S. Administration's Energy and natural resources tariffs on Canada",
breaks: {
_1: [0.01, 0.02, 0.03, 0.08],
_2: [0.01, 0.05, 0.1, 0.2],
_3: [0.01, 0.03, 0.08, 0.2],
_B: [5, 10, 20, 50],
_E: [50, 100, 250, 1000],
_C: [25, 100, 200, 500],
},
},
];
// ---------------------------------------------------------------------------
// Expansion — builds the flat { "Auto_1": {...}, ... } object the map consumes.
// `tariffType` is always set to the CODE, which is what mapSelected matches on.
// ---------------------------------------------------------------------------
const SUFFIXES = {
_1: { metricType: 'Percent', impactType: 'Business', who: 'businesses' },
_2: { metricType: 'Percent', impactType: 'EmployeeWork', who: 'employees (by work location)' },
_3: { metricType: 'Percent', impactType: 'EmployeeHome', who: 'employees (by primary residence)' },
_B: { metricType: 'Count', impactType: 'Business', who: 'businesses' },
_E: { metricType: 'Count', impactType: 'EmployeeWork', who: 'employees (by work location)' },
_C: { metricType: 'Count', impactType: 'EmployeeHome', who: 'employees (by primary residence)' },
};
function buildDataLayers() {
const layers = {};
for (const spec of LAYER_SPECS) {
for (const [suffix, meta] of Object.entries(SUFFIXES)) {
const breaks = spec.breaks[suffix];
if (!breaks) continue;
const key = `${spec.code}${suffix}`;
const lead = meta.metricType === 'Percent'
? `Estimated % of ${meta.who}`
: `Estimated count of ${meta.who}`;
layers[key] = {
dataSource: key,
metricType: meta.metricType,
impactType: meta.impactType,
tariffType: spec.code,
breaks,
colours: GRADUATED_COLORS,
text: `${lead} directly exposed to ${spec.subject}`,
...(meta.metricType === 'Count' ? { size: GRADUATED_SIZES } : {}),
};
}
}
return layers;
}
export const DATA_LAYERS = buildDataLayers();
// ---------------------------------------------------------------------------
// Dev-only consistency check. Catches the class of bug where a dropdown option
// maps to a code that has no layer (silently logs "no matching data layer").
// ---------------------------------------------------------------------------
if (import.meta.env?.DEV) {
const specCodes = new Set(LAYER_SPECS.map((s) => s.code));
const dropdownCodes = new Set(Object.values(TARIFF_NAME_CODES));
const missing = [...dropdownCodes].filter((c) => !specCodes.has(c));
if (missing.length) {
console.warn('[dataLayers] dropdown codes with no layer spec:', missing);
}
const unreachable = [...specCodes].filter((c) => !dropdownCodes.has(c));
if (unreachable.length) {
console.warn('[dataLayers] layer specs not reachable from the dropdown:', unreachable);
}
}