tmcw / obsidian-freeform

An Obsidian plugin for freeform visualization and JavaScript code
https://obsidian.md/plugins?id=freeform
MIT License
84 stars 2 forks source link

Stashing in window.top messes up dates #12

Open lyon-fnal opened 3 months ago

lyon-fnal commented 3 months ago

Hi, Any idea why the formatting is lost on the date? image

This affects plotting when getting data from windows.top as instead of using the actual date for the axis ticks, it will use seconds since epoch.

tmcw commented 3 months ago

Hi - yeah, there are some notes on this in the release blog post and I added a new note in the using DataView API example.

The gist is that in different JavaScript contexts, objects like Date objects have different prototype roots, so if you create a Date object in the top frame (window.top) and then pull it into the iframe then check if it is instanceof Date, it will give you false, because Date in the iframe is a different prototype than Date in the top frame.

Recreating Date objects as in the example is the clearest way to work around this. I don't think there is a way to work around it in the general case, this is a fundamental attribute of how JavaScript works across contexts.

lyonsquark commented 3 months ago

Thanks for the explanation and the additional documentation!!