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

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

Closed
K-lone opened this issue May 28, 2020 · 17 comments
Closed

Comments

@K-lone
Copy link

K-lone commented May 28, 2020

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

@K-lone K-lone changed the title Timevis doesn't Work With Dates Before Common Era (or inferior to 100) Timevis doesn't work with dates Before Common Era (or inferior to 100) May 28, 2020
@daattali
Copy link
Owner

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
Copy link
Author

K-lone commented May 29, 2020

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: #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
Copy link
Owner

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
Copy link
Author

K-lone commented May 29, 2020

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:

  • for BCE dates (negative dates), you have to give a 6 numbers date (for example "-000400-01-01" or "-000400") and it works.
  • for dates from 0 to 99 CE, you have to give a 4 numbers date (for example, "0080-01-01" or "0010").
  • for dates superior to 100 CE, everything works.

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
Copy link
Owner

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
Copy link
Author

K-lone commented May 29, 2020

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 #34, a very similar reprex was working with BCE dates in Rstudio.

@daattali
Copy link
Owner

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
Copy link
Author

K-lone commented May 29, 2020

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

@K-lone
Copy link
Author

K-lone commented May 30, 2020

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
Copy link
Owner

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
Copy link
Author

K-lone commented May 30, 2020

yes of course. In which form ? a reprex ?

@daattali
Copy link
Owner

daattali commented May 30, 2020 via email

@K-lone
Copy link
Author

K-lone commented May 31, 2020

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

@daattali
Copy link
Owner

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

@Mitlley
Copy link

Mitlley commented Jul 16, 2020

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
Copy link
Owner

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
Copy link
Owner

Fixed in 172274f

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

3 participants