daattali / timevis

📅 Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
652 stars 157 forks source link

Timevis doesn't work with dates Before Common Era (or inferior to 100) #99

Closed K-lone closed 3 years ago

K-lone commented 4 years ago

Hello,

I attempted to display a data set containing dates before the Common Era (BCE) which are negative (or inferior to 100) and they do not appear in the timevis chronology. I made a function to produce negative date using lubridate and put it in my column and it did not work. I put values in start/end, for example "-700" and "-700/01/01", with numeric, character, factors classes but it did not work. I have the same behavior with dates between 0 and 100.

Could you help me please ? I did not find any answer on internet.

I did a reproducible example of the problem:

example <- data.frame(id= 1:3,
                      content= as.character(c("A", "B", "C")),
                      start= factor(c("-700", "90", "100")),
                      end= factor(c("-400", "300", "700")),
                      group= factor(c("G1", "G1", "G2")),
                      type=factor(c("range", "range", "range"))
                       )

groups <- tibble(id=factor(unique(example$group)), 
                 content=factor(unique(example$group)))

timevis(data = example, group = groups)

I get this timeline : Capture d’écran 2020-05-28 à 17.17.29.pdf

Thanks !

Matthieu

daattali commented 4 years ago

I'm fairly certain this is a limitation of the underlying javascript library, not the R pacakge. If you can verify that you can use these dates with https://visjs.github.io/vis-timeline/docs/timeline/ then I'll have to look at this as a bug.

K-lone commented 4 years ago

I tried the dates on: https://jsfiddle.net/api/post/library/pure/ (I don't know anything in html) ... and it did not work either. It seems indeed to be a problem of the javascript library. The strange thing is that it was working with previous versions of timevis and R: https://github.com/daattali/timevis/issues/34. I was trying to build an app to build a shared chronology with shiny ... and timevis was the only interactive tool for timelines in R :(

daattali commented 4 years ago

Do you have a small reprex that worked in timevis v0.4 but doesn't work in v0.5? If so, post it here and I'll take a look

K-lone commented 4 years ago

Thanks a lot for your time @daattali. you can find a reprex in my first post that worked with 0.4 (this code don't work).

I worked around this problem and find a strange solution:

Strange isn't it?

Thus, for the previous reprex, the following code works:

example <- data.frame(id= 1:3,
                      content= as.character(c("A", "B", "C")),
                      start= factor(c("-000700", "0090", "100")),
                      end= factor(c("-000400", "300", "700")),
                      group= factor(c("G1", "G1", "G2")),
                      type=factor(c("range", "range", "range"))
                       )

groups <- tibble(id=factor(unique(example$group)), 
                 content=factor(unique(example$group)))

timevis(data = example, group = groups)
daattali commented 4 years ago

It looks like your workaround for specifying dates does indeed works. I'm almost certain this is a bug to do with how dates are handled in javascript by the visjs library.

I wasn't able to reproduce the regression bug though. The minimal reprex seems to be

example <- data.frame(id= 1:3,
                      content= as.character(c("A", "B", "C")),
                      start= factor(c("-700", "90", "100")))
timevis::timevis(data = example)

And I went all the way back to version 0.2 and it never seemed to have worked. Please show me exact code and a specific version when this was not an issue.

K-lone commented 4 years ago

ok my apologize for my previous post. I checked all my timevis codes and I do manage to find the version that was working (I am still thinking 0.4 but as I have updated my package and my system a few time ago, I cannot be sure of it). As a clue, in this post https://github.com/daattali/timevis/issues/34, a very similar reprex was working with BCE dates in Rstudio.

daattali commented 4 years ago

If it's different behaviour in RStudio's browser vs chrome, it's definitely a javascript issue or an issue with the browser's javascript engine parsing old dates. I don't think there's much I can do on the timevis side, unless you find out that there's a specific format that we can reliably convert old dates to automatically to make them work

K-lone commented 4 years ago

Yes it is what I have done juggling with mutate, ifelse and str_pad... and now it works like a charm :) Thanks !

K-lone commented 4 years ago

A last precision for people who want to deploy the app on a server, the behavior change a little bit: for dates between 0 and 999 CE, you have to put 4 numbers (400 CE => 0400).

daattali commented 4 years ago

If there are special ways to get certain dates to work (how do you get negative dates to work?) do you want to add documentation?

K-lone commented 4 years ago

yes of course. In which form ? a reprex ?

daattali commented 4 years ago

No, I mean literally add a sentence to the timevis function documentation saying in brief how to make it work with old dates

On Sat., May 30, 2020, 15:21 K-lone, notifications@github.com wrote:

yes of course. In which form ? a reprex ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/daattali/timevis/issues/99#issuecomment-636373283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIQFDX2WY4PVNQPLMZPM3RUFMDLANCNFSM4NNRJKSQ .

K-lone commented 4 years ago

I will write something ina fork of the readme file, is it ok ?

daattali commented 4 years ago

Not in the readme, it should go in the function documentation

Mitlley commented 3 years ago

As a rookie user of R and timevis, it was hard to find function documentation. This is a really great feature but it's really hidden, I reached this workaround by a question in stackoverflow. Any chance we may document it on the readme?

daattali commented 3 years ago

The README is for providing an overview of a package, not just into the specific edge cases of functions. It's completely standard to place such details in the function documentation, and it's an essential skill to learn to use the documentation in R.

The problem is that this is not even in the function documentation yet, as you can see from the fact that this issue is still open. Feel free to submit a PR to add this info.

daattali commented 3 years ago

Fixed in 172274fcca8ed2eba6a84155de1e4f58e456a695