From 8997c1bbfc6102f774da9e42ccd9c88df6febb9a Mon Sep 17 00:00:00 2001 From: RafaelSzmarowski Date: Fri, 29 Sep 2023 12:00:28 +0200 Subject: [PATCH] Move legend to utils folder --- .../stories/Legend/CategoryLegendTemplate.tsx | 21 --------------- .../Legend/CategoryLegend.stories.tsx | 26 ++++++++++++++----- .../src/components/Chart/Chart.svelte | 4 +-- .../src/components/Chart/legend.ts | 2 +- .../src/components/Chart/types.ts | 2 +- .../src/components/Legend/index.ts | 9 ------- .../src/components/Map/WebGl/MapRender.svelte | 4 +-- .../src/components/Map/types.ts | 2 +- .../src/components/MapPoi/MapRender.svelte | 4 +-- .../src/components/MapPoi/types.ts | 2 +- .../{ => utils}/Legend/CategoryLegend.svelte | 0 .../Item/CategoryLegendItem.svelte | 0 .../Item/CategoryLegendItemLabel.svelte | 0 .../Item/CategoryLegendItemSymbol.svelte | 0 .../CategoryLegend/Symbols/BoxSymbol.svelte | 0 .../Symbols/CircleSymbol.svelte | 0 .../CategoryLegend/Symbols/LineSymbol.svelte | 0 .../{ => utils}/Legend/ColorsLegend.svelte | 4 +-- .../components/{ => utils}/Legend/types.ts | 2 +- .../SvelteUtilsImpl.ts} | 4 +-- .../src/components/utils/index.ts | 9 ++++++- packages/visualizations/src/index.ts | 4 +-- 22 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 packages/visualizations-react/stories/Legend/CategoryLegendTemplate.tsx rename packages/visualizations-react/stories/{ => UtilsComponents}/Legend/CategoryLegend.stories.tsx (58%) delete mode 100644 packages/visualizations/src/components/Legend/index.ts rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Item/CategoryLegendItem.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Item/CategoryLegendItemLabel.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Item/CategoryLegendItemSymbol.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Symbols/BoxSymbol.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Symbols/CircleSymbol.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/CategoryLegend/Symbols/LineSymbol.svelte (100%) rename packages/visualizations/src/components/{ => utils}/Legend/ColorsLegend.svelte (98%) rename packages/visualizations/src/components/{ => utils}/Legend/types.ts (97%) rename packages/visualizations/src/components/{SvelteSimpleImpl.ts => utils/SvelteUtilsImpl.ts} (94%) diff --git a/packages/visualizations-react/stories/Legend/CategoryLegendTemplate.tsx b/packages/visualizations-react/stories/Legend/CategoryLegendTemplate.tsx deleted file mode 100644 index 41296045..00000000 --- a/packages/visualizations-react/stories/Legend/CategoryLegendTemplate.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; -import { ComponentStory } from '@storybook/react'; -import { CategoryLegendType } from '@opendatasoft/visualizations'; -import { CategoryLegend } from '../../src'; -import { SimpleProps } from '../../src/components/Props'; - -const CategoryLegendTemplate: ComponentStory = ( - args: SimpleProps -) => ( -
- -
-); - -export default CategoryLegendTemplate; \ No newline at end of file diff --git a/packages/visualizations-react/stories/Legend/CategoryLegend.stories.tsx b/packages/visualizations-react/stories/UtilsComponents/Legend/CategoryLegend.stories.tsx similarity index 58% rename from packages/visualizations-react/stories/Legend/CategoryLegend.stories.tsx rename to packages/visualizations-react/stories/UtilsComponents/Legend/CategoryLegend.stories.tsx index a610f07c..e6cb17d4 100644 --- a/packages/visualizations-react/stories/Legend/CategoryLegend.stories.tsx +++ b/packages/visualizations-react/stories/UtilsComponents/Legend/CategoryLegend.stories.tsx @@ -1,18 +1,32 @@ -import { ComponentMeta } from '@storybook/react'; +import React from 'react'; +import { ComponentMeta, ComponentStory } from '@storybook/react'; import type { CategoryLegendType } from '@opendatasoft/visualizations'; import { CATEGORY_ITEM_VARIANT } from '@opendatasoft/visualizations'; -import { CategoryLegend } from '../../src'; -import { SimpleProps } from '../../src/components/Props'; -import CategoryLegendTemplate from './CategoryLegendTemplate'; +import { CategoryLegend } from '../../../src'; +import { SimpleProps } from '../../../src/components/Props'; const meta: ComponentMeta = { - title: 'Legend', + title: 'Utils/Legend', component: CategoryLegend, }; export default meta; -export const CategoryCircleLegend = CategoryLegendTemplate.bind({}); +const Template: ComponentStory = ( + args: SimpleProps +) => ( +
+ +
+); + +export const CategoryCircleLegend = Template.bind({}); const CategoryCircleLegendArgs: SimpleProps = { legendOptions: { type: 'category' as const, diff --git a/packages/visualizations/src/components/Chart/Chart.svelte b/packages/visualizations/src/components/Chart/Chart.svelte index c6285416..b51261dc 100644 --- a/packages/visualizations/src/components/Chart/Chart.svelte +++ b/packages/visualizations/src/components/Chart/Chart.svelte @@ -8,8 +8,8 @@ import { generateId } from '../utils'; import SourceLink from '../utils/SourceLink.svelte'; import { defaultNumberFormat } from '../utils/formatter'; - import CategoryLegend from '../Legend/CategoryLegend.svelte'; - import type { LegendPositions, CategoryLegendType } from '../Legend/types'; + import CategoryLegend from '../utils/Legend/CategoryLegend.svelte'; + import type { LegendPositions, CategoryLegendType } from '../utils/Legend/types'; import { ChartSeriesType } from './types'; import type { ChartOptions, ChartSeries } from './types'; import { defaultValue } from './utils'; diff --git a/packages/visualizations/src/components/Chart/legend.ts b/packages/visualizations/src/components/Chart/legend.ts index e63cbc9a..2cbf185a 100644 --- a/packages/visualizations/src/components/Chart/legend.ts +++ b/packages/visualizations/src/components/Chart/legend.ts @@ -3,7 +3,7 @@ import type { _DeepPartialObject } from 'chart.js/types/utils'; import type { ChartOptions } from './types'; import { assureMaxLength } from '../utils/formatter'; import { defaultValue, DEFAULT_GREY_COLOR } from './utils'; -import { CATEGORY_ITEM_VARIANT } from '../Legend/types'; +import { CATEGORY_ITEM_VARIANT } from '../utils/Legend/types'; const LEGEND_MAX_LENGTH = 50; diff --git a/packages/visualizations/src/components/Chart/types.ts b/packages/visualizations/src/components/Chart/types.ts index ebc21f10..86992eec 100644 --- a/packages/visualizations/src/components/Chart/types.ts +++ b/packages/visualizations/src/components/Chart/types.ts @@ -1,5 +1,5 @@ import type { Color, Source } from '../types'; -import type { LegendConfiguration } from '../Legend/types'; +import type { LegendConfiguration } from '../utils/Legend/types'; export interface ChartOptions { /** Specify label column in DataFrame */ diff --git a/packages/visualizations/src/components/Legend/index.ts b/packages/visualizations/src/components/Legend/index.ts deleted file mode 100644 index 3403eaea..00000000 --- a/packages/visualizations/src/components/Legend/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import CategoryLegendImpl from './CategoryLegend.svelte'; -import SvelteSimpleImpl from '../SvelteSimpleImpl'; -import type { CategoryLegendType } from './types'; - -export default class CategoryLegendComponent extends SvelteSimpleImpl { - protected getSvelteSimpleComponentClass(): typeof CategoryLegendImpl { - return CategoryLegendImpl; - } -} \ No newline at end of file diff --git a/packages/visualizations/src/components/Map/WebGl/MapRender.svelte b/packages/visualizations/src/components/Map/WebGl/MapRender.svelte index 3b05cfee..2420bf9d 100644 --- a/packages/visualizations/src/components/Map/WebGl/MapRender.svelte +++ b/packages/visualizations/src/components/Map/WebGl/MapRender.svelte @@ -17,11 +17,11 @@ import type { BBox } from 'geojson'; import SourceLink from '../../utils/SourceLink.svelte'; import { computeMaxZoomFromGeoJsonFeatures, getFixedTooltips } from '../utils'; - import ColorsLegend from '../../Legend/ColorsLegend.svelte'; + import ColorsLegend from '../../utils/Legend/ColorsLegend.svelte'; import BackButton from '../../utils/BackButton.svelte'; import MiniMap from '../../utils/MiniMap.svelte'; import type { ColorScale, DataBounds, Source } from '../../types'; - import type { LegendVariant } from '../../Legend/types'; + import type { LegendVariant } from '../../utils/Legend/types'; import type { ChoroplethFixedTooltipDescription, MapLayer, diff --git a/packages/visualizations/src/components/Map/types.ts b/packages/visualizations/src/components/Map/types.ts index 24ca1943..f574eb22 100644 --- a/packages/visualizations/src/components/Map/types.ts +++ b/packages/visualizations/src/components/Map/types.ts @@ -1,7 +1,7 @@ import type { Feature, FeatureCollection, Position, BBox } from 'geojson'; import type { FillLayerSpecification, Popup } from 'maplibre-gl'; import type { DebouncedFunc } from 'lodash'; -import type { LegendPositions } from '../Legend/types'; +import type { LegendPositions } from '../utils/Legend/types'; import type { ColorScale, Color, Source } from '../types'; export interface ChoroplethOptions { diff --git a/packages/visualizations/src/components/MapPoi/MapRender.svelte b/packages/visualizations/src/components/MapPoi/MapRender.svelte index 578765a9..f91b73aa 100644 --- a/packages/visualizations/src/components/MapPoi/MapRender.svelte +++ b/packages/visualizations/src/components/MapPoi/MapRender.svelte @@ -4,8 +4,8 @@ import type { BBox } from 'geojson'; import type { LngLatBoundsLike, LngLatLike, MapOptions, StyleSpecification } from 'maplibre-gl'; import { onDestroy, onMount } from 'svelte'; - import CategoryLegend from '../Legend/CategoryLegend.svelte'; - import type { CategoryLegendType } from '../Legend/types'; + import CategoryLegend from '../utils/Legend/CategoryLegend.svelte'; + import type { CategoryLegendType } from '../utils/Legend/types'; import SourceLink from '../utils/SourceLink.svelte'; import type { Source } from '../types'; diff --git a/packages/visualizations/src/components/MapPoi/types.ts b/packages/visualizations/src/components/MapPoi/types.ts index cd26a052..773e45ca 100644 --- a/packages/visualizations/src/components/MapPoi/types.ts +++ b/packages/visualizations/src/components/MapPoi/types.ts @@ -7,7 +7,7 @@ import type { import type { BBox, GeoJsonProperties } from 'geojson'; import type { Color, Source } from '../types'; -import type { CategoryLegendType } from '../Legend/types'; +import type { CategoryLegendType } from '../utils/Legend/types'; // To render data layers on the map export type PoiMapData = Partial<{ diff --git a/packages/visualizations/src/components/Legend/CategoryLegend.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItem.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItem.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItem.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItem.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItemLabel.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItemLabel.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItemLabel.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItemLabel.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItemSymbol.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItemSymbol.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Item/CategoryLegendItemSymbol.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Item/CategoryLegendItemSymbol.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Symbols/BoxSymbol.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/BoxSymbol.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Symbols/BoxSymbol.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/BoxSymbol.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Symbols/CircleSymbol.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/CircleSymbol.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Symbols/CircleSymbol.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/CircleSymbol.svelte diff --git a/packages/visualizations/src/components/Legend/CategoryLegend/Symbols/LineSymbol.svelte b/packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/LineSymbol.svelte similarity index 100% rename from packages/visualizations/src/components/Legend/CategoryLegend/Symbols/LineSymbol.svelte rename to packages/visualizations/src/components/utils/Legend/CategoryLegend/Symbols/LineSymbol.svelte diff --git a/packages/visualizations/src/components/Legend/ColorsLegend.svelte b/packages/visualizations/src/components/utils/Legend/ColorsLegend.svelte similarity index 98% rename from packages/visualizations/src/components/Legend/ColorsLegend.svelte rename to packages/visualizations/src/components/utils/Legend/ColorsLegend.svelte index 8321f1ac..e4eadcbd 100644 --- a/packages/visualizations/src/components/Legend/ColorsLegend.svelte +++ b/packages/visualizations/src/components/utils/Legend/ColorsLegend.svelte @@ -3,9 +3,9 @@