# Using a conditional mark in Plot to make a timeline

**URL:** <https://talk.observablehq.com/t/using-a-conditional-mark-in-plot-to-make-a-timeline/8082>\
**Category:** Help\
**Created:** [July 11, 2023, 10:45am UTC](https://talk.observablehq.com/t/using-a-conditional-mark-in-plot-to-make-a-timeline/8082 "2023-07-11T10:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![calm\_computer](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@calm\_computer](https://talk.observablehq.com/u/calm_computer)\
**Post date:** [July 11, 2023, 10:45am UTC](https://talk.observablehq.com/t/using-a-conditional-mark-in-plot-to-make-a-timeline/8082/1 "2023-07-11T10:45:11Z")

</div>

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:

```auto
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:

 ![Screenshot 2023-07-11 at 11.43.50](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/8/89597f00f10a0fd1ed354b6a6275a698573ac42b.png)

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [July 11, 2023, 11:00am UTC](https://talk.observablehq.com/t/using-a-conditional-mark-in-plot-to-make-a-timeline/8082/2 "2023-07-11T11:00:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![calm\_computer](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@calm\_computer](https://talk.observablehq.com/u/calm_computer)\
**Post date:** [July 11, 2023, 11:09am UTC](https://talk.observablehq.com/t/using-a-conditional-mark-in-plot-to-make-a-timeline/8082/3 "2023-07-11T11:09:02Z")

</div>

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

This is [the link](https://observablehq.com/d/966694fba46bd969) to the notebook!
