From 58f357826b2dac087b4641722b9415562562f688 Mon Sep 17 00:00:00 2001 From: MFed Date: Wed, 6 Jul 2016 09:46:15 -0400 Subject: [PATCH 1/3] Adding event which is raised when an annontation is edited in an editable plot. --- src/components/annotations/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index 3fc49527908..eebb4a634c2 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -549,6 +549,32 @@ annotations.draw = function(gd, index, opt, value) { var annbase = 'annotations[' + index + ']'; + var emitEditAnnotation = function(gd, update, optionsIn, options) { + var annBeingEdited = /(.*].)/.exec(Object.keys(update)[0])[1]; + + ['x', 'y'].forEach(function(axLetter) { + var axis = Axes.getFromId(gd, options[axLetter + 'ref']); + + if(axis.type === 'date') { + if(update[annBeingEdited + axLetter]) { + update[annBeingEdited + axLetter] = Lib.ms2DateTime(update[annBeingEdited + axLetter]); + } + + if(options['a' + axLetter + 'ref'] === options[axLetter + 'ref']) { + if(update[annBeingEdited + 'a' + axLetter]) { + update[annBeingEdited + 'a' + axLetter] = Lib.ms2DateTime(update[annBeingEdited + 'a' + axLetter]); + } + } + } + }); + + gd.emit('plotly_editannotation', { + update: update, + annotation: optionsIn, + fullAnnotation: options + }); + }; + // add the arrow // uses options[arrowwidth,arrowcolor,arrowhead] for styling var drawArrow = function(dx, dy) { @@ -695,6 +721,7 @@ annotations.draw = function(gd, index, opt, value) { }, doneFn: function(dragged) { if(dragged) { + emitEditAnnotation(gd, update, optionsIn, options); Plotly.relayout(gd, update); var notesBox = document.querySelector('.js-notes-box-panel'); if(notesBox) notesBox.redraw(notesBox.selectedObj); @@ -787,6 +814,7 @@ annotations.draw = function(gd, index, opt, value) { doneFn: function(dragged) { setCursor(ann); if(dragged) { + emitEditAnnotation(gd, update, optionsIn, options); Plotly.relayout(gd, update); var notesBox = document.querySelector('.js-notes-box-panel'); if(notesBox) notesBox.redraw(notesBox.selectedObj); From 45b26b33d0a1cb11cac2e91981a522efa819f956 Mon Sep 17 00:00:00 2001 From: MFed Date: Wed, 6 Jul 2016 13:21:53 -0400 Subject: [PATCH 2/3] Fixing bug where the logic expected the contents of the first property in "update" was for one of the coordinates. --- src/components/annotations/index.js | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index eebb4a634c2..5568012c398 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -550,29 +550,37 @@ annotations.draw = function(gd, index, opt, value) { var annbase = 'annotations[' + index + ']'; var emitEditAnnotation = function(gd, update, optionsIn, options) { - var annBeingEdited = /(.*].)/.exec(Object.keys(update)[0])[1]; + console.log('*** update: ' + JSON.stringify(update)) + var annBeingEdited = null + for(var key in update) { + var match = /(.*].)/.exec(key) + if(match) + annBeingEdited = match[1] + } - ['x', 'y'].forEach(function(axLetter) { - var axis = Axes.getFromId(gd, options[axLetter + 'ref']); + if(annBeingEdited) { + ['x', 'y'].forEach(function(axLetter) { + var axis = Axes.getFromId(gd, options[axLetter + 'ref']); - if(axis.type === 'date') { - if(update[annBeingEdited + axLetter]) { - update[annBeingEdited + axLetter] = Lib.ms2DateTime(update[annBeingEdited + axLetter]); - } + if(axis.type === 'date') { + if(update[annBeingEdited + axLetter]) { + update[annBeingEdited + axLetter] = Lib.ms2DateTime(update[annBeingEdited + axLetter]); + } - if(options['a' + axLetter + 'ref'] === options[axLetter + 'ref']) { - if(update[annBeingEdited + 'a' + axLetter]) { - update[annBeingEdited + 'a' + axLetter] = Lib.ms2DateTime(update[annBeingEdited + 'a' + axLetter]); + if(options['a' + axLetter + 'ref'] === options[axLetter + 'ref']) { + if(update[annBeingEdited + 'a' + axLetter]) { + update[annBeingEdited + 'a' + axLetter] = Lib.ms2DateTime(update[annBeingEdited + 'a' + axLetter]); + } } } - } - }); + }); - gd.emit('plotly_editannotation', { - update: update, - annotation: optionsIn, - fullAnnotation: options - }); + gd.emit('plotly_editannotation', { + update: update, + annotation: optionsIn, + fullAnnotation: options + }); + } }; // add the arrow From 7e3893cb4cf517d7f4ea59dee635c705151fd926 Mon Sep 17 00:00:00 2001 From: MFed Date: Wed, 6 Jul 2016 13:44:21 -0400 Subject: [PATCH 3/3] oops. didn't cleaup/run lint. --- src/components/annotations/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/annotations/index.js b/src/components/annotations/index.js index 5568012c398..03cd3d7482e 100644 --- a/src/components/annotations/index.js +++ b/src/components/annotations/index.js @@ -550,12 +550,11 @@ annotations.draw = function(gd, index, opt, value) { var annbase = 'annotations[' + index + ']'; var emitEditAnnotation = function(gd, update, optionsIn, options) { - console.log('*** update: ' + JSON.stringify(update)) - var annBeingEdited = null + var annBeingEdited = null; for(var key in update) { - var match = /(.*].)/.exec(key) + var match = /(.*].)/.exec(key); if(match) - annBeingEdited = match[1] + annBeingEdited = match[1]; } if(annBeingEdited) {