Skip to content

Conversation

mhtorp
Copy link
Contributor

@mhtorp mhtorp commented Mar 31, 2022

This fix allows specifying subgroupStack = TRUE or subgroupStack = list(subgroup_id = TRUE) in the groups data.frame.

Current behaviour converts subgroupStack = "TRUE" to {subgroupStack: {0: "T", 1: "R", 2: "U", 3: "E"}}

@daattali
Copy link
Owner

daattali commented Apr 2, 2022

Is there an open issue that corresponds to this or is this a new issue?

@mhtorp
Copy link
Contributor Author

mhtorp commented Apr 2, 2022 via email

@daattali
Copy link
Owner

daattali commented Apr 4, 2022

Can you please share an example (for testing) with the full code of a timeline that uses this feature?

@mhtorp
Copy link
Contributor Author

mhtorp commented Apr 7, 2022

Here's a reprex that works using my fork and not using the current release.

## Example from https://visjs.github.io/vis-timeline/examples/timeline/groups/subgroups.html

library(jsonlite)
library(shiny)
library(timevis)

ui <- fluidPage(
    titlePanel("Timevis stacking bug"),

    sidebarLayout(
        sidebarPanel(
            checkboxInput("stack", "Stack nodes")
        ),
        mainPanel(
           timevis::timevisOutput("timeline")
        )
    )
)

vis_nodes <- jsonlite::parse_json('[
  {
    "id": "A",
    "start": "2014-01-20",
    "end": "2014-01-22",
    "type": "background",
    "group": "foo"
  },
  {
    "id": "B",
    "start": "2014-01-22",
    "end": "2014-01-23",
    "type": "background",
    "group": "foo",
    "className": "negative"
  },
  {
    "id": 0,
    "content": "no subgroup",
    "start": "2014-01-20",
    "end": "2014-01-22",
    "group": "foo"
  },
  {
    "id": "SG_1_1",
    "start": "2014-01-25",
    "end": "2014-01-27",
    "type": "background",
    "group": "bar",
    "subgroup": "sg_1",
    "subgroupOrder": 0
  },
  {
    "id": "SG_1_2",
    "start": "2014-01-26",
    "end": "2014-01-27",
    "type": "background",
    "className": "positive",
    "group": "bar",
    "subgroup": "sg_1",
    "subgroupOrder": 0
  },
  {
    "id": 1,
    "content": "subgroup0_1",
    "start": "2014-01-23T12:00:00",
    "end": "2014-01-26T12:00:00",
    "group": "bar",
    "subgroup": "sg_1",
    "subgroupOrder": 0
  },
  {
    "id": 2,
    "content": "subgroup0_2",
    "start": "2014-01-22T12:00:01",
    "end": "2014-01-25T12:00:00",
    "group": "bar",
    "subgroup": "sg_1",
    "subgroupOrder": 0
  },
  {
    "id": "SG_2_1",
    "start": "2014-02-01",
    "end": "2014-02-02",
    "type": "background",
    "group": "bar",
    "subgroup": "sg_2",
    "subgroupOrder": 1
  },
  {
    "id": "SG_2_2",
    "start": "2014-02-2",
    "end": "2014-02-03",
    "type": "background",
    "className": "negative",
    "group": "bar",
    "subgroup": "sg_2",
    "subgroupOrder": 1
  },
  {
    "id": 3,
    "content": "subgroup1_1",
    "start": "2014-01-27T02:00:00",
    "end": "2014-01-29",
    "group": "bar",
    "subgroup": "sg_2",
    "subgroupOrder": 1
  },
  {
    "id": 4,
    "content": "subgroup1_2",
    "start": "2014-01-28",
    "end": "2014-02-02",
    "group": "bar",
    "subgroup": "sg_2",
    "subgroupOrder": 1
  },
  {
    "id": "SG_3_1",
    "start": "2014-01-23",
    "end": "2014-01-25",
    "type": "background",
    "group": "bar",
    "subgroup": "sg_3",
    "subgroupOrder": 2,
    "content": "a"
  },
  {
    "id": "SG_3_2",
    "start": "2014-01-26",
    "end": "2014-01-28",
    "type": "background",
    "className": "positive",
    "group": "bar",
    "subgroup": "sg_3",
    "subgroupOrder": 2,
    "content": "b"
  },
  {
    "id": 5,
    "content": "subgroup2_1",
    "start": "2014-01-23T12:00:00",
    "end": "2014-01-26T12:00:00",
    "group": "bar",
    "subgroup": "sg_3",
    "subgroupOrder": 2
  },
  {
    "id": 6,
    "content": "subgroup2_2",
    "start": "2014-01-26T12:00:01",
    "end": "2014-01-29T12:00:00",
    "group": "bar",
    "subgroup": "sg_3",
    "subgroupOrder": 2
  },
  {
    "id": "background",
    "start": "2014-01-29",
    "end": "2014-01-30",
    "type": "background",
    "className": "negative",
    "group": "bar"
  },
  {
    "id": "background_all",
    "start": "2014-01-31",
    "end": "2014-02-02",
    "type": "background",
    "className": "positive"
  }
]', simplifyVector = TRUE)

vis_groups <- jsonlite::parse_json('[
  {
    "id": "bar", "content":"bar", "subgroupStack": true
  },{
    "id": "foo", "content": "foo", "subgroupStack": true
  }
]', simplifyVector = TRUE)

server <- function(input, output) {

    output$timeline <- timevis::renderTimevis({
      timevis::timevis(
        data = vis_nodes,
        groups = vis_groups,
        options = list(
          stack = input$stack,
          stackSubgroups = TRUE
        )
      )
    })
}

# Run the application
shinyApp(ui = ui, server = server)

@daattali daattali merged commit 5d5d53b into daattali:master Apr 19, 2022
@daattali
Copy link
Owner

Thanks for the great code, added!

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

Successfully merging this pull request may close these issues.

2 participants