Skip to content

Commit

Permalink
feat(mark): add path, geoView, choropleth
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Nov 4, 2022
1 parent e940261 commit 9f844d8
Show file tree
Hide file tree
Showing 26 changed files with 7,410 additions and 4 deletions.
45 changes: 45 additions & 0 deletions __tests__/integration/charts/airports-point-choropleth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { csv } from 'd3-fetch';
import { feature, mesh } from 'topojson';
import { autoType } from 'd3-dsv';
import { G2Spec } from '../../../src';

export async function airportsPointChoropleth(): Promise<G2Spec> {
const us = await fetch('data/us-10m.json').then((res) => res.json());
const airports = await csv('data/airports.csv', autoType);
const states = feature(us, us.objects.states);
const statesmesh = mesh(us, us.objects.states);
return {
type: 'geoView',
projection: {
type: 'albersUsa',
},
children: [
{
type: 'choropleth',
data: {
value: {
feature: states,
border: statesmesh,
},
},
style: {
featureFill: 'lightgray',
borderStroke: 'white',
},
},
{
type: 'point',
data: airports,
encode: {
y: 'latitude',
x: 'longitude',
color: 'steelblue',
shape: 'point',
},
style: {
r: 2,
},
},
],
};
}
40 changes: 40 additions & 0 deletions __tests__/integration/charts/hale-choropleth-world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { csv } from 'd3-fetch';
import { feature, mesh } from 'topojson';
import { autoType } from 'd3-dsv';
import { G2Spec } from '../../../src';

export async function haleChoroplethWorld(): Promise<G2Spec> {
const world = await fetch('data/countries-50m.json').then((res) =>
res.json(),
);
const hale = await csv('data/hale.csv', autoType);
const countries = feature(world, world.objects.countries);
const coutriesmesh = mesh(world, world.objects.countries);
return {
type: 'choropleth',
width: 1000,
padding: 10,
projection: {
type: 'equalEarth',
},
data: {
value: {
lookup: hale,
feature: countries,
border: coutriesmesh,
outline: { type: 'Sphere' },
},
},
scale: {
color: {
type: 'sequential',
palette: 'ylGnBu',
},
},
encode: {
value: 'hale',
lookupKey: 'name',
featureKey: (d) => d.properties.name,
},
};
}
3 changes: 3 additions & 0 deletions __tests__/integration/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ export { alphabetIntervalDataDrivenStyled } from './alphabet-interval-data-drive
export { unemploymentAreaStackedDataDrivenStyled } from './unemployment-area-stacked-data-driven-styled';
export { energySankeyDefaults } from './energy-sankey-defaults';
export { energySankeyCustom } from './energy-sankey-custom';
export { airportsPointChoropleth } from './airports-point-choropleth';
export { unemploymentChoropleth } from './unemployment-choropleth';
export { haleChoroplethWorld } from './hale-choropleth-world';
34 changes: 34 additions & 0 deletions __tests__/integration/charts/unemployment-choropleth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { tsv } from 'd3-fetch';
import { feature } from 'topojson';
import { autoType } from 'd3-dsv';
import { G2Spec } from '../../../src';

export async function unemploymentChoropleth(): Promise<G2Spec> {
const us = await fetch('data/us-10m.json').then((res) => res.json());
const unemployment = await tsv('data/unemployment.tsv', autoType);
const counties = feature(us, us.objects.counties);
return {
type: 'choropleth',
projection: {
type: 'albersUsa',
},
data: {
value: {
lookup: unemployment,
feature: counties,
},
},
scale: {
color: {
type: 'sequential',
palette: 'ylGnBu',
unknown: '#fff',
},
},
encode: {
value: 'rate',
lookupKey: 'id',
featureKey: 'id',
},
};
}
3,377 changes: 3,377 additions & 0 deletions __tests__/integration/data/airports.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions __tests__/integration/data/countries-50m.json

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions __tests__/integration/data/hale.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name,hale
Afghanistan,53
Albania,68.1
Algeria,65.5
Andorra,NaN
Angola,55.8
Antigua and Barb.,67
Argentina,68.4
Armenia,66.3
Australia,73
Austria,72.4
Azerbaijan,64.9
Bahamas,66.8
Bahrain,68.1
Bangladesh,63.3
Barbados,67
Belarus,65.5
Belgium,71.6
Belize,62.5
Benin,53.5
Bhutan,60.7
Bolivia,63
Bosnia and Herz.,67.2
Botswana,57.5
Brazil,66
Brunei,67.9
Bulgaria,66.4
Burkina Faso,52.9
Burundi,52.6
Cabo Verde,64.5
Cambodia,60.8
Cameroon,51.1
Canada,73.2
Central African Rep.,44.9
Chad,47.2
Chile,69.7
China,68.7
Colombia,67.1
Comoros,56.6
Congo,56.7
Cook Is.,NaN
Costa Rica,70.9
Côte d'Ivoire,48.3
Croatia,69
Cuba,69.9
Cyprus,73.3
Czechia,69.3
North Korea,64.6
Dem. Rep. Congo,52.5
Denmark,71.8
Djibouti,56.6
Dominica,NaN
Dominican Rep.,65.2
Ecuador,67.9
Egypt,61.1
El Salvador,65.5
Eq. Guinea,53.8
Eritrea,57.4
Estonia,68.2
Ethiopia,57.5
Fiji,61.3
Finland,71.7
France,73.4
Gabon,58.7
Gambia,54.4
Georgia,64.9
Germany,71.6
Ghana,56.4
Greece,72
Grenada,64.7
Guatemala,64.2
Guinea,52.2
Guinea-Bissau,51.7
Guyana,58.3
Haiti,55.3
Honduras,66.8
Hungary,66.8
Iceland,73
India,59.3
Indonesia,61.7
Iran,65.4
Iraq,59
Ireland,72.1
Israel,72.9
Italy,73.2
Jamaica,66.9
Japan,74.8
Jordan,66.4
Kazakhstan,63.4
Kenya,58.9
Kiribati,57.8
Kuwait,66.3
Kyrgyzstan,63.5
Laos,57.9
Latvia,66.2
Lebanon,66.1
Lesotho,46.6
Liberia,54.5
Libya,62.3
Lithuania,66.1
Luxembourg,72.6
Madagascar,58.3
Malawi,56.2
Malaysia,66.6
Maldives,69.8
Mali,50.7
Malta,72.2
Marshall Is.,NaN
Mauritania,56.4
Mauritius,65.8
Mexico,67.7
Micronesia,61.1
Monaco,NaN
Mongolia,61.9
Montenegro,68.1
Morocco,65.3
Mozambique,52.2
Myanmar,58.4
Namibia,55.9
Nauru,NaN
Nepal,61.3
Netherlands,72.1
New Zealand,72.8
Nicaragua,66.9
Niger,52.5
Nigeria,48.9
Niue,NaN
Norway,73
Oman,65.6
Pakistan,57.7
Palau,NaN
Panama,69.4
Papua New Guinea,58
Paraguay,65.3
Peru,67.5
Philippines,61.7
Poland,68.5
Portugal,72
Qatar,68.6
South Korea,73
Moldova,63.6
Romania,66.6
Russia,63.5
Rwanda,59.9
St. Kitts and Nevis,NaN
Saint Lucia,66.4
St. Vin. and Gren.,63.4
Samoa,66
San Marino,NaN
São Tomé and Principe,60.7
Saudi Arabia,65.7
Senegal,58.8
Serbia,67.4
Seychelles,65.7
Sierra Leone,47.6
Singapore,76.2
Slovakia,68.3
Slovenia,70.5
Solomon Is.,61.9
Somalia,50
South Africa,55.7
S. Sudan,50.6
Spain,73.8
Sri Lanka,66.8
Sudan,55.7
Suriname,63.2
eSwatini,50.2
Sweden,72.4
Switzerland,73.5
Syria,55.8
Tajikistan,63.5
Thailand,66.8
Macedonia,67.1
Timor-Leste,59.2
Togo,53.9
Tonga,64.3
Trinidad and Tobago,63.3
Tunisia,66.3
Turkey,66
Turkmenistan,61.4
Tuvalu,NaN
Uganda,54.9
Ukraine,64
United Arab Emirates,66.7
United Kingdom,71.9
Tanzania,56.5
United States of America,68.5
Uruguay,68.8
Uzbekistan,64.5
Vanuatu,62.7
Venezuela,66.1
Vietnam,67.5
Yemen,55.1
Zambia,54.3
Zimbabwe,54.4

0 comments on commit 9f844d8

Please sign in to comment.