Skip to content

Commit 80d79a5

Browse files
author
alexandre-em
committed
Update doc usage examples
1 parent 2a786ef commit 80d79a5

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

website/docs/js/api/components/DamageHighlight.md

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ const image = {
3030
};
3131

3232
const polygons = [[[0, 0], [1, 0], [0, 1]], [[2, 0], [1, 1], [0, 2]]];
33+
const damages = [{ damageType: "Scratch", polygons, id }];
3334

34-
<DamageHighlight image={image} polygons={polygons} />;
35+
<DamageHighlight image={image} damages={damages} />;
3536
```
3637

3738
The component's properties are from the result of an inspection. Both of them are a part of `inspection.images`.
@@ -160,46 +161,52 @@ Format an `image` to a classical [image](#image) object (cf. [example](#Example)
160161

161162
# Example
162163
``` javascript
163-
import { usePolygons } from '@monkvision/visualization';
164-
```
165-
166-
``` javascript
167-
const oneImage = inspection.images[0]; // result from API
168-
169-
const ref = useRef(null);
170-
const { getDamages, getImage } = usePolygons();
171-
const options = {
172-
polygons: {
173-
opacity: 0.5,
174-
stroke: {
175-
color: 'green',
176-
strokeWidth: 50,
177-
}
178-
},
179-
label: {
180-
fontSize: 20,
181-
},
182-
background: {
183-
opacity: 0.35,
184-
},
185-
}
186-
187-
const handleSaveImage = useCallback(async () => {
188-
const base64 = await ref.current.toImage();
189-
save(base64);
190-
}, [ref]);
191-
192-
const handlePressDamage = (damage) => {
193-
console.log(damage);
164+
import React, { useState, useEffect } from 'react';
165+
import { DamageHighlight, useProps } from '@monkvision/visualization';
166+
167+
export default function App() {
168+
const oneImage = inspection.images[0]; // result from API
169+
170+
const ref = useRef(null);
171+
const { getDamages, getImage } = useProps();
172+
const options = {
173+
polygons: {
174+
opacity: 0.5,
175+
stroke: {
176+
color: 'green',
177+
strokeWidth: 50,
178+
}
179+
},
180+
label: {
181+
fontSize: 20,
182+
},
183+
background: {
184+
opacity: 0.35,
185+
},
186+
}
187+
188+
const handleSaveImage = useCallback(async () => {
189+
const base64 = await ref.current.toImage();
190+
save(base64);
191+
}, [ref]);
192+
193+
const handlePressDamage = (damage) => {
194+
console.log(damage);
195+
}
196+
197+
return (
198+
<View>
199+
<DamageHighlight
200+
image={getImage(oneImage)}
201+
damages={getDamages(oneImage, inspection.damages)}
202+
options={options}
203+
width={400}
204+
height={180}
205+
onPressDamage={console.log}
206+
ref={ref}
207+
/>
208+
</View>
209+
)
194210
}
195211

196-
<DamageHighlight
197-
image={getImage(oneImage)}
198-
damages={getDamages(oneImage, inspection.damages)}
199-
options={options}
200-
width={400}
201-
height={180}
202-
onPressDamage={console.log}
203-
ref={ref}
204-
/>
205212
```

0 commit comments

Comments
 (0)