@@ -263,10 +263,28 @@ export class PlotlyGraph extends HTMLElement {
263
263
return [ start , end + msPad ] ;
264
264
}
265
265
getVisibleRange ( ) {
266
- return this . contentEl . layout . xaxis ! . range ! . map ( ( date ) =>
267
- // if autoscale is used after scrolling, plotly returns the dates as numbers instead of strings
268
- Number . isFinite ( date ) ? date : + parseISO ( date )
269
- ) ;
266
+ console . log ( this . contentEl . layout . xaxis ! . range ) ;
267
+ return this . contentEl . layout . xaxis ! . range ! . map ( ( date ) => {
268
+ // if autoscale is used after scrolling, plotly returns the dates as timestamps (numbers) instead of iso strings
269
+ if ( Number . isFinite ( date ) ) return date ;
270
+ if ( date . startsWith ( "-" ) ) {
271
+ /*
272
+ The function parseISO can't handle negative dates.
273
+ To work around that, I'm parsing it without the minus, and then manually calculating the timestamp from that.
274
+ The arithmetic has a twist because timestamps start on 1970 and not on year zero,
275
+ so the distance to a the year zero has to be calculated by subtracting the "zero year" timestamp.
276
+ positive_date = -date (which is negative)
277
+ timestamp = (year 0) - (time from year 0)
278
+ timestamp = (year 0) - (positive_date - year 0)
279
+ timestamp = 2 * (year 0) - positive_date
280
+ timestamp = 2 * (year 0) - (-date)
281
+ */
282
+ return (
283
+ 2 * + parseISO ( "0000-01-01 00:00:00.000" ) - + parseISO ( date . slice ( 1 ) )
284
+ ) ;
285
+ }
286
+ return + parseISO ( date ) ;
287
+ } ) ;
270
288
}
271
289
async enterBrowsingMode ( ) {
272
290
this . isBrowsing = true ;
0 commit comments