From d8b674d5d0f5de7248ef091ed7dec63e64abf3f5 Mon Sep 17 00:00:00 2001 From: amitsh1 Date: Sun, 26 Jan 2020 14:11:34 +0000 Subject: [PATCH 1/3] add json_objects --- src/lib/components/DashCanvas.react.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/components/DashCanvas.react.js b/src/lib/components/DashCanvas.react.js index c6c85eb..fb9fb82 100644 --- a/src/lib/components/DashCanvas.react.js +++ b/src/lib/components/DashCanvas.react.js @@ -23,7 +23,7 @@ DashCanvas.defaultProps = { json_data: '', image_content: '', trigger: 0, width: 500, height: 500, scale: 1, lineWidth: 10, lineColor: 'red', tool: "pencil", zoom: 1, - goButtonTitle: 'Save', hide_buttons: [] + goButtonTitle: 'Save', hide_buttons: [],json_objects='' }; DashCanvas.propTypes = { @@ -112,7 +112,14 @@ DashCanvas.propTypes = { * Dash-assigned callback that should be called whenever any of the * properties change */ - setProps: PropTypes.func + setProps: PropTypes.func, + + /** + * Like json_data,add objects like paths or images + * Use utils.parse_json.parse_jsonstring to parse + * this string. + */ + json_objects: PropTypes.string }; export const propTypes = DashCanvas.propTypes; From 0db72ffd2113f3a786ffae869c9185ed5836ed14 Mon Sep 17 00:00:00 2001 From: amitsh1 Date: Sun, 26 Jan 2020 14:25:26 +0000 Subject: [PATCH 2/3] react to changes in json_objects --- src/lib/fragments/DashCanvas.react.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/fragments/DashCanvas.react.js b/src/lib/fragments/DashCanvas.react.js index 05cd811..6f07969 100644 --- a/src/lib/fragments/DashCanvas.react.js +++ b/src/lib/fragments/DashCanvas.react.js @@ -107,6 +107,12 @@ export default class DashCanvas extends Component { sketch._fc.setZoom(this.props.zoom); }; + + if ((this.props.json_objects !== prevProps.json_objects)) { + this._sketch.fromJSON({ + 'objects':sketch.toJSON().objects.concat(JSON.parse(this.props.json_objects)) + }); + }; }; From bc967c8674682b19934017f76782ab504a811e8a Mon Sep 17 00:00:00 2001 From: amitsh1 Date: Sun, 26 Jan 2020 14:30:15 +0000 Subject: [PATCH 3/3] fix mistake '=' instead of ':' --- src/lib/components/DashCanvas.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/DashCanvas.react.js b/src/lib/components/DashCanvas.react.js index fb9fb82..2aa0fa1 100644 --- a/src/lib/components/DashCanvas.react.js +++ b/src/lib/components/DashCanvas.react.js @@ -23,7 +23,7 @@ DashCanvas.defaultProps = { json_data: '', image_content: '', trigger: 0, width: 500, height: 500, scale: 1, lineWidth: 10, lineColor: 'red', tool: "pencil", zoom: 1, - goButtonTitle: 'Save', hide_buttons: [],json_objects='' + goButtonTitle: 'Save', hide_buttons: [],json_objects: '' }; DashCanvas.propTypes = {