Using a conditional mark in Plot to make a timeline

Hello,
I’m trying to make a timeline using Plot regarding internet shutdowns in different countries. In my dataset I have a start date and end date so I’m able to see these on the chart. However, some internet shutdowns are ongoing so there is no end date on certain records - in these situations they don’t appear on the chart and I don’t know how to work around that. Does anyone know if there is a way to create a conditional so if the end date is null it’s marked from the start date to the end of the timeline? Or another alternative?

Thanks

This is my code here:

Plot.plot({
  color: {legend: true},
  marginLeft: 150,
  marginBottom: 50,
  width: 1000,
  height: 1000,
  axis: true,
  x: {
    axis: "top",
    grid: true,
  },
  marks: [
    Plot.barX(dataShutdown, {
      x1: "start_date",
      x2: "end_date",
      y: "country",
      sort: {y: "x1"},
      fill: "shutdown_type",
    }),
  ]
})

This is what the chart looks like so far:

1 Like

Values for the channels like x1, x2, or y etc can be functions so you can deal with conditionals there. Thus, perhaps something like the following would work:

let end_date = d3.max(dataShutdown, o => o.end_date);

Plot.plot(
  ...
  marks: [
    Plot.barX(dataShutdown, {
      ...
      x2: d => d.end_date || end_date
    })
  ]
)

Of course, it’s hard to say without a look at the data and the easiest way to share the data is to share a link to public notebook.

Thanks for the help, that’s good to know they can be functions.

This is the link to the notebook!