@ttoss/geovis-workspace 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Terezinha Tech Operations (ttoss)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @ttoss/geovis-workspace
2
+
3
+ A React component that composes a sidebar-driven workspace around a GeoVis map.
4
+ The sidebars are configured through a `config` object and the map is rendered
5
+ from a GeoVis `visualizationSpec`; each sidebar only renders when defined.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @ttoss/geovis-workspace
11
+ ```
12
+
13
+ `@ttoss/geovis`, `@ttoss/ui`, `@ttoss/react-i18n` and `react` are peer
14
+ dependencies.
15
+
16
+ ## Storybook
17
+
18
+ Interactive examples are available on [Storybook](https://storybook.ttoss.dev/).
19
+
20
+ ## Usage
21
+
22
+ The parent owns the selection state and derives the next `visualizationSpec`
23
+ from it, so picking a menu item recolors the map. Seed the initial selection
24
+ with `getInitialSelection` (reads each menu's `defaultValue`).
25
+
26
+ ```tsx
27
+ import { type VisualizationSpec } from '@ttoss/geovis';
28
+ import {
29
+ type GeovisWorkspaceConfig,
30
+ GeovisWorkspace,
31
+ getInitialSelection,
32
+ } from '@ttoss/geovis-workspace';
33
+ import * as React from 'react';
34
+
35
+ const config: GeovisWorkspaceConfig = {
36
+ leftSidebar: {
37
+ menus: [
38
+ {
39
+ id: 'variable',
40
+ title: 'Variável',
41
+ defaultValue: 'rate',
42
+ items: [
43
+ { value: 'rate', label: 'Taxa cumulativa' },
44
+ { value: 'range', label: 'Faixa (% da pop 65+)' },
45
+ ],
46
+ },
47
+ ],
48
+ },
49
+ rightSidebar: { title: 'Details' },
50
+ };
51
+
52
+ // Maps the current selection to a GeoVis spec — your domain logic.
53
+ const buildSpec = (
54
+ selection: Record<string, string | undefined>
55
+ ): VisualizationSpec => {
56
+ // ...
57
+ };
58
+
59
+ export const Example = () => {
60
+ const [selection, setSelection] = React.useState(() => {
61
+ return getInitialSelection({ config });
62
+ });
63
+
64
+ const visualizationSpec = React.useMemo(() => {
65
+ return buildSpec(selection);
66
+ }, [selection]);
67
+
68
+ return (
69
+ <GeovisWorkspace
70
+ config={config}
71
+ visualizationSpec={visualizationSpec}
72
+ variables={selection}
73
+ onVariableChange={setSelection}
74
+ />
75
+ );
76
+ };
77
+ ```
78
+
79
+ `variables` and `onVariableChange` are optional: omit both to let the workspace
80
+ manage the selection internally (seeded from `defaultValue`). Provide them to
81
+ control it from the parent — required when the selection must drive the
82
+ `visualizationSpec`. Selection is per menu group: choosing an item only affects
83
+ its own group. Read the current selection anywhere inside the workspace with
84
+ `useGeovisWorkspace()`.
85
+
86
+ ## API
87
+
88
+ ### `GeovisWorkspace` props
89
+
90
+ | Prop | Type | Description |
91
+ | ------------------- | ------------------------------------- | ----------------------------------------------------------- |
92
+ | `config` | `GeovisWorkspaceConfig` | Describes the sidebars. Required. |
93
+ | `visualizationSpec` | `VisualizationSpec` | GeoVis spec rendered in the main map area. Required. |
94
+ | `variables` | `Record<string, string \| undefined>` | Controlled selection per menu group. Omit for uncontrolled. |
95
+ | `onVariableChange` | `(variables) => void` | Called with the full next selection when an item is picked. |
96
+
97
+ ### `GeovisWorkspaceConfig`
98
+
99
+ | Property | Type | Description |
100
+ | -------------- | ---------------------------------- | -------------------------------------- |
101
+ | `leftSidebar` | `{ menus: GeovisWorkspaceMenu[] }` | Left sidebar config. Omit to hide it. |
102
+ | `rightSidebar` | `GeovisWorkspaceRightSidebar` | Right sidebar config. Omit to hide it. |
103
+
104
+ ### `GeovisWorkspaceMenu`
105
+
106
+ | Property | Type | Description |
107
+ | -------------- | ------------------------------------ | -------------------------------------- |
108
+ | `id` | `string` | Unique group identifier. |
109
+ | `title` | `string` | Title shown above the group. |
110
+ | `items` | `{ value: string; label: string }[]` | Selectable items. |
111
+ | `defaultValue` | `string` | Item selected by default in the group. |
112
+
113
+ ### `GeovisWorkspaceRightSidebar`
114
+
115
+ | Property | Type | Description |
116
+ | ----------------- | -------------------------------- | -------------------------------------- |
117
+ | `title` | `string` | Title shown at the top of the sidebar. |
118
+ | `legendWithColor` | `GeovisWorkspaceLegendWithColor` | Color-legend panel. Omit to hide it. |
119
+
120
+ ### `GeovisWorkspaceLegendWithColor`
121
+
122
+ A declarative color-legend panel: a description, a swatch-per-class legend and a
123
+ list of (optionally linked) data sources. Each block renders only when present.
124
+
125
+ | Property | Type | Description |
126
+ | ------------- | ----------------------------------------------- | --------------------------------- |
127
+ | `description` | `string` | Paragraph under the title. |
128
+ | `legend` | `{ title?: string; items: { color; label }[] }` | Class swatches (color + label). |
129
+ | `sources` | `{ title?: string; items: { label; href? }[] }` | Data sources; `href` adds a link. |
130
+
131
+ ```tsx
132
+ const config: GeovisWorkspaceConfig = {
133
+ rightSidebar: {
134
+ title: 'POPULAÇÃO 65+ COMO % DA POPULAÇÃO TOTAL',
135
+ legendWithColor: {
136
+ description: 'Proporção da população total com 65 anos ou mais.',
137
+ legend: {
138
+ title: 'Classes',
139
+ items: [
140
+ { color: '#eff3ff', label: '0% – 5%' },
141
+ { color: '#08519c', label: '20% – 100%' },
142
+ ],
143
+ },
144
+ sources: {
145
+ title: 'Fonte dos dados:',
146
+ items: [
147
+ { label: 'SEADE (2025)', href: 'https://repositorio.seade.gov.br' },
148
+ { label: 'Geometria: Distritos Municipais de São Paulo.' },
149
+ ],
150
+ },
151
+ },
152
+ },
153
+ };
154
+ ```