question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotation Callback 'onMove'

See original GitHub issue

What I’m trying to do is set up an API call to my DB that allows users to add, edit, move, remove (etc.) annotations from the plot in their report. (I’ll need x/y coordinates, arrow info etc. to recreate from the DB on next run).

I’m having a hard time understanding the event handlers. (Sorry for the code formatting).

I set the plot with:

$( document ).ready(function() {
	Plotly.newPlot('main_graph{{key}}',
	                        main_data{{key}},
				main_layout{{key}},
				{displayModeBar: false,
				edits:{annotationPosition: true,
					 annotationText: true,
					 annotationTail: true}},
				);
});

And I have a button on the page to add a new default annotation

function addAnnotation(
    var myPlot{{key}} = document.getElementById('main_graph{{key}}');
    var annotate_text = 'New Annotation';
    var annotation = {
        text: annotate_text,
	x: 1,
	y: 15
    }

    var annotations = myPlot{{key}}.layout.annotations || [];
    annotations.push(annotation);
    var update = {  annotations: annotations  };
	
    Plotly.relayout('main_graph{{key}}', update);

    $(".annotation").bind("click mouseup mouseleave",function(e) { 
		var annotations_list = myPlot{{key}}.getElementsByClassName("annotation");
		var ann_list = Array.prototype.slice.call( annotations_list );
		var annot_number = this.getAttribute('data-index')
		var annot = ann_list[annot_number]
		var x = myPlot{{key}}.layout.annotations[annot_number]['x']
			console.log('well something happened', annot)
		});	
	};

The event prints to console until I move (drag and drop) an annotation…then nothing prints when I mouseup or mouseleave the new annotation location.

Ideally I would like an event to fire that I can tie to AJAX to update DB anytime an annotation is modified…re-positioned, renamed, etc.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mitja-pcommented, Feb 24, 2020

You should use plotly_relayout event which will send you the changes after annotation change is finished.

0reactions
etpinardcommented, Feb 25, 2020

Closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ItemTouchHelper.Callback - Android Developers
This class is the contract between ItemTouchHelper and your application. It lets you control which touch behaviors are enabled per each ViewHolder and...
Read more >
OnMoveListener - Mapbox docs
OnMove Listener. Interface definition for a callback to be invoked when the map is moved. interface OnMoveListener. Content copied to clipboard. Functions
Read more >
Callback - HELP CENTER
Callback is used after the script has issues a Reqagent and has not yet been answered. The phone call will not be initiated...
Read more >
ItemTouchHelper.java - Google Git
import android.annotation.SuppressLint; ... import androidx.annotation.NonNull; ... {@link Callback#onMove(RecyclerView, ViewHolder, ViewHolder)} and / or.
Read more >
android.support.v7.widget.helper.ItemTouchHelper$Callback ...
ItemTouchHelper$Callback ... RecyclerViewElasticityAdapter$ItemTouchHelperCallbackWrapper.getMoveThreshold(. ... Annotation (javassist.bytecode.annotation).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found