How to get rid of this popup when hovering over a label in the Chord Diagram (Holoviews - Python)

280 views Asked by At

Exactly like the title says, I've used some code that I collected from multiple places to build up this Chord diagram, but unfortunately one last thing that's kind of going to hinder that 100% perfection is this popup that shows up whenever I hover over the label. The pop up remains there even when the mouse is moving elsewhere... By the way, I'm using Python and Holoviews for plotting the chord. I'm pretty sure this is due to a bug or something... however, I'd love to find a way to bypass it... Example here : bug example

Code :

%%opts Chord [height=600 width=600 title="Transactions from 2000 to 2021" ]
#plot 
#edit links = moves[moves['Transactions'] > x] // x refers to the number of transactions minimum for the diagram display
moves = moves[moves['Transactions']>5]
links = moves
chord = hv.Chord(links)
chord
nodesl = []
c = []
for i, row in moves.iterrows():
    c.append(row[0])
    c.append(row[1])

c = pd.DataFrame(c)
c.drop_duplicates(inplace=True)
c.reset_index(inplace=True)
c.drop(columns='index', inplace=True)
c 

nodes = []
for i, row in c.iterrows():
    nodes.append({'name':row[0]})


nodes = pd.DataFrame(nodes)
# nodes

nodes = hv.Dataset(nodes, 'name')
nodes.data.head()



%%opts Chord [height=800 width=800  bgcolor="black"]
%%opts Chord [title="Transactions from 2000 to 2021 (Countries with over 5 moves)\nTip: Please do not hover over the label as it might produce a bug, else refresh the page" ]

chord = hv.Chord((links, nodes)).select(value=(5, None))

#this function allows text to fit perfectly on the screen
def rotate_label(plot, element):
    text_cds = plot.handles['text_1_source']
    length = len(text_cds.data['angle'])
    text_cds.data['angle'] = [0]*length
    xs = text_cds.data['x']
    text = np.array(text_cds.data['text'])
    xs[xs<0] -= np.array([len(t)*0.019 for t in text[xs<0]])

chord.opts(
    opts.Chord(cmap='Category10', 
               edge_color=dim('Target').str(), 
               node_color=dim('name').str(),
               labels='name',
               label_text_color="white",
               hooks=[rotate_label]
               ))
chord
1

There are 1 answers

5
James A. Bednar On

The ??? usually indicates that some field it's trying to display isn't available; not sure why that would be in this case. You can always override the default tools HoloViews uses for Bokeh by setting default_tools=[] and then specify whatever tools you do want, without 'hover', e.g. tools=['save', 'pan', 'wheel_zoom', 'box_zoom', 'reset'].