Skip to content

Commit e3e06da

Browse files
committed
Add mapPalette URL parameter
The mapping between the palette and the temperature anomalies can either be computed on a per-region basis (`per-region`, default) or for a single region (index) that is then applied to the whole dataset. Using a single dataset as a reference makes it easier to compare temperature anomalies of different regions by color. Otherwise, the same temperature anomaly might be displayed in different colors for different regions.
1 parent 583a215 commit e3e06da

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ valid:
3333
app starts. Note that the region index is with respect to the order in the dataset.
3434
- `palette` (`'berkeleyEarth'`, `'edHawkins'`, default: `'edHawkins'`): Temperature anomaly color palette.
3535
See `/src/js/palettes.js`.
36+
- `mapPalette` (`'per-region'`, `<number>`, default: `'per-region'`): The temperature anomalies are mapped to the
37+
palette. If `'per-region'`, compute the mapping for each regio individually. This can lead to the same temperature
38+
anomalies being assigned different colors for different regions. If `<number>`, use the mapping computed for the
39+
respective region in the dataset. This provides a more uniform view onto the dataset and makes it easier to compare
40+
temperature anomalies of different regions by color.
3641
- `highContrast` (`<boolean>`, default: `false`): Invert text brightness for dark temperature anomaly colors.
3742
- `prevRegionKey` (`<string>`, [JS key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values),
3843
default: `'ArrowLeft'`): Key that selects the previous region.

src/js/options/defaultOptions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const warmingNavigator = {
1515
initialYear: 'random', // 'first', 'last', 'random', <number>
1616
initialRegion: 'random', // 'first', 'last', 'random', <number>
1717
palette: 'edHawkins', // see ../palettes.js
18-
highContrast: false,
18+
mapPalette: 'per-region', // 'per-region', <number>
19+
highContrast: false, // <boolean>
1920
};
2021

2122
export const keyboard = {

src/js/options/optionParsers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const warmingNavigator = {
9494
initialYear: intOrStringsParser('first', 'last', 'random'),
9595
initialRegion: intOrStringsParser('first', 'last', 'random'),
9696
palette: paletteParser(),
97+
mapPalette: intOrStringsParser('per-region'),
9798
highContrast: booleanParser(),
9899
};
99100

src/js/wn/model.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ function sortedMapping(data, language) {
1616
}
1717

1818
export default class Model {
19-
constructor(data, minYear, maxYear, lang, sort) {
19+
constructor(
20+
data,
21+
minYear,
22+
maxYear,
23+
lang,
24+
sort,
25+
shift = undefined,
26+
scale = undefined,
27+
) {
2028
this.data = data;
2129
this.minYear = minYear;
2230
this.maxYear = maxYear;
2331
this.language = lang;
2432
this.sort = true;
2533
this.regionMapping = (sort ? sortedMapping : identityMapping)(data, lang);
34+
this.shift = shift;
35+
this.scale = scale;
2636
}
2737

2838
_getRegion(regionIndex) {
@@ -75,7 +85,8 @@ export default class Model {
7585
? region.anomalies[indexForYear]
7686
: null;
7787

78-
const { shift, scale } = region;
88+
const shift = this.shift ?? region.shift;
89+
const scale = this.scale ?? region.scale;
7990
const relativeAnomaly = anomaly === null ? null : (anomaly - shift) * scale;
8091

8192
const uncertainty =

src/js/wn/option-processor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function processOther(data, options) {
137137
sort: options.sort,
138138
singleCellView: options.singleCellView,
139139
gridView: options.gridView,
140+
mapPalette: options.mapPalette,
140141
highContrast: options.highContrast,
141142
};
142143
}
@@ -159,7 +160,7 @@ export default function processOptions(data, optionsNoDefaults) {
159160
const inputs = processInputs(options);
160161
const gridViewElement = processGridViewElement(options);
161162

162-
const { sort, highContrast } = processOther(data, options);
163+
const { sort, mapPalette, highContrast } = processOther(data, options);
163164

164165
return {
165166
initialRegion,
@@ -175,6 +176,7 @@ export default function processOptions(data, optionsNoDefaults) {
175176
gridViewElement,
176177

177178
sort,
179+
mapPalette,
178180
highContrast,
179181
};
180182
}

src/js/wn/warming-navigator.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,27 @@ export default class WarmingNavigator {
2323
gridViewElement,
2424

2525
sort,
26+
mapPalette,
2627
highContrast,
2728
} = this.processedOptions;
2829

29-
const model = new Model(data, minYear, maxYear, language, sort);
30+
const shift =
31+
typeof mapPalette === 'number'
32+
? data.regions[mapPalette].shift
33+
: undefined;
34+
const scale =
35+
typeof mapPalette === 'number'
36+
? data.regions[mapPalette].scale
37+
: undefined;
38+
const model = new Model(
39+
data,
40+
minYear,
41+
maxYear,
42+
language,
43+
sort,
44+
shift,
45+
scale,
46+
);
3047

3148
const rySelector = new RYSelectorClass({
3249
numRegions: model.getNumRegions(),
@@ -44,6 +61,7 @@ export default class WarmingNavigator {
4461
rySelector,
4562
language,
4663
palette,
64+
mapPalette,
4765
highContrast,
4866
);
4967
views.push(singleRecordView);
@@ -56,6 +74,7 @@ export default class WarmingNavigator {
5674
rySelector,
5775
language,
5876
palette,
77+
mapPalette,
5978
highContrast,
6079
);
6180
views.push(gridView);

0 commit comments

Comments
 (0)