|
59 | 59 |
|
60 | 60 | export let showAnnotations = true;
|
61 | 61 |
|
| 62 | + export let showNeighbors = true; |
| 63 | +
|
62 | 64 | let showFull = expandableWindow === 'full';
|
63 | 65 |
|
64 | 66 | /**
|
|
104 | 106 | region,
|
105 | 107 | date,
|
106 | 108 | timeFrame,
|
107 |
| - { height, zero, raw, isMobile, singleRegionOnly, domain, cumulative }, |
| 109 | + { height, zero, raw, isMobile, singleRegionOnly, domain, cumulative, showNeighbors }, |
108 | 110 | ) {
|
109 | 111 | const isWeekly = sensor.value.isWeeklySignal;
|
110 | 112 | const options = {
|
|
134 | 136 | if (region.level === 'county') {
|
135 | 137 | // county vs related vs state vs nation
|
136 | 138 | const state = getStateOfCounty(region);
|
137 |
| - return generateCompareLineSpec( |
138 |
| - [region.displayName, neighboringInfo.displayName, state.displayName, nationInfo.displayName], |
139 |
| - options, |
140 |
| - ); |
| 139 | + const regions = [region.displayName, state.displayName, nationInfo.displayName]; |
| 140 | + if (showNeighbors) { |
| 141 | + regions.splice(1, 0, neighboringInfo.displayName); |
| 142 | + } |
| 143 | + return generateCompareLineSpec(regions, options); |
141 | 144 | }
|
142 | 145 | if (region.level !== 'nation') {
|
143 | 146 | return generateCompareLineSpec([region.displayName, nationInfo.displayName], options);
|
|
150 | 153 | * @param {import("../stores/params").DateParam} date
|
151 | 154 | * @param {import("../stores/params").RegionParam} region
|
152 | 155 | */
|
153 |
| - function loadData(sensor, region, timeFrame, singleRegionOnly) { |
| 156 | + function loadData(sensor, region, timeFrame, singleRegionOnly, showNeighbors) { |
154 | 157 | if (!region.value) {
|
155 | 158 | return null;
|
156 | 159 | }
|
|
163 | 166 | const data = [selfData];
|
164 | 167 |
|
165 | 168 | if (region.level === 'county') {
|
| 169 | + if (showNeighbors) { |
| 170 | + const relatedCounties = getRelatedCounties(region.value); |
| 171 | + const relatedData = fetcher |
| 172 | + .fetch1SensorNRegionsNDates(sensor, relatedCounties, timeFrame) |
| 173 | + .then((r) => averageByDate(r, neighboringInfo)) |
| 174 | + .then((r) => addMissing(r, sensor.isWeeklySignal ? 'week' : 'day')); |
| 175 | + data.push(relatedData); |
| 176 | + } |
166 | 177 | const state = getStateOfCounty(region);
|
167 | 178 | const stateData = fetcher.fetch1Sensor1RegionNDates(sensor, state, timeFrame);
|
168 |
| - const relatedCounties = getRelatedCounties(region.value); |
169 |
| - const relatedData = fetcher |
170 |
| - .fetch1SensorNRegionsNDates(sensor, relatedCounties, timeFrame) |
171 |
| - .then((r) => averageByDate(r, sensor, neighboringInfo)) |
172 |
| - .then((r) => addMissing(r, sensor)); |
173 |
| - data.push(relatedData, stateData); |
| 179 | + data.push(stateData); |
174 | 180 | }
|
175 | 181 | if (region.level !== 'nation') {
|
176 | 182 | data.push(fetcher.fetch1Sensor1RegionNDates(sensor, nationInfo, timeFrame));
|
177 | 183 | }
|
178 |
| - return Promise.all(data).then((rows) => rows.reverse().flat()); |
| 184 | + return Promise.all(data).then((rows) => { |
| 185 | + return rows.reverse().flat(); |
| 186 | + }); |
179 | 187 | }
|
180 | 188 |
|
181 | 189 | /**
|
|
221 | 229 | }
|
222 | 230 | }
|
223 | 231 |
|
224 |
| - function resolveRegions(region, singleRegionOnly) { |
| 232 | + function resolveRegions(region, singleRegionOnly, showNeighbors) { |
225 | 233 | if (singleRegionOnly) {
|
226 | 234 | return [region];
|
227 | 235 | }
|
228 | 236 | if (region.level === 'county') {
|
229 | 237 | // county vs related vs state vs nation
|
230 | 238 | const state = getStateOfCounty(region);
|
231 |
| - return [region, neighboringInfo, state, nationInfo]; |
| 239 | + const regions = [region, state, nationInfo]; |
| 240 | + if (showNeighbors) { |
| 241 | + regions.splice(1, 0, neighboringInfo); |
| 242 | + } |
| 243 | + return regions; |
232 | 244 | }
|
233 | 245 | if (region.level !== 'nation') {
|
234 | 246 | // state vs nation
|
|
273 | 285 |
|
274 | 286 | $: raw = singleRaw && sensor.rawValue != null && !($isMobileDevice && showFull);
|
275 | 287 | $: cumulative = raw && singleCumulative && sensor.rawCumulativeValue != null;
|
276 |
| - $: regions = raw ? [region.value] : resolveRegions(region.value, singleRegionOnly); |
| 288 | + $: regions = raw ? [region.value] : resolveRegions(region.value, singleRegionOnly, showNeighbors); |
277 | 289 | $: annotations = showAnnotations
|
278 | 290 | ? $annotationManager.getWindowAnnotations(sensor.value, regions, timeFrame.min, timeFrame.max)
|
279 | 291 | : [];
|
|
286 | 298 | singleRegionOnly,
|
287 | 299 | domain,
|
288 | 300 | cumulative,
|
| 301 | + showNeighbors, |
289 | 302 | }),
|
290 | 303 | timeFrame,
|
291 | 304 | annotations,
|
292 | 305 | );
|
293 | 306 | $: data = raw
|
294 | 307 | ? loadSingleData(sensor, region, timeFrame, { cumulative })
|
295 |
| - : loadData(sensor, region, timeFrame, singleRegionOnly); |
| 308 | + : loadData(sensor, region, timeFrame, singleRegionOnly, showNeighbors); |
296 | 309 | $: fileName = generateFileName(sensor, regions, timeFrame, raw, cumulative);
|
297 | 310 |
|
298 | 311 | function findValue(region, data, date, prop = 'value') {
|
|
0 commit comments