Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations type change dynamically #46

Closed
Eugene88 opened this issue Mar 9, 2018 · 5 comments
Closed

Annotations type change dynamically #46

Eugene88 opened this issue Mar 9, 2018 · 5 comments

Comments

@Eugene88
Copy link

Eugene88 commented Mar 9, 2018

Hi,
I have a problem with dynamically changing annotation type. I tring change annotation type when I click on note.

var makeAnnotation= d3.annotation().annotations(annotations0).type(d3.annotationCallout).on('noteclick', onClick)

function onClick(annotation)
{
annotation.color = "#000000"; - it works
annotation.type = d3.annotationLabel; - it doesn't work
makeAnnotation.update();
}

I can change type for all items from annotations0, but I need change a single annotation type.
It works:
makeAnnotation.type(d3.annotationLabel)
d3.select("#groupId0").select("g.annotation-group").call(makeAnnotation)

How can I change a single annotation type?

Thanks.

@susielu
Copy link
Owner

susielu commented Mar 9, 2018

I should post a better example of this, if you re-call the function on the selection it should update the type. So assuming you were doing something like this to create the annotations

d3.select("svg")
  .append("g")
  .attr("class", "annotation-group")
  .call(makeAnnotations)

You would then change you onClick to something like this :

function onClick(annotation) {
  annotation.color = "#000000"; 
  annotation.type = d3.annotationLabel;
  // makeAnnotation.update(); <- this does reset type
  d3.select(".annotation-group") //<- this should
    .call(makeAnnotations)
}

@Eugene88
Copy link
Author

Eugene88 commented Mar 9, 2018

Thanks. It works.
But I have a problem with d3.annotationBadge. Badge was created and not removed after change type
annotation
I switch types [d3.annotationLabel, d3.annotationCallout, d3.annotationCalloutElbow, d3.annotationBadge]

@Eugene88
Copy link
Author

Eugene88 commented Mar 9, 2018

And type doesn't change to d3.annotationLabel too (visualisation not changed)

@susielu
Copy link
Owner

susielu commented Mar 31, 2018

I believe this version fixes this 2.2.1 let me know if you have any more issues with it.

@susielu susielu closed this as completed Mar 31, 2018
@susielu
Copy link
Owner

susielu commented Mar 31, 2018

Oh no there was a bug in that version 2.2.4 should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants