Skip to content
Snippets Groups Projects
Commit 03af8057 authored by Samuel Jugnet's avatar Samuel Jugnet
Browse files

wip save svg

parent 37941236
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1712 failed
mirador @ 1a9ef869
Subproject commit 3956139233904c4666e611a2b3aa09143cb67b57 Subproject commit 1a9ef869f8868c6983ba5e465da63598b14d2d8e
This diff is collapsed.
...@@ -311,6 +311,7 @@ class AnnotationCreation extends Component { ...@@ -311,6 +311,7 @@ class AnnotationCreation extends Component {
canvases, canvases,
receiveAnnotation, receiveAnnotation,
config, config,
} = this.props; } = this.props;
const { const {
title, title,
...@@ -323,9 +324,14 @@ class AnnotationCreation extends Component { ...@@ -323,9 +324,14 @@ class AnnotationCreation extends Component {
tend, tend,
textEditorStateBustingKey, textEditorStateBustingKey,
} = this.state; } = this.state;
console.log('submitting form',this.state);
const t = (tstart && tend) ? `${tstart},${tend}` : null; const t = (tstart && tend) ? `${tstart},${tend}` : null;
const body = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody }; const body = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody };
canvases.forEach((canvas) => { canvases.forEach(async(canvas) => {
const storageAdapter = config.annotation.adapter(canvas.id); const storageAdapter = config.annotation.adapter(canvas.id);
const anno = new WebAnnotation({ const anno = new WebAnnotation({
...@@ -339,9 +345,12 @@ class AnnotationCreation extends Component { ...@@ -339,9 +345,12 @@ class AnnotationCreation extends Component {
id: (annotation && annotation.id) || `${uuid()}`, id: (annotation && annotation.id) || `${uuid()}`,
image, image,
manifestId: canvas.options.resource.id, manifestId: canvas.options.resource.id,
svg, svg:svg,
tags, tags,
}).toJson(); }).toJson();
console.log(anno);
if (annotation) { if (annotation) {
storageAdapter.update(anno) storageAdapter.update(anno)
.then((annoPage) => { .then((annoPage) => {
...@@ -418,7 +427,7 @@ class AnnotationCreation extends Component { ...@@ -418,7 +427,7 @@ class AnnotationCreation extends Component {
strokeWidth, strokeWidth,
closedMode, closedMode,
textBody, textBody,
svg,
tstart, tstart,
tend, tend,
textEditorStateBustingKey, textEditorStateBustingKey,
...@@ -452,6 +461,8 @@ class AnnotationCreation extends Component { ...@@ -452,6 +461,8 @@ class AnnotationCreation extends Component {
updateGeometry={this.updateGeometry} updateGeometry={this.updateGeometry}
windowId={windowId} windowId={windowId}
player={mediaIsVideo ? VideosReferences.get(windowId) : OSDReferences.get(windowId)} player={mediaIsVideo ? VideosReferences.get(windowId) : OSDReferences.get(windowId)}
width={mediaIsVideo ? VideosReferences.get(windowId).video.videoWidth : OSDReferences.get(windowId).viewer.world.getItemAt(0).source.dimensions.x}
height={mediaIsVideo ? VideosReferences.get(windowId).video.videoHeight : OSDReferences.get(windowId).viewer.world.getItemAt(0).source.dimensions.y}
/> />
<StyledForm <StyledForm
onSubmit={this.submitForm} onSubmit={this.submitForm}
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
, Ellipse, Transformer,Shape , Ellipse, Transformer,Shape
} from 'react-konva'; } from 'react-konva';
import { exportStageSVG } from 'react-konva-to-svg';
class FreeHand extends React.Component { class FreeHand extends React.Component {
...@@ -469,7 +469,7 @@ class AnnotationDrawing extends Component { ...@@ -469,7 +469,7 @@ class AnnotationDrawing extends Component {
this.paper = null; this.paper = null;
this.konvas = null;
// this.addPath = this.addPath.bind(this); // this.addPath = this.addPath.bind(this);
...@@ -479,17 +479,41 @@ class AnnotationDrawing extends Component { ...@@ -479,17 +479,41 @@ class AnnotationDrawing extends Component {
newShape: null, newShape: null,
currentShape: null, currentShape: null,
isDrawing: false, isDrawing: false,
svg: async () => {
// Your function implementation here
// stage is the one with same windowId
const stage = window.Konva.stages.find((stage) => stage.attrs.id === this.props.windowId);
const svg = await exportStageSVG(stage);
console.log('svg',svg);
return svg;
},
}; };
this.shapeRefs = {}; this.shapeRefs = {};
this.transformerRefs = {}; this.transformerRefs = {};
} }
onShapeClick = (shape) => { onShapeClick = (shape) => {
this.svg();
this.setState({ selectedShapeId: shape.id }); this.setState({ selectedShapeId: shape.id });
const id = shape.id; const id = shape.id;
// find shape by id // find shape by id
...@@ -725,6 +749,16 @@ class AnnotationDrawing extends Component { ...@@ -725,6 +749,16 @@ class AnnotationDrawing extends Component {
}; };
exportStageSVG=(stage)=>{
const svg = exportStageSVG({
container: stage,
width: 1920,
height: 1080,
});
console.log('svg',svg);
}
drawKonvas() { drawKonvas() {
...@@ -733,13 +767,15 @@ class AnnotationDrawing extends Component { ...@@ -733,13 +767,15 @@ class AnnotationDrawing extends Component {
const { shapes, newShape } = this.state; const { shapes, newShape } = this.state;
const { windowId } = this.props;
console.log(windowId)
// potentiellement videoRef et windowId
return ( return (
<Stage <Stage
width={1920} width={this.props.width || 1920}
height={1080} height={this.props.height || 1080}
style={{ style={{
height: '100%', left: 0, position: 'absolute', top: 0, width: '100%', height: '100%', left: 0, position: 'absolute', top: 0, width: '100%',
}} }}
...@@ -747,6 +783,8 @@ class AnnotationDrawing extends Component { ...@@ -747,6 +783,8 @@ class AnnotationDrawing extends Component {
onMouseUp={this.handleMouseUp} onMouseUp={this.handleMouseUp}
onMouseMove={this.handleMouseMove} onMouseMove={this.handleMouseMove}
onDblClick={this.handleKonvasDblClick} onDblClick={this.handleKonvasDblClick}
id={windowId}
svg={this.svg}
> >
...@@ -797,7 +835,7 @@ AnnotationDrawing.propTypes = { ...@@ -797,7 +835,7 @@ AnnotationDrawing.propTypes = {
fillColor: PropTypes.string, fillColor: PropTypes.string,
strokeColor: PropTypes.string, strokeColor: PropTypes.string,
strokeWidth: PropTypes.number, strokeWidth: PropTypes.number,
svg: PropTypes.string, svg: PropTypes.func.isRequired,
updateGeometry: PropTypes.func.isRequired, updateGeometry: PropTypes.func.isRequired,
windowId: PropTypes.string.isRequired, windowId: PropTypes.string.isRequired,
}; };
...@@ -812,4 +850,5 @@ AnnotationDrawing.defaultProps = { ...@@ -812,4 +850,5 @@ AnnotationDrawing.defaultProps = {
svg: null, svg: null,
}; };
export default AnnotationDrawing; export default AnnotationDrawing;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment