daattali / timevis

đŸ“… Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
655 stars 157 forks source link

Cannot assign HTML attributes to table in content #146

Closed trafficonese closed 10 months ago

trafficonese commented 10 months ago

In the content I would like to place a bigger table with some custom styling and custom classes. But somehow it always filters out HTML attributes:

Here is an example. The CSS classes for the table, tr and td are not respected.

library(timevis)

dataBasic <- data.frame(
  number = c("Item one", "Item two" ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14"),
  end    = c(NA, NA, "2016-02-04", NA),
  os = sample(1:5, 4, T),
  cs = sample(1:5, 4, T)
)

dataBasic$content <- sprintf(
  '<table class="lsatimetbl"><tbody>
        <tr><td colspan="2"><em>Number %s</em></td></tr>
        <tr class="specialclass">
          <td class=\'os_%s\'>OS: %s</td>
          <td class="cs_%s">CY: %s</td>
        </tr>
      </tbody></table>',
  dataBasic$number, 
  dataBasic$os, dataBasic$os,
  dataBasic$cs, dataBasic$cs)

dataBasic <- dataBasic[,c("start","end","content")]

timevis(showZoom = FALSE, timezone = NULL) %>%
  timevis::addItems(dataBasic) %>%
  timevis::fitWindow(options = list(animation = TRUE))
trafficonese commented 10 months ago

This https://github.com/visjs/vis-timeline/issues/846 seems to be the issue..

trafficonese commented 10 months ago

downgrading to v1.0.0 seems to work.

The template function looks like this with 1.0.0: function(item) and the newer timevis versions: function(item, element, data)

daattali commented 10 months ago

Thanks for taking the time to trackd down the cause - you probably saved me an hour of my time. Unfortunately that "security fix" in vis-timeline a few years ago caused several issues, like this one https://github.com/daattali/timevis/issues/118

You're right that you can use v1 of the package if you want the older vis-timeline. I was also annoyed by the fact that upgrading caused a few new bugs, and for a while I considered trying to support different version of vis-timeline simultaneously, but I eventually decided against it as it would be a maintenance nightmare. Unfortunately you have to either use an old version that doesn't have all the newest features, or you have to use the newer version that has a few regression bugs.

I'm closing this issue as it seems you know what to do.