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

[FEAT][EXPLO][SC-46279] Table - Geo field #245

Merged
Show file tree
Hide file tree
Changes from 16 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build-ci": "npm ci --workspaces --include-workspace-root --install-links",
"test": "lerna run test --parallel --no-bail",
"watch": "lerna run watch --parallel --stream",
"lint": "lerna run lint:prettier:check,lint:eslint:check --parallel --no-bail",
"lint": "lerna run lint:prettier:check,lint:eslint:check,lint:svelte:check --parallel --no-bail",
"lint:fix": "lerna run lint:prettier:fix,lint:eslint:fix --parallel --no-bail",
"build-package-lock": "lerna run build-package-lock",
"storybook": "lerna run --scope=@opendatasoft/visualizations-react storybook"
Expand Down
4 changes: 2 additions & 2 deletions packages/visualizations-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
MarkdownTextProps,
ChoroplethGeoJsonProps,
ChoroplethVectorTilesProps,
MapPoiProps,
PoiMapProps,
TableProps,
} from '@opendatasoft/visualizations';
import reactifySvelte from 'reactify';
Expand All @@ -39,5 +39,5 @@ export const ChoroplethSvg = reactifySvelte<ChoroplethGeoJsonProps>(
_ChoroplethSvg,
'ods-visualizations-choropleth-svg'
);
export const PoiMap = reactifySvelte<MapPoiProps>(_PoiMap, 'ods-visualizations-poi-map');
export const PoiMap = reactifySvelte<PoiMapProps>(_PoiMap, 'ods-visualizations-poi-map');
export const Table = reactifySvelte<TableProps>(_Table, 'ods-visualizations-table');
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const meta: ComponentMeta<typeof PoiMap> = {

export default meta;

const Template: ComponentStory<typeof PoiMap> = (args) => (
const Template: ComponentStory<typeof PoiMap> = args => (
<div
style={{
width: '50%',
Expand Down
2 changes: 1 addition & 1 deletion packages/visualizations-react/stories/Poi/sources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { PoiMapData } from '@opendatasoft/visualizations';

const sources : PoiMapData["sources"] = {
const sources : Required<PoiMapData>["value"]["sources"] = {
cities : {
type: 'geojson',
data: {
Expand Down
9 changes: 9 additions & 0 deletions packages/visualizations-react/stories/Table/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default [
wordCount: 1200,
readingTime: 5.5,
url: 'https://example.com/lorem-ipsum',
geopoint: [2.357573,48.837904],
},
{
title: 'pellentesque nec blog post',
Expand All @@ -19,6 +20,7 @@ export default [
wordCount: 800,
readingTime: 3.8,
url: 'https://example.com/pellentesque-nec',
geopoint: [2.357573,48.837904],
},
{
title: 'fusce sit amet blog post',
Expand All @@ -30,6 +32,7 @@ export default [
wordCount: 1500,
readingTime: 7.2,
url: 'https://example.com/fusce-sit-amet',
geopoint: [2.357573,48.837904],
},
{
title: 'vestibulum nec blog post',
Expand All @@ -40,6 +43,7 @@ export default [
wordCount: 1000,
readingTime: 4.5,
url: 'https://example.com/vestibulum-nec',
geopoint: [2.357573,48.837904],
},
{
title: 'Cras At Blog Post',
Expand All @@ -51,6 +55,7 @@ export default [
wordCount: 1300,
readingTime: 6.0,
url: 'https://example.com/cras-at',
geopoint: [2.357573,48.837904],
},
{
title: 'Quisque A Blog Post',
Expand All @@ -62,6 +67,7 @@ export default [
wordCount: 900,
readingTime: 4.0,
url: 'https://example.com/quisque-a',
geopoint: [2.357573,48.837904],
},
{
title: 'Ut Vitae Blog Post',
Expand All @@ -73,6 +79,7 @@ export default [
wordCount: 1100,
readingTime: 5.0,
url: 'https://example.com/ut-vitae',
geopoint: [2.357573,48.837904],
},
{
title: 'Integer Id Blog Post',
Expand All @@ -84,6 +91,7 @@ export default [
wordCount: 950,
readingTime: 4.2,
url: 'https://example.com/integer-id',
geopoint: [2.357573,48.837904],
},
{
title: 'Undefined row',
Expand All @@ -94,6 +102,7 @@ export default [
wordCount: undefined,
readingTime: null,
url: undefined,
geopoint: undefined,
},
{
title: 'Empty row',
Expand Down
37 changes: 37 additions & 0 deletions packages/visualizations-react/stories/Table/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,43 @@ export const columns: Column[] = [
display: () => 'link',
},
},
{
title: 'Geo point',
key: 'geopoint',
dataFormat: 'geo',
options: {
mapOptions: {
style: 'https://demotiles.maplibre.org/style.json',
interactive: false,
},
display: (v: unknown) => `longitude: ${(v as number[])[0]}, latitude: ${(v as number[])[1]}`,
sources: (coordinates: unknown) => ({
'table-stories' : {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
id: 1,
type: 'Feature',
geometry: {
type: 'Point',
coordinates,
},
},
],
}
},
}),
layers: () => ([{
id:'table-stories-layer',
source: 'table-stories',
type: 'circle',
color: 'black',
borderColor: 'white',
}])
},
},
];

const options: TableOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<svelte:options immutable={true} />

<script lang="ts">
import maplibregl, {
Map as MapType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'maplibre-gl/dist/maplibre-gl.css';

export { default as ChoroplethGeoJson } from './ChoroplethGeoJson.svelte';
export { default as ChoroplethVectorTiles } from './ChoroplethVectorTiles.svelte';
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<svelte:options immutable={true} />

<script lang="ts">
import { onDestroy } from 'svelte';
import { debounce } from 'lodash';
Expand Down
86 changes: 86 additions & 0 deletions packages/visualizations/src/components/Map/Poi/Poi.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<script lang="ts">
import CategoryLegend from '../../Legend/CategoryLegend.svelte';
import SourceLink from '../../utils/SourceLink.svelte';
import WelGlMap from '../WebGl';

import type { PoiMapProps } from './types';
import { DEFAULT_ASPECT_RATIO } from './constants';

// ensure exported type matches declared props
type $$Props = PoiMapProps;

export let data: $$Props['data'];
export let options: $$Props['options'];

// Used in front of console and error messages to debug multiple maps on a same page
const mapId = Math.floor(Math.random() * 1000);

$: ({
title,
subtitle,
description,
legend,
sourceLink,
aspectRatio = DEFAULT_ASPECT_RATIO,
} = options);

$: cssVarStyles = `--aspect-ratio:${aspectRatio};`;
</script>

<figure class="map-card maps-container" style={cssVarStyles}>
{#if title || subtitle}
<figcaption>
{#if title}
<h3>
{title}
</h3>
{/if}
{#if subtitle}
<p>
{subtitle}
</p>
{/if}
</figcaption>
{/if}
<div class="main" aria-describedby={description ? mapId.toString() : undefined}>
{#key options.style}
<WelGlMap {options} data={data.value} />
{/key}
</div>
{#if description}
<p id={mapId.toString()} class="a11y-invisible-description">{description}</p>
{/if}
{#if legend}
<CategoryLegend legendOptions={legend} />
{/if}
{#if sourceLink}
<SourceLink source={sourceLink} />
{/if}
</figure>

<style>
.map-card {
display: flex;
flex-direction: column;
margin: 0;
position: relative;
}
figcaption {
margin: 0 0 1em 0;
}
figcaption p,
figcaption h3 {
margin: 0;
}

.main {
aspect-ratio: var(--aspect-ratio);
flex-grow: 1;
position: relative;
display: block;
}
/* Suitable for elements that are used via aria-describedby or aria-labelledby */
.a11y-invisible-description {
display: none;
}
</style>
2 changes: 2 additions & 0 deletions packages/visualizations/src/components/Map/Poi/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export const DEFAULT_ASPECT_RATIO = 1;
3 changes: 3 additions & 0 deletions packages/visualizations/src/components/Map/Poi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PoiMap from './Poi.svelte';

export default PoiMap;
20 changes: 20 additions & 0 deletions packages/visualizations/src/components/Map/Poi/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Async } from '../../../types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this import is useless

Copy link
Contributor Author

@KevinFabre-ods KevinFabre-ods Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Why ?
It is used at line 6

export type PoiMapData = Async<WebGlMapData>;

import type { Source } from '../../types';
import type { WebGlMapData, WebGlMapOptions } from '../WebGl/types';
import type { CategoryLegend } from '../../Legend/types';

export type PoiMapData = Async<WebGlMapData>;

export type PoiMapOptions = WebGlMapOptions & {
title?: string;
subtitle?: string;
description?: string;
legend?: CategoryLegend;
/** Link button to source */
sourceLink?: Source;
};

export type PoiMapProps = {
data: PoiMapData;
options: PoiMapOptions;
};
Loading
Loading