@reuters-graphics/graphics-components 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ export type LegendMode = 'threshold' | 'continuous' | 'diverging' | 'categorical' | 'proportional-symbols';
2
+ /** A formatter that turns a numeric value into a display string. */
3
+ export type LegendFormatter = (value: number) => string;
4
+ /**
5
+ * A threshold/diverging bin. Define at least one of `from`/`to`. Colors are
6
+ * passed through directly, so use any CSS color or design token.
7
+ */
8
+ export interface LegendItem {
9
+ /** CSS color for the bin or category swatch. */
10
+ color: string;
11
+ /** Lower bound of the bin (inclusive). Omit for an open-ended first bin. */
12
+ from?: number | null;
13
+ /** Upper bound of the bin (exclusive). Omit for an open-ended last bin. */
14
+ to?: number | null;
15
+ /** Optional explicit label. Generated from the bounds when omitted. */
16
+ label?: string;
17
+ }
18
+ /** A continuous gradient stop. */
19
+ export interface LegendStop {
20
+ /** Numeric position of the stop along the domain. */
21
+ value: number;
22
+ /** CSS color at this stop. */
23
+ color: string;
24
+ /** Optional explicit label. */
25
+ label?: string;
26
+ }
27
+ /** A continuous-mode axis tick. */
28
+ export interface LegendTick {
29
+ /** Numeric position of the tick along the domain. */
30
+ value: number;
31
+ /** Optional explicit label. Formatted from `value` when omitted. */
32
+ label?: string;
33
+ }
34
+ /** The highlighted center of a diverging legend. */
35
+ export interface LegendMidpoint {
36
+ /** Numeric value of the midpoint within the legend domain. */
37
+ value: number;
38
+ /** Optional explicit label. Formatted from `value` when omitted. */
39
+ label?: string;
40
+ }
41
+ /** A proportional-symbols entry. */
42
+ export interface LegendSymbolItem {
43
+ /** Non-negative numeric value mapped to circle area. */
44
+ value: number;
45
+ /** Optional explicit label. Formatted from `value` when omitted. */
46
+ label?: string;
47
+ }
48
+ /** Fallback swatch for missing/unknown values. */
49
+ export interface LegendNoData {
50
+ /** Label shown next to the fallback swatch. */
51
+ label: string;
52
+ /** Optional CSS color for the fallback swatch. */
53
+ color?: string;
54
+ }
55
+ import type { ContainerWidth } from '../@types/global';
56
+ interface Props {
57
+ /** Optional legend heading displayed above the scale. */
58
+ title?: string;
59
+ /** Optional subtitle displayed beneath the title. */
60
+ subtitle?: string;
61
+ /** Legend rendering mode. */
62
+ mode?: LegendMode;
63
+ /**
64
+ * Legend entries. Threshold/diverging modes use numeric bounds and colors;
65
+ * categorical mode uses label and color pairs; proportional-symbols mode
66
+ * uses numeric values and optional labels.
67
+ */
68
+ items?: LegendItem[] | LegendSymbolItem[];
69
+ /** Ordered continuous color stops with numeric values. */
70
+ stops?: LegendStop[];
71
+ /** Optional tick values and labels for continuous mode. */
72
+ ticks?: LegendTick[];
73
+ /** Diverging midpoint with a numeric value and optional label. */
74
+ midpoint?: LegendMidpoint | null;
75
+ /** Optional formatter applied to numeric values. */
76
+ formatter?: LegendFormatter | null;
77
+ /** Optional fallback swatch for missing values. */
78
+ noData?: LegendNoData | null;
79
+ /** Width of the legend within the text well. */
80
+ width?: ContainerWidth;
81
+ }
82
+ /**
83
+ * `Legend` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-graphics-legend--docs)
84
+ *
85
+ * Quantitative and categorical legend for maps and data displays.
86
+ *
87
+ * Renders one of five legend types:
88
+ * - `threshold`: discrete bins with color swatches
89
+ * - `continuous`: a continuous gradient with ticks
90
+ * - `diverging`: threshold bins with a highlighted midpoint
91
+ * - `categorical`: square swatches with labels in a horizontal row
92
+ * - `proportional-symbols`: nested circles with leader lines and labels
93
+ *
94
+ * The component is presentational and can be placed anywhere in page layout. The
95
+ * optional `noData` prop renders a separate fallback swatch for missing, unknown,
96
+ * or unavailable values across all legend modes.
97
+ */
98
+ declare const Legend: import("svelte").Component<Props, {}, "">;
99
+ type Legend = ReturnType<typeof Legend>;
100
+ export default Legend;
@@ -79,6 +79,12 @@
79
79
  textWidth?: ContainerWidth;
80
80
  /** Callback function that receives the map instance when ready */
81
81
  onMapReady?: (map: maplibregl.Map) => void;
82
+ /**
83
+ * Optional content rendered inside the map's `GraphicBlock`, directly above
84
+ * the map. Use it to share a single block — with one title and the standard
85
+ * spacing — between the map and an accompanying element such as a `Legend`.
86
+ */
87
+ legend?: Snippet;
82
88
  /** Child components (e.g., TileMapLayer) */
83
89
  children?: Snippet;
84
90
  }
@@ -99,6 +105,7 @@
99
105
  width = 'normal',
100
106
  textWidth = 'normal',
101
107
  onMapReady,
108
+ legend,
102
109
  children,
103
110
  }: Props = $props();
104
111
 
@@ -174,6 +181,11 @@
174
181
  </script>
175
182
 
176
183
  <GraphicBlock {width} {textWidth} {title} {description} {notes}>
184
+ {#if legend}
185
+ <div class="map-legend">
186
+ {@render legend()}
187
+ </div>
188
+ {/if}
177
189
  <div class="map" {id}>
178
190
  <div
179
191
  bind:this={mapContainer}
@@ -196,4 +208,9 @@
196
208
  width: 100%;
197
209
  position: relative;
198
210
  }
211
+
212
+ /* Sit the legend snug above the map, sharing the block's spacing. */
213
+ .map-legend {
214
+ margin-bottom: 0.5rem;
215
+ }
199
216
  </style>
@@ -59,6 +59,12 @@ interface Props {
59
59
  textWidth?: ContainerWidth;
60
60
  /** Callback function that receives the map instance when ready */
61
61
  onMapReady?: (map: maplibregl.Map) => void;
62
+ /**
63
+ * Optional content rendered inside the map's `GraphicBlock`, directly above
64
+ * the map. Use it to share a single block — with one title and the standard
65
+ * spacing — between the map and an accompanying element such as a `Legend`.
66
+ */
67
+ legend?: Snippet;
62
68
  /** Child components (e.g., TileMapLayer) */
63
69
  children?: Snippet;
64
70
  }
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export { default as InlineAd } from './components/AdSlot/InlineAd.svelte';
29
29
  export { default as KinesisLogo } from './components/KinesisLogo/KinesisLogo.svelte';
30
30
  export { default as LanguageButton } from './components/LanguageButton/LanguageButton.svelte';
31
31
  export { default as LeaderboardAd } from './components/AdSlot/LeaderboardAd.svelte';
32
+ export { default as Legend } from './components/Legend/Legend.svelte';
32
33
  export { default as TileMap } from './components/TileMap/TileMap.svelte';
33
34
  export { default as TileMapLayer } from './components/TileMap/TileMapLayer.svelte';
34
35
  export { default as PaddingReset } from './components/PaddingReset/PaddingReset.svelte';
@@ -59,3 +60,4 @@ export { default as Video } from './components/Video/Video.svelte';
59
60
  export { default as Visible } from './components/Visible/Visible.svelte';
60
61
  export type { ContainerWidth, HeadlineSize, ScrollerVideoInstance, } from './components/@types/global';
61
62
  export type { GeocodeOptions, GeocodeFeature, GeocodeFeatureType, } from './components/Geocoder/geocode';
63
+ export type { LegendMode, LegendFormatter, LegendItem, LegendStop, LegendTick, LegendMidpoint, LegendSymbolItem, LegendNoData, } from './components/Legend/Legend.svelte';
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ export { default as InlineAd } from './components/AdSlot/InlineAd.svelte';
32
32
  export { default as KinesisLogo } from './components/KinesisLogo/KinesisLogo.svelte';
33
33
  export { default as LanguageButton } from './components/LanguageButton/LanguageButton.svelte';
34
34
  export { default as LeaderboardAd } from './components/AdSlot/LeaderboardAd.svelte';
35
+ export { default as Legend } from './components/Legend/Legend.svelte';
35
36
  export { default as TileMap } from './components/TileMap/TileMap.svelte';
36
37
  export { default as TileMapLayer } from './components/TileMap/TileMapLayer.svelte';
37
38
  export { default as PaddingReset } from './components/PaddingReset/PaddingReset.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "3.4.1",
3
+ "version": "3.5.0",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",