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

[SC-44672][FEAT] Add new legend symbol: Image #204

Merged
merged 1 commit into from
Nov 24, 2023
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
69 changes: 42 additions & 27 deletions packages/visualizations-react/stories/Poi/PoiMap.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,50 @@ const citiesColorMatch = {

const bbox: BBox = [-6.855469, 41.343825, 11.645508, 51.37178];

const legendCitiesItems = [
{
label: 'Paris',
color: citiesColorMatch.colors.Paris,
borderColor: citiesColorMatch.borderColors.Paris,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Nantes',
color: citiesColorMatch.colors.Nantes,
borderColor: citiesColorMatch.borderColors.Nantes,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Bordeaux',
color: citiesColorMatch.colors.Bordeaux,
borderColor: citiesColorMatch.borderColors.Bordeaux,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Marseille',
color: citiesColorMatch.colors.Marseille,
borderColor: citiesColorMatch.borderColors.Marseille,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
];

const legendbattleItems = [
{
variant: CATEGORY_ITEM_VARIANT.Image,
label: 'Battle of Verdun',
src: 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Battle_icon_gladii_red.svg/14px-Battle_icon_gladii_red.svg.png',
},
{
variant: CATEGORY_ITEM_VARIANT.Image,
label: 'Battle of the Somme',
src: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Big_battle_symbol.svg/14px-Big_battle_symbol.svg.png',
},
];

const legend = {
type: 'category' as const,
title: 'French cities',
items: [
{
label: 'Paris',
color: citiesColorMatch.colors.Paris,
borderColor: citiesColorMatch.borderColors.Paris,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Nantes',
color: citiesColorMatch.colors.Nantes,
borderColor: citiesColorMatch.borderColors.Nantes,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Bordeaux',
color: citiesColorMatch.colors.Bordeaux,
borderColor: citiesColorMatch.borderColors.Bordeaux,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
{
label: 'Marseille',
color: citiesColorMatch.colors.Marseille,
borderColor: citiesColorMatch.borderColors.Marseille,
variant: CATEGORY_ITEM_VARIANT.Circle,
},
],
title: 'French cities and famous battles',
items: [...legendCitiesItems, ...legendbattleItems],
align: 'start' as const,
};

Expand Down
KevinFabre-ods marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import BoxSymbol from '../Symbols/BoxSymbol.svelte';
import LineSymbol from '../Symbols/LineSymbol.svelte';
import CircleSymbol from '../Symbols/CircleSymbol.svelte';
import ImageSymbol from '../Symbols/ImageSymbol.svelte';
import type { CategoryItem } from '../../types';
import { CATEGORY_ITEM_VARIANT } from '../../types';

Expand All @@ -12,6 +13,8 @@
<CircleSymbol {item} />
{:else if item.variant === CATEGORY_ITEM_VARIANT.Box}
<BoxSymbol {item} />
{:else}
{:else if item.variant === CATEGORY_ITEM_VARIANT.Line}
<LineSymbol {item} />
{:else if item.variant === CATEGORY_ITEM_VARIANT.Image}
<ImageSymbol {item} />
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import type { ImageCategoryItem } from '../../types';

export let item: ImageCategoryItem;
</script>

<!-- svelte-ignore a11y-missing-attribute -->
<img src={item.src} />

<style>
img {
width: 16px;
margin-right: 6px;
object-fit: contain;
}
</style>
12 changes: 11 additions & 1 deletion packages/visualizations/src/components/Legend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const CATEGORY_ITEM_VARIANT = {
Circle: 'circle',
Line: 'line',
Box: 'box',
Image: 'image',
} as const;

type BaseCategoryItem = {
Expand Down Expand Up @@ -56,7 +57,16 @@ export type LineCategoryItem = BaseCategoryItem & {
dashed?: boolean;
};

export type CategoryItem = CircleCategoryItem | BoxCategoryItem | LineCategoryItem;
export type ImageCategoryItem = BaseCategoryItem & {
variant: typeof CATEGORY_ITEM_VARIANT.Image;
src: string;
};

export type CategoryItem =
| CircleCategoryItem
| BoxCategoryItem
| LineCategoryItem
| ImageCategoryItem;

export type CategoryLegend = {
type: 'category';
Expand Down
Loading