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

Changing the source of streams doesn't update Stream.registry correctly. #3965

Closed
ruoyu0088 opened this issue Sep 17, 2019 · 2 comments · Fixed by #3978
Closed

Changing the source of streams doesn't update Stream.registry correctly. #3965

ruoyu0088 opened this issue Sep 17, 2019 · 2 comments · Fixed by #3978
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@ruoyu0088
Copy link
Contributor

ruoyu0088 commented Sep 17, 2019

Here is an example:

import holoviews as hv
from holoviews import opts, streams

def func1(x, y):
    x = x or 0
    y = y or 0
    return hv.Points(([x], [y])).opts(color="red", size=10)

def func2(x, y):
    x = x or 0
    y = y or 0
    return hv.Points(([x], [y])).opts(color="green", size=10)
    
stream1 = streams.PointerXY(source=None)
stream2 = streams.PointerXY(source=None)

d1 = hv.DynamicMap(func1, streams=[stream1])    
d2 = hv.DynamicMap(func2, streams=[stream2])

print(streams.Stream.registry[d1], streams.Stream.registry[d2])
stream1.source = d2
stream2.source = d1
print(streams.Stream.registry[d1], streams.Stream.registry[d2])

the output is

[PointerXY(x=None,y=None)] [PointerXY(x=None,y=None)]
[PointerXY(x=None,y=None), PointerXY(x=None,y=None)] [PointerXY(x=None,y=None), PointerXY(x=None,y=None)]

after changing the source, both the streams have been registered to both the DynamicMap objects. Mouse moving in one of the plot will cause the two points move. Because of this problem, I cannot make two plots that link the stream to each other.

It seems that it is a bug in the setter of source property. if self.source should be if self.source is not None. bool(d1) returns False because len(d1)==0.

    @source.setter
    def source(self, source):
        if self.source:  #--> if self.source is not None
            source_list = self.registry[self.source]
            if self in source_list:
                source_list.remove(self)

        if source is None:
            self._source = None
            return

        self._source = weakref.ref(source)
        if source in self.registry:
            self.registry[source].append(self)
        else:
            self.registry[source] = [self]
@philippjfr
Copy link
Member

Yes, just encountered this bug myself. Could you submit a PR or should I?

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Sep 20, 2019
@philippjfr philippjfr added this to the v1.12.6 milestone Sep 22, 2019
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants