From eab1f6eddac27d1e999e6188fbafe4c54b36d245 Mon Sep 17 00:00:00 2001 From: thinkinggis Date: Wed, 27 May 2020 14:57:09 +0800 Subject: [PATCH] fix(district): contry layer --- examples/district/basic/demo/world_map.js | 4 +-- examples/district/bubble/demo/world_map.js | 4 +-- packages/district/src/layer/country.ts | 4 ++- packages/utils/__tests__/statistic.spec.ts | 35 ++++++++++++++++++---- packages/utils/src/statistics.ts | 6 ++-- stories/Draw/Components/DrawLine.tsx | 3 +- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/examples/district/basic/demo/world_map.js b/examples/district/basic/demo/world_map.js index 3bf88ac21c..1d2f01a7e6 100644 --- a/examples/district/basic/demo/world_map.js +++ b/examples/district/basic/demo/world_map.js @@ -32,12 +32,12 @@ scene.on('loaded', () => { label: { enable: true, textAllowOverlap: false, - field: 'Short_Name_ZH' + field: 'NAME_CHN' }, popup: { enable: false, Html: props => { - return `${props.Short_Name_ZH}`; + return `${props.NAME_CHN}`; } } }); diff --git a/examples/district/bubble/demo/world_map.js b/examples/district/bubble/demo/world_map.js index 0191718de6..6e011f10d6 100644 --- a/examples/district/bubble/demo/world_map.js +++ b/examples/district/bubble/demo/world_map.js @@ -33,12 +33,12 @@ scene.on('loaded', () => { label: { enable: true, textAllowOverlap: false, - field: 'Short_Name_ZH' + field: 'NAME_CHN' }, popup: { enable: false, Html: props => { - return `${props.Short_Name_ZH}`; + return `${props.NAME_CHN}`; } } }); diff --git a/packages/district/src/layer/country.ts b/packages/district/src/layer/country.ts index ec043820b7..a282ddced9 100644 --- a/packages/district/src/layer/country.ts +++ b/packages/district/src/layer/country.ts @@ -24,7 +24,9 @@ export default class CountryLayer extends BaseLayer { } protected async addProvinceFill() { const { depth } = this.options; - const countryConfig = getDataConfig(this.options.geoDataLevel).CHN[depth]; + const countryConfig = getDataConfig(this.options.geoDataLevel).country.CHN[ + depth + ]; const fillData = await this.fetchData(countryConfig.fill); this.addFillLayer(fillData); } diff --git a/packages/utils/__tests__/statistic.spec.ts b/packages/utils/__tests__/statistic.spec.ts index bea992c0a2..e0fbfc9d0d 100644 --- a/packages/utils/__tests__/statistic.spec.ts +++ b/packages/utils/__tests__/statistic.spec.ts @@ -1,10 +1,35 @@ -import { sum } from '../src/statistics'; -describe('sum', () => { - it('sum string array', () => { - const a = ['1', '2', '3']; - const b = [1, 2, 3]; +import { max, mean, min, mode, sum } from '../src/statistics'; +const a = ['1', '2', '3']; +const b = [1, 2, 3]; +const c = [1, 2, 3, '1', 2, '3', 3]; +describe('statistic', () => { + it('sum', () => { // @ts-ignore expect(sum(a)).toEqual(6); expect(sum(b)).toEqual(6); }); + it('max', () => { + // @ts-ignore + expect(max(a)).toEqual(3); + expect(max(b)).toEqual(3); + }); + + it('min', () => { + // @ts-ignore + expect(min(a)).toEqual(1); + expect(min(b)).toEqual(1); + }); + + it('mean', () => { + // @ts-ignore + expect(mean(a)).toEqual(2); + // @ts-ignore + expect(mean(b)).toEqual(2); + }); + + it('mode', () => { + // @ts-ignore + expect(mode(a)).toEqual(1); + expect(mode(c)).toEqual(2); + }); }); diff --git a/packages/utils/src/statistics.ts b/packages/utils/src/statistics.ts index 31f4e2d6db..9a3a05ad7c 100644 --- a/packages/utils/src/statistics.ts +++ b/packages/utils/src/statistics.ts @@ -14,7 +14,7 @@ function max(x: number[]) { value = x[i]; } } - return value; + return value * 1; } function min(x: number[]) { @@ -30,7 +30,7 @@ function min(x: number[]) { value = x[i]; } } - return value; + return value * 1; } function sum(x: number[]) { @@ -81,7 +81,7 @@ function mode(x: any[]) { seenThis++; } } - return value; + return value * 1; } export { sum, max, min, mean, mode }; diff --git a/stories/Draw/Components/DrawLine.tsx b/stories/Draw/Components/DrawLine.tsx index f9b3148cc5..3cd564279a 100644 --- a/stories/Draw/Components/DrawLine.tsx +++ b/stories/Draw/Components/DrawLine.tsx @@ -21,8 +21,7 @@ export default class Circle extends React.Component { }), }); this.scene = scene; - - scene.on('loaded', () => { + const line = scene.on('loaded', () => { const drawLine = new DrawLine(scene); drawLine.enable(); });