Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MET-6314 Map Unknown Location Handling #219

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/chart/map/map.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div id="mapChartGlobe"></div>
<div id="mapChart"></div>
<div id="mapChartHidden"></div>
<div id="mapLegend"></div>
8 changes: 8 additions & 0 deletions src/app/chart/map/map.component.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
@import "../../../scss/_variables";

#mapChart,
#mapChartGlobe,
#mapChartHidden {
height: $map-height;
width: 100%;
}

#mapChartGlobe {
left: 0;
right: 0;
min-height: $map-height;
position: absolute;
}

#mapChartHidden {
margin-top: -100%;
visibility: hidden;
Expand Down
78 changes: 77 additions & 1 deletion src/app/chart/map/map.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ describe('MapComponent', () => {
}).compileComponents();
}));

const getFakeChart = (): am4maps.MapChart => {
return {
show: () => {},
hide: () => {},
zoomToRectangle: () => {},
animate: () => {}
} as unknown as am4maps.MapChart;
};

beforeEach(() => {
fixture = TestBed.createComponent(MapComponent);
component = fixture.componentInstance;
component.chart = getFakeChart();
component.chartGlobe = getFakeChart();
component.mapData = [];
fixture.detectChanges();
});
Expand All @@ -38,13 +49,34 @@ describe('MapComponent', () => {
expect(component).toBeTruthy();
});

it('should hide the globe', () => {
spyOn(component.chart, 'show');
spyOn(component.chartGlobe, 'hide');
component.hideGlobe();
expect(component.chart.show).toHaveBeenCalled();
expect(component.chartGlobe.hide).toHaveBeenCalled();
});

it('should show the globe', () => {
spyOn(component.chart, 'hide');
spyOn(component.chartGlobe, 'show');
spyOn(component.chartGlobe, 'animate');

component.showGlobe();
expect(component.chart.hide).toHaveBeenCalled();
expect(component.chartGlobe.show).toHaveBeenCalled();
expect(component.chartGlobe.animate).toHaveBeenCalled();
});

it('should update the data', () => {
component.mapCountries = [];
component.mapData = [{ id: 'IT', value: 1881 }];
expect(component.mapCountries.length).toBeGreaterThan(0);
});

it('should track the selected country', () => {
spyOn(component, 'hideGlobe');
spyOn(component, 'showGlobe');
component.mapData = [{ id: 'IT', value: 1881 }];

spyOn(component.mapCountrySet, 'emit');
Expand All @@ -58,6 +90,11 @@ describe('MapComponent', () => {
component.selectedCountry = undefined;

expect(component.mapCountrySet.emit).toHaveBeenCalledWith(false);
expect(component.hideGlobe).toHaveBeenCalled();
expect(component.showGlobe).not.toHaveBeenCalled();

component.selectedCountry = component.countryUnknown;
expect(component.showGlobe).toHaveBeenCalled();
});

it('should generate the polygon series', () => {
Expand Down Expand Up @@ -103,8 +140,9 @@ describe('MapComponent', () => {
it('should debounce clicks on the country', fakeAsync(() => {
spyOn(component, 'countryClick');
component.countryClickSubject.next('IT');
tick(250);
tick(component.animationTime);
expect(component.countryClick).toHaveBeenCalled();
tick(component.animationTime);
}));

it('should debounce dragging', fakeAsync(() => {
Expand All @@ -116,6 +154,7 @@ describe('MapComponent', () => {

it('should handle clicks on the country', () => {
spyOn(component, 'setCountryInclusion');
spyOn(component, 'hideGlobe');

component.drawChart();
expect(component.selectedCountry).toBeFalsy();
Expand Down Expand Up @@ -150,9 +189,11 @@ describe('MapComponent', () => {

component.countryClick(country);
expect(component.setCountryInclusion).toHaveBeenCalled();
expect(component.hideGlobe).toHaveBeenCalled();
});

it('should track which countries are shown', () => {
spyOn(component, 'hideGlobe');
component.mapData = [{ id: 'IT', value: 1881 }];
spyOn(component.polygonSeries.events, 'once');

Expand All @@ -161,9 +202,11 @@ describe('MapComponent', () => {

expect(component.polygonSeries.events.once).toHaveBeenCalled();
expect(component.selectedCountry).toBeFalsy();
expect(component.hideGlobe).toHaveBeenCalled();
});

it('should morph', () => {
spyOn(component, 'hideGlobe');
component.mapData = [{ id: 'IT', value: 1881 }];
component.setCountryInclusion(['IT', 'DE']);

Expand All @@ -187,5 +230,38 @@ describe('MapComponent', () => {
component.countryMorph('DE');

expect(component.selectedCountry).toEqual('DE');
expect(component.hideGlobe).toHaveBeenCalledTimes(2);
});

it('should detect chart series container events', () => {
component.drawChart();

const spyDragStart = jasmine.createSpy();
const spyDragStop = jasmine.createSpy();

component.chart.seriesContainer.events.on('dragstart', spyDragStart);
component.chart.seriesContainer.events.on('dragstop', spyDragStop);

component.chart.seriesContainer.dispatchImmediately('dragstart');
expect(spyDragStart).toHaveBeenCalled();

component.chart.seriesContainer.dispatchImmediately('dragstop');
expect(spyDragStop).toHaveBeenCalled();
});

it('should detect chart events', () => {
component.drawChart();

const spyOut = jasmine.createSpy();
const spyOver = jasmine.createSpy();

component.chart.events.on('out', spyOut);
component.chart.events.on('over', spyOver);

component.chart.dispatchImmediately('out');
expect(spyOut).toHaveBeenCalled();

component.chart.dispatchImmediately('over');
expect(spyOver).toHaveBeenCalled();
});
});
55 changes: 54 additions & 1 deletion src/app/chart/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MapComponent extends SubscriptionManager {
_mapData: Array<IdValue>;
chart: am4maps.MapChart;
chartHidden: am4maps.MapChart;
chartGlobe: am4maps.MapChart;
mapPercentMode = false;
polygonSeries: am4maps.MapPolygonSeries;
polygonSeriesHidden: am4maps.MapPolygonSeries;
Expand All @@ -59,6 +60,7 @@ export class MapComponent extends SubscriptionManager {

animationTime = 750;
boundingCountries = ['IS', 'TR', 'ES', 'NO'];
countryUnknown = 'EU';
mapCountries = [];

selectedCountryNext?: string;
Expand Down Expand Up @@ -96,6 +98,11 @@ export class MapComponent extends SubscriptionManager {
this.selectedCountryNext = this.mapCountries[indexNext];
this.selectedCountryPrev = this.mapCountries[indexPrev];

if (selectedCountry === this.countryUnknown) {
this.showGlobe();
} else {
this.hideGlobe();
}
this.mapCountrySet.emit(!!selectedCountry);
}

Expand Down Expand Up @@ -130,7 +137,6 @@ export class MapComponent extends SubscriptionManager {

constructor() {
super();
am4core.options.autoDispose = true;

const cst = Object.values(TargetFieldName).reduce(
(ob: ColourSchemeMap, tType: TargetFieldName) => {
Expand Down Expand Up @@ -432,6 +438,26 @@ export class MapComponent extends SubscriptionManager {
this.chartHidden.minZoomLevel = 0.2;
}

hideGlobe(): void {
this.chart.show();
this.chartGlobe.hide();
}

showGlobe(): void {
this.chart.hide();
this.chartGlobe.show();
this.animateLatitude();
}

animateLatitude(): void {
this.chartGlobe.deltaLatitude = -45;
this.chartGlobe.animate(
{ property: 'deltaLatitude', to: 0 },
12000,
am4core.ease.circleOut
);
}

/** drawChart
*
**/
Expand All @@ -442,8 +468,10 @@ export class MapComponent extends SubscriptionManager {
// Create map instance
const chart = am4core.create('mapChart', am4maps.MapChart);
const chartHidden = am4core.create('mapChartHidden', am4maps.MapChart);
const chartGlobe = am4core.create('mapChartGlobe', am4maps.MapChart);
this.chart = chart;
this.chartHidden = chartHidden;
this.chartGlobe = chartGlobe;
this.chart.seriesContainer.resizable = false;

// Set map definition
Expand Down Expand Up @@ -585,6 +613,31 @@ export class MapComponent extends SubscriptionManager {
chart.seriesContainer.events.on('dragstop', () => {
this.dragEndSubject.next(true);
});

chartGlobe.events.on('ready', () => {
this.hideGlobe();

chartGlobe.deltaLongitude = -45;
chartGlobe.projection = new am4maps.projections.Orthographic();
chartGlobe.series.push(new am4maps.MapPolygonSeries()).useGeodata = true;
chartGlobe.seriesContainer.resizable = false;
chartGlobe.seriesContainer.draggable = false;

chartGlobe.animate({ property: 'deltaLongitude', to: 100050 }, 20000000);

setTimeout(() => {
chartGlobe.geodata = am4geodata_worldHigh;
const label = chartGlobe.chartAndLegendContainer.createChild(
am4core.Label
);
label.text = 'location unknown';
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
label.fontSize = 20;
label.fontWeight = 'bold';
label.align = 'center';
label.fill = am4core.color('#4d4d4d');
label.padding(110, 0, 0, 0);
}, this.animationTime);
});
}

getBoundingCoords(countryIds: Array<string>): Array<number> {
Expand Down
3 changes: 2 additions & 1 deletion src/app/landing/landing.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ a[disabled] {
}

.map-container {
width: 100%;
position: relative;
max-width: 100%;
width: 100%;

& + .data-rows {
width: 100%;
Expand Down
Loading