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

After deep zoom in Holoview difference between hover values is changing unexpectedly #6165

Open
zyuzin2024 opened this issue Mar 29, 2024 · 7 comments

Comments

@zyuzin2024
Copy link

zyuzin2024 commented Mar 29, 2024

Thanks for contacting us! Please read and follow these instructions carefully, then delete this introductory text to keep your issue easy to read. Note that the issue tracker is NOT the place for usage questions and technical assistance; post those at Discourse instead. Issues without the required information below may be closed immediately.

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

pandas=1.1.3=py38ha925a31_0
numpy=1.21.2=py38hfca59bb_0
holoviews=1.14.7=pyhd8ed1ab_0
bokeh=2.4.2=py38haa244fe_0
panel=0.12.6=pyhd8ed1ab_0
datashader=0.13.0=pyh6c4a22f_0

Description of expected behavior and the observed behavior

After deep zoom in Holoview difference between hover values is changing unexpectedly

7 to 8 zoom in steps may be required to see detailed picture.
File “ZyuzinTestCleared - Jupyter Notebook” includes 2 cells:

Code in the first cell generates the chart provided in "Test results" file.

Code in the second cell
df2
Displaying target nanosecond and a_price_1 value

Here are test results:

Main part in seconds 1538685910
Nanoseconds:

Hover value Hover value difference Click value Click value difference
861211100 300 861211136 256
861211400 200 861211392 256
861211600 400 861211648 256
861212000 200 861211904 256
861212200 200 861212160 256
861212400 300 861212416 256
861212700 300 861212672 256
861213000 400 861212928 512
861213400 300 861213440 256
861213700 861213696

Target value 861211796

The first problem is that hover values have last two digits = 0.
The second problem is that difference between click values not always the same (256 and 512).

Complete, minimal, self-contained example code that reproduces the issue

# code goes here between backticks

### The first cell:

import pandas as pd
import numpy as np
import holoviews as hv
from holoviews import opts
from holoviews.operation.datashader import datashade, dynspread
from bokeh.models.formatters import BasicTickFormatter, NumeralTickFormatter, DatetimeTickFormatter, FuncTickFormatter
import panel as pn
import datashader as ds
from datetime import datetime
from io import StringIO

hv.extension('bokeh')

customIntToTime = FuncTickFormatter(code="""
    var intTimestamp = BigInt(tick);
    var nanoseconds = Number(intTimestamp % BigInt(1000000000));
    var milliseconds = Number(intTimestamp / BigInt(1000000)); 
    var date = new Date(milliseconds);
    var yr = date.getYear();
    var mon = date.getMonth();
    var dt = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    var formattedDate = `${yr+1900}-${mon+1}-${dt} ${hours}:${minutes}:${seconds}`;
    return formattedDate;
""")
#    var formattedDate = `${yr+1900}-${mon+1}-${dt} ${hours}:${minutes}:${seconds}.${nanoseconds}`;

def clicked_point(x, y):
    return pn.pane.Str('Click at %1f, %1f' % (x, y), width=200)

#df3 = pd.read_csv('D:\Data\OneDrive\mzyuzin\OneDrive - CFTC\Zyuzin\Data\zzz.csv')
#print(df3)

TESTDATA = u"""\
 nanoseconds a_price_1
0 1538685910861211796 3
1 1538685910861211801 2
2 1538685910861211811 4
3 1538685910861211817 5
4 1538685910861211835 8
5 1538685910861211847 6
6 1538685910861211851 11
7 1538685910861211870 3
8 1538685910861211896 8
9 1538685910861211900 7
"""
df = pd.read_csv(StringIO(TESTDATA), index_col=0, sep=r"\s+", engine='python')
print(df)

df2=df.head(1)
df2=df2[['nanoseconds', 'a_price_1']]

# Getting the current date and timestamp
dt = datetime.now()
ts = datetime.timestamp(dt)
print("Date and time is:", dt)

kdims = ['nanoseconds', 'a_price_1']
vdims = ['nanoseconds','a_price_1']
points  = hv.Points(df2, kdims, vdims)

shaded = datashade(points).opts(hv.opts.RGB(width=800))
spreaded = dynspread(shaded)
#plot = spreaded.opts(tools=['hover','tap'])
plot = spreaded.opts(tools=['hover','tap'], xformatter=customIntToTime)
stream = hv.streams.Tap(source=spreaded, x=np.nan, y=np.nan)
layout = pn.Row(plot, pn.bind(clicked_point, x=stream.param.x, y=stream.param.y))
setattr(plot, 'plot_width', 1700)
setattr(plot, 'plot_height', 900)
layout
​

### The second cell:
df2

#### Stack traceback and/or browser JavaScript console output

#### Screenshots or screencasts of the bug in action

- [ ] I may be interested in making a pull request to address this
@zyuzin2024
Copy link
Author

Ticket related to #6156

@hoxbro
Copy link
Member

hoxbro commented Mar 29, 2024

Thank for the report. I can't run the code as provided.

Can you try making a minimal, reproducible example (MRE)? In general, a complete script with only the essential code can be copied/pasted and immediately run as-is with no modifications and no need to download data files.

You are running pretty old versions of the packages. Try upgrading to the latest version in a new environment and see if that works. If it doesn't, update the example to work with the latest packages.

Adding a video showing the problem would be helpful, for me to understand the problem.

Lastly, data sharing and the hover tool make no promises; the result of a datashaded object is a way to represent how the data looks, not the data itself.

@zyuzin2024
Copy link
Author

Hoxbro, thank you for your quick respond. I am not sure if I can change my test to run it without file having data. It is the simplest csv file with a title and 10 records. I understand that you prefer copied /pasted code to run immediately. I hope you can spend an extra effort to save the file in a directory and reference it. If you just save the file and provide directory where it is located, I can update Python code.
I will try to get latest the libraries, but it would be nice to know if the has same behavior with libraries you use.

"Lastly, data sharing and the hover tool make no promises; the result of a datashaded object is a way to represent how the data looks, not the data itself."

I see that "object represents the way how data looks like", but it would be nice to know why hover values have so "strange" precision with the last two digits = 0 and click values spread unequally.

Please let me know if I can provide more info and we can move forward with this ticket.

@hoxbro
Copy link
Member

hoxbro commented Mar 30, 2024

I am not sure if I can change my test to run it without file having data. It is the simplest csv file with a title and 10 records

Just create the dataframe in the file. For what it is worth, your data have the same timestamp.

I understand that you prefer copied /pasted code to run immediately. I hope you can spend an extra effort to save the file in a directory and reference it.

I did 🙂, but I couldn't get the code to run on the latest versions. But as this is OSS, I can't fix your code to the latest versions.

I see that "object represents the way how data looks like", but it would be nice to know why hover values have so "strange" precision with the last two digits = 0 and click values spread unequally.

I can't give you more information because I was vague because your problem is vague to me; I can't run the code and have no visual feedback on the problem.

Please let me know if I can provide more info and we can move forward with this ticket.

Getting your example to work on the latest packages. I can't do anything until I have a MRE that works with the latest packages.

@zyuzin2024
Copy link
Author

Hoxbro,
I updated code to remove *.csv file. Now you can copy and paste to run it. Please let me know if it helps.
Thanks

@hoxbro
Copy link
Member

hoxbro commented Apr 4, 2024

Have you updated the code to work with the lastest packages?

@zyuzin2024
Copy link
Author

Packages updated. No difference.
Conda 24.1.2
Python 3.12.2
pandas 2.2.1
numpy 1.26.4
holoviews 1.18.3
bokeh 3.3.4
panel 1.3.8
datashader 0.16.0

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