@hopara/react 0.1.120 → 0.2.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/README.md +187 -0
- package/build/index.js +1 -1
- package/package.json +15 -15
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# @hopara/react
|
|
2
|
+
This package provides the react component to add [Hopara](https://hopara.io) visualizations to your project.
|
|
3
|
+
|
|
4
|
+
## Requirements
|
|
5
|
+
The [Hopara](https://hopara.io) component is built on top of [React](https://react.dev/) and [React-Redux](https://react-redux.js.org/). It requires the following depencies:
|
|
6
|
+
|
|
7
|
+
- react >= 18.2
|
|
8
|
+
- react-redux >= 8.0
|
|
9
|
+
- redux >= 4.2
|
|
10
|
+
|
|
11
|
+
## Installing
|
|
12
|
+
### Package manager
|
|
13
|
+
Using npm:
|
|
14
|
+
```shell
|
|
15
|
+
$ npm install --save @hopara/react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Using yarn:
|
|
19
|
+
```shell
|
|
20
|
+
$ yarn add @hopara/react
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Once installed, you can import the library using import or require approach:
|
|
24
|
+
```jsx
|
|
25
|
+
import {Hopara} from '@hopara/react';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Authentication
|
|
29
|
+
The component requires a valid `accessToken`. Use the `Auth API` to fetch it, as explained in our [documentation website](https://docs.hopara.app/docs/external-integration/authentication-integration.html)
|
|
30
|
+
|
|
31
|
+
## Examples
|
|
32
|
+
### Basic usage
|
|
33
|
+
```jsx
|
|
34
|
+
<div className="HoparaEmbedded">
|
|
35
|
+
<Hopara
|
|
36
|
+
app="your-app-id"
|
|
37
|
+
accessToken="your-access-token"
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Module API
|
|
43
|
+
You can further customize the integration by using the component props:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
type HoparaProps = {
|
|
47
|
+
// The app id
|
|
48
|
+
app: string
|
|
49
|
+
|
|
50
|
+
// The accessToken fetched from the auth API
|
|
51
|
+
accessToken: string
|
|
52
|
+
|
|
53
|
+
// Overwrites the data at render time
|
|
54
|
+
dataLoaders: DataLoader[] | undefined
|
|
55
|
+
|
|
56
|
+
// Provides a custom ways to update data
|
|
57
|
+
dataUpdaters: DataUpdaters[] | undefined
|
|
58
|
+
|
|
59
|
+
// The initial position to load the visualization
|
|
60
|
+
initialPosition: InitialPosition | undefined
|
|
61
|
+
|
|
62
|
+
// The initial row (e.g. asset) to load the visualization
|
|
63
|
+
initialRow: InitialRow | undefined
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Data Loader
|
|
68
|
+
By default Hopara will load the same visualization and data as seen as in hopara.app. You can use the data loader prop to provide a custom way to load the data.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
type DataLoader = {
|
|
72
|
+
// query name
|
|
73
|
+
name: string
|
|
74
|
+
|
|
75
|
+
// data source name
|
|
76
|
+
source: string
|
|
77
|
+
|
|
78
|
+
// callback to be used on data load
|
|
79
|
+
loader: (filterSet: {limit: number, offset:number, filters: any[]}) => Promise<Record<string, any>[]>
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#### Example
|
|
85
|
+
|
|
86
|
+
```jsx
|
|
87
|
+
const dataLoaders = [{
|
|
88
|
+
name: 'queryName',
|
|
89
|
+
source: 'dataSourceName',
|
|
90
|
+
loader: () => {
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
id: 1,
|
|
94
|
+
name: 'Eiffel Tower',
|
|
95
|
+
country: 'France',
|
|
96
|
+
longitude: 48.85845461500544,
|
|
97
|
+
latitude: 2.294467845588995
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 2,
|
|
101
|
+
name: 'Liberty Statue',
|
|
102
|
+
country: 'USA',
|
|
103
|
+
longitude: 40.68815550804761,
|
|
104
|
+
latitude: -74.02620077137483
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 3,
|
|
108
|
+
name: 'Great Wall of China',
|
|
109
|
+
country: 'China',
|
|
110
|
+
longitude: 40.43211592595951,
|
|
111
|
+
latitude: 116.57040708445938,
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}]
|
|
116
|
+
...
|
|
117
|
+
<div className="HoparaEmbedded">
|
|
118
|
+
<Hopara
|
|
119
|
+
app="your-app-id"
|
|
120
|
+
accessToken="your-access-token"
|
|
121
|
+
dataLoaders={dataLoaders}
|
|
122
|
+
/>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Data Updater
|
|
126
|
+
By default Hopara will update the visualization in the same database configured in hopara.app. You can use the data updater prop to provide a custom way to update the data.
|
|
127
|
+
|
|
128
|
+
The data updater is called when placing objetcs in a visualization and when resizing images.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
type DataUpdater = {
|
|
132
|
+
// query name
|
|
133
|
+
name: string
|
|
134
|
+
|
|
135
|
+
// data source name
|
|
136
|
+
source: string
|
|
137
|
+
|
|
138
|
+
// callback to be used on data update
|
|
139
|
+
updater: (updatedRow: Record<string, any>, originalRow: Record<string, any>, diff: Partial<Record<string, any>>) => Promise<void>
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```jsx
|
|
144
|
+
const dataUpdaters = [{
|
|
145
|
+
name: 'queryName',
|
|
146
|
+
source: 'dataSourceName',
|
|
147
|
+
updater: (newRow) => {
|
|
148
|
+
const rowIndex = dataInMemory.findIndex((row) => row.id === newRow.id)
|
|
149
|
+
dataInMemory[rowIndex] = newRow
|
|
150
|
+
}
|
|
151
|
+
}]
|
|
152
|
+
|
|
153
|
+
...
|
|
154
|
+
|
|
155
|
+
<div className="HoparaEmbedded">
|
|
156
|
+
<Hopara
|
|
157
|
+
app="your-app-id"
|
|
158
|
+
accessToken="your-access-token"
|
|
159
|
+
dataUpdaters={dataUpdaters}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Initial Position
|
|
165
|
+
The initial position prop overrides the initial position of the visualization.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
type InitialPosition = {
|
|
169
|
+
latitude: number | undefined
|
|
170
|
+
longitude: number | undefined
|
|
171
|
+
x: number | undefined
|
|
172
|
+
y: number | undefined
|
|
173
|
+
z: number | undefined
|
|
174
|
+
zoom: number | undefined
|
|
175
|
+
bearing: number | undefined
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Initial Row
|
|
180
|
+
The initial row prop centers the visualization around a specific row (e.g. asset, facility).
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
type InitialRow = {
|
|
184
|
+
entityId: string
|
|
185
|
+
rowId: string
|
|
186
|
+
}
|
|
187
|
+
```
|