Skip to content

Commit ee48641

Browse files
matschafferamotl
authored andcommitted
Revert "Support multiple metrics in popup content (#77)"
This reverts commit 5e7ae9f.
1 parent 1aa9e82 commit ee48641

File tree

3 files changed

+7
-53
lines changed

3 files changed

+7
-53
lines changed

src/worldmap.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,6 @@ describe('Worldmap', () => {
138138
});
139139
});
140140

141-
describe('when the data has multiple metrics', () => {
142-
beforeEach(() => {
143-
ctrl.data = new DataBuilder()
144-
.withCountryAndValue('SE', 1, {
145-
__field_device_urn: 'safecast:903348716',
146-
'__field_ingest.location': 'wecnv3p07bjj',
147-
'__field_Average pms_pm02_5': 33,
148-
'__field_Average lnd_7318u': 110,
149-
})
150-
.build();
151-
152-
ctrl.panel.esGeoPoint = 'ingest.location';
153-
ctrl.panel.esLocationName = 'device_urn';
154-
ctrl.panel.esMetric = 'Average pms_pm02_5';
155-
worldMap.drawCircles();
156-
});
157-
158-
it('should create a circle popup with additional metrics', () => {
159-
expect(worldMap.circles[0]._popup._content).toBe('Sweden: 1 <br />Average lnd_7318u: 110');
160-
});
161-
});
162-
163141
describe('when the data has three points', () => {
164142
beforeEach(() => {
165143
ctrl.data = new DataBuilder()

src/worldmap.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default class WorldMap {
296296
});
297297

298298
this.createClickthrough(circle, dataPoint);
299-
const content = this.getPopupContent(dataPoint);
299+
const content = this.getPopupContent(dataPoint.locationName, dataPoint.valueRounded);
300300
this.createPopup(circle, content);
301301
return circle;
302302
}
@@ -318,7 +318,7 @@ export default class WorldMap {
318318

319319
// Re-create popup.
320320
circle.unbindPopup();
321-
const content = this.getPopupContent(dataPoint);
321+
const content = this.getPopupContent(dataPoint.locationName, dataPoint.valueRounded);
322322
this.createPopup(circle, content);
323323

324324
// Re-create clickthrough-link.
@@ -417,16 +417,12 @@ export default class WorldMap {
417417
extendPopupContent(circle, dataPoint) {
418418
const popup = circle.getPopup();
419419
let popupContent = popup._content;
420-
popupContent += `\n${this.getPopupContent(dataPoint)}`;
420+
popupContent += `\n${this.getPopupContent(dataPoint.locationName, dataPoint.valueRounded)}`;
421421
circle.setPopupContent(popupContent);
422422
}
423423

424-
getPopupContent(dataPoint) {
424+
getPopupContent(locationName, value) {
425425
let unit;
426-
427-
let locationName = dataPoint.locationName;
428-
let value = dataPoint.value;
429-
430426
if (_.isNaN(value)) {
431427
value = 'n/a';
432428
} else {
@@ -436,27 +432,7 @@ export default class WorldMap {
436432
if (this.ctrl.settings.formatOmitEmptyValue && value === 'n/a') {
437433
return `${locationName}`.trim();
438434
} else {
439-
let fieldPrefix = '__field_';
440-
441-
let specialFields = [
442-
fieldPrefix + this.ctrl.settings.esLocationName,
443-
fieldPrefix + this.ctrl.settings.esMetric,
444-
fieldPrefix + this.ctrl.settings.esGeoPoint,
445-
];
446-
447-
let freeDataFields = Object.keys(dataPoint).filter(
448-
(key: string) => key.startsWith(fieldPrefix) && !specialFields.includes(key)
449-
);
450-
451-
let freeDataDisplay = freeDataFields
452-
.map((field: string) => {
453-
let name = field.slice(fieldPrefix.length);
454-
let value = dataPoint[field];
455-
return `<br />${name}: ${value}`;
456-
})
457-
.join('');
458-
459-
return `${locationName}: ${value} ${unit || ''}${freeDataDisplay}`.trim();
435+
return `${locationName}: ${value} ${unit || ''}`.trim();
460436
}
461437
}
462438

test/data_builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class DataBuilder {
77
this.data.categories = [];
88
}
99

10-
withCountryAndValue(countryCode, value, overrides?: {[key: string]: any}) {
10+
withCountryAndValue(countryCode, value) {
1111
let dataPoint;
1212
if (countryCode === 'SE') {
1313
dataPoint = {
@@ -39,7 +39,7 @@ export default class DataBuilder {
3939
} else {
4040
throw new Error(`Unable to create fixture for country code ${countryCode}`);
4141
}
42-
this.data.push({...dataPoint, ...overrides});
42+
this.data.push(dataPoint);
4343

4444
return this;
4545
}

0 commit comments

Comments
 (0)