collab/mermaid/docs/syntax/timeline.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/timeline.md](../../packages/mermaid/src/docs/syntax/timeline.md).
6dd74de6
6dd74de7# Timeline Diagram
6dd74de8
6dd74de9> Timeline: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stable except for the icon integration which is the experimental part.
6dd74de10
6dd74de11"A timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life" [(Wikipedia)](https://en.wikipedia.org/wiki/Timeline).
6dd74de12
6dd74de13### An example of a timeline
6dd74de14
6dd74de15```mermaid-example
6dd74de16timeline
6dd74de17 title History of Social Media Platform
6dd74de18 2002 : LinkedIn
6dd74de19 2004 : Facebook
6dd74de20 : Google
6dd74de21 2005 : YouTube
6dd74de22 2006 : Twitter
6dd74de23```
6dd74de24
6dd74de25```mermaid
6dd74de26timeline
6dd74de27 title History of Social Media Platform
6dd74de28 2002 : LinkedIn
6dd74de29 2004 : Facebook
6dd74de30 : Google
6dd74de31 2005 : YouTube
6dd74de32 2006 : Twitter
6dd74de33```
6dd74de34
6dd74de35## Syntax
6dd74de36
6dd74de37The syntax for creating Timeline diagram is simple. You always start with the `timeline` keyword to let mermaid know that you want to create a timeline diagram.
6dd74de38
6dd74de39After that there is a possibility to add a title to the timeline. This is done by adding a line with the keyword `title` followed by the title text.
6dd74de40
6dd74de41Then you add the timeline data, where you always start with a time period, followed by a colon and then the text for the event. Optionally you can add a second colon and then the text for the event. So, you can have one or more events per time period.
6dd74de42
6dd74de43```json
6dd74de44{time period} : {event}
6dd74de45```
6dd74de46
6dd74de47or
6dd74de48
6dd74de49```json
6dd74de50{time period} : {event} : {event}
6dd74de51```
6dd74de52
6dd74de53or
6dd74de54
6dd74de55```json
6dd74de56{time period} : {event}
6dd74de57 : {event}
6dd74de58 : {event}
6dd74de59```
6dd74de60
6dd74de61**NOTE**: Both time period and event are simple text, and not limited to numbers.
6dd74de62
6dd74de63Let us look at the syntax for the example above.
6dd74de64
6dd74de65```mermaid-example
6dd74de66timeline
6dd74de67 title History of Social Media Platform
6dd74de68 2002 : LinkedIn
6dd74de69 2004 : Facebook : Google
6dd74de70 2005 : YouTube
6dd74de71 2006 : Twitter
6dd74de72```
6dd74de73
6dd74de74```mermaid
6dd74de75timeline
6dd74de76 title History of Social Media Platform
6dd74de77 2002 : LinkedIn
6dd74de78 2004 : Facebook : Google
6dd74de79 2005 : YouTube
6dd74de80 2006 : Twitter
6dd74de81```
6dd74de82
6dd74de83In this way we can use a text outline to generate a timeline diagram.
6dd74de84The sequence of time period and events is important, as it will be used to draw the timeline. The first time period will be placed at the left side of the timeline, and the last time period will be placed at the right side of the timeline.
6dd74de85
6dd74de86Similarly, the first event will be placed at the top for that specific time period, and the last event will be placed at the bottom.
6dd74de87
6dd74de88## Grouping of time periods in sections/ages
6dd74de89
6dd74de90You can group time periods in sections/ages. This is done by adding a line with the keyword `section` followed by the section name.
6dd74de91
6dd74de92All subsequent time periods will be placed in this section until a new section is defined.
6dd74de93
6dd74de94If no section is defined, all time periods will be placed in the default section.
6dd74de95
6dd74de96Let us look at an example, where we have grouped the time periods in sections.
6dd74de97
6dd74de98```mermaid-example
6dd74de99timeline
6dd74de100 title Timeline of Industrial Revolution
6dd74de101 section 17th-20th century
6dd74de102 Industry 1.0 : Machinery, Water power, Steam <br>power
6dd74de103 Industry 2.0 : Electricity, Internal combustion engine, Mass production
6dd74de104 Industry 3.0 : Electronics, Computers, Automation
6dd74de105 section 21st century
6dd74de106 Industry 4.0 : Internet, Robotics, Internet of Things
6dd74de107 Industry 5.0 : Artificial intelligence, Big data, 3D printing
6dd74de108```
6dd74de109
6dd74de110```mermaid
6dd74de111timeline
6dd74de112 title Timeline of Industrial Revolution
6dd74de113 section 17th-20th century
6dd74de114 Industry 1.0 : Machinery, Water power, Steam <br>power
6dd74de115 Industry 2.0 : Electricity, Internal combustion engine, Mass production
6dd74de116 Industry 3.0 : Electronics, Computers, Automation
6dd74de117 section 21st century
6dd74de118 Industry 4.0 : Internet, Robotics, Internet of Things
6dd74de119 Industry 5.0 : Artificial intelligence, Big data, 3D printing
6dd74de120```
6dd74de121
6dd74de122As you can see, the time periods are placed in the sections, and the sections are placed in the order they are defined.
6dd74de123
6dd74de124All time periods and events under a given section follow a similar color scheme. This is done to make it easier to see the relationship between time periods and events.
6dd74de125
6dd74de126## Wrapping of text for long time-periods or events
6dd74de127
6dd74de128By default, the text for time-periods and events will be wrapped if it is too long. This is done to avoid that the text is drawn outside the diagram.
6dd74de129
6dd74de130You can also use `<br>` to force a line break.
6dd74de131
6dd74de132Let us look at another example, where we have a long time period, and a long event.
6dd74de133
6dd74de134```mermaid-example
6dd74de135timeline
6dd74de136 title England's History Timeline
6dd74de137 section Stone Age
6dd74de138 7600 BC : Britain's oldest known house was built in Orkney, Scotland
6dd74de139 6000 BC : Sea levels rise and Britain becomes an island.<br> The people who live here are hunter-gatherers.
6dd74de140 section Bronze Age
6dd74de141 2300 BC : People arrive from Europe and settle in Britain. <br>They bring farming and metalworking.
6dd74de142 : New styles of pottery and ways of burying the dead appear.
6dd74de143 2200 BC : The last major building works are completed at Stonehenge.<br> People now bury their dead in stone circles.
6dd74de144 : The first metal objects are made in Britain.Some other nice things happen. it is a good time to be alive.
6dd74de145
6dd74de146```
6dd74de147
6dd74de148```mermaid
6dd74de149timeline
6dd74de150 title England's History Timeline
6dd74de151 section Stone Age
6dd74de152 7600 BC : Britain's oldest known house was built in Orkney, Scotland
6dd74de153 6000 BC : Sea levels rise and Britain becomes an island.<br> The people who live here are hunter-gatherers.
6dd74de154 section Bronze Age
6dd74de155 2300 BC : People arrive from Europe and settle in Britain. <br>They bring farming and metalworking.
6dd74de156 : New styles of pottery and ways of burying the dead appear.
6dd74de157 2200 BC : The last major building works are completed at Stonehenge.<br> People now bury their dead in stone circles.
6dd74de158 : The first metal objects are made in Britain.Some other nice things happen. it is a good time to be alive.
6dd74de159
6dd74de160```
6dd74de161
6dd74de162```mermaid-example
6dd74de163timeline
6dd74de164 title MermaidChart 2023 Timeline
6dd74de165 section 2023 Q1 <br> Release Personal Tier
6dd74de166 Bullet 1 : sub-point 1a : sub-point 1b
6dd74de167 : sub-point 1c
6dd74de168 Bullet 2 : sub-point 2a : sub-point 2b
6dd74de169 section 2023 Q2 <br> Release XYZ Tier
6dd74de170 Bullet 3 : sub-point <br> 3a : sub-point 3b
6dd74de171 : sub-point 3c
6dd74de172 Bullet 4 : sub-point 4a : sub-point 4b
6dd74de173```
6dd74de174
6dd74de175```mermaid
6dd74de176timeline
6dd74de177 title MermaidChart 2023 Timeline
6dd74de178 section 2023 Q1 <br> Release Personal Tier
6dd74de179 Bullet 1 : sub-point 1a : sub-point 1b
6dd74de180 : sub-point 1c
6dd74de181 Bullet 2 : sub-point 2a : sub-point 2b
6dd74de182 section 2023 Q2 <br> Release XYZ Tier
6dd74de183 Bullet 3 : sub-point <br> 3a : sub-point 3b
6dd74de184 : sub-point 3c
6dd74de185 Bullet 4 : sub-point 4a : sub-point 4b
6dd74de186```
6dd74de187
6dd74de188## Styling of time periods and events
6dd74de189
6dd74de190As explained earlier, each section has a color scheme, and each time period and event under a section follow the similar color scheme.
6dd74de191
6dd74de192However, if there is no section defined, then we have two possibilities:
6dd74de193
6dd74de1941. Style time periods individually, i.e. each time period(and its corresponding events) will have its own color scheme. This is the DEFAULT behavior.
6dd74de195
6dd74de196```mermaid-example
6dd74de197 timeline
6dd74de198 title History of Social Media Platform
6dd74de199 2002 : LinkedIn
6dd74de200 2004 : Facebook : Google
6dd74de201 2005 : YouTube
6dd74de202 2006 : Twitter
6dd74de203
6dd74de204```
6dd74de205
6dd74de206```mermaid
6dd74de207 timeline
6dd74de208 title History of Social Media Platform
6dd74de209 2002 : LinkedIn
6dd74de210 2004 : Facebook : Google
6dd74de211 2005 : YouTube
6dd74de212 2006 : Twitter
6dd74de213
6dd74de214```
6dd74de215
6dd74de216**NOTE**: that there are no sections defined, and each time period and its corresponding events will have its own color scheme.
6dd74de217
6dd74de2182. Disable the multiColor option using the `disableMultiColor` option. This will make all time periods and events follow the same color scheme.
6dd74de219
6dd74de220You will need to add this option either via mermaid.initialize function or directives.
6dd74de221
6dd74de222```javascript
6dd74de223mermaid.initialize({
6dd74de224 theme: 'base',
6dd74de225 startOnLoad: true,
6dd74de226 logLevel: 0,
6dd74de227 timeline: {
6dd74de228 disableMulticolor: false,
6dd74de229 },
6dd74de230 ...
6dd74de231 ...
6dd74de232```
6dd74de233
6dd74de234let us look at same example, where we have disabled the multiColor option.
6dd74de235
6dd74de236```mermaid-example
6dd74de237---
6dd74de238config:
6dd74de239 logLevel: 'debug'
6dd74de240 theme: 'base'
6dd74de241 timeline:
6dd74de242 disableMulticolor: true
6dd74de243---
6dd74de244 timeline
6dd74de245 title History of Social Media Platform
6dd74de246 2002 : LinkedIn
6dd74de247 2004 : Facebook : Google
6dd74de248 2005 : YouTube
6dd74de249 2006 : Twitter
6dd74de250
6dd74de251```
6dd74de252
6dd74de253```mermaid
6dd74de254---
6dd74de255config:
6dd74de256 logLevel: 'debug'
6dd74de257 theme: 'base'
6dd74de258 timeline:
6dd74de259 disableMulticolor: true
6dd74de260---
6dd74de261 timeline
6dd74de262 title History of Social Media Platform
6dd74de263 2002 : LinkedIn
6dd74de264 2004 : Facebook : Google
6dd74de265 2005 : YouTube
6dd74de266 2006 : Twitter
6dd74de267
6dd74de268```
6dd74de269
6dd74de270### Customizing Color scheme
6dd74de271
6dd74de272You can customize the color scheme using the `cScale0` to `cScale11` theme variables, which will change the background colors. Mermaid allows you to set unique colors for up-to 12 sections, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on.
6dd74de273In case you have more than 12 sections, the color scheme will start to repeat.
6dd74de274
6dd74de275If you also want to change the foreground color of a section, you can do so use theme variables corresponding `cScaleLabel0` to `cScaleLabel11` variables.
6dd74de276
6dd74de277**NOTE**: Default values for these theme variables are picked from the selected theme. If you want to override the default values, you can use the `initialize` call to add your custom theme variable values.
6dd74de278
6dd74de279Example:
6dd74de280
6dd74de281Now let's override the default values for the `cScale0` to `cScale2` variables:
6dd74de282
6dd74de283```mermaid-example
6dd74de284---
6dd74de285config:
6dd74de286 logLevel: 'debug'
6dd74de287 theme: 'default'
6dd74de288 themeVariables:
6dd74de289 cScale0: '#ff0000'
6dd74de290 cScaleLabel0: '#ffffff'
6dd74de291 cScale1: '#00ff00'
6dd74de292 cScale2: '#0000ff'
6dd74de293 cScaleLabel2: '#ffffff'
6dd74de294---
6dd74de295 timeline
6dd74de296 title History of Social Media Platform
6dd74de297 2002 : LinkedIn
6dd74de298 2004 : Facebook : Google
6dd74de299 2005 : YouTube
6dd74de300 2006 : Twitter
6dd74de301 2007 : Tumblr
6dd74de302 2008 : Instagram
6dd74de303 2010 : Pinterest
6dd74de304
6dd74de305```
6dd74de306
6dd74de307```mermaid
6dd74de308---
6dd74de309config:
6dd74de310 logLevel: 'debug'
6dd74de311 theme: 'default'
6dd74de312 themeVariables:
6dd74de313 cScale0: '#ff0000'
6dd74de314 cScaleLabel0: '#ffffff'
6dd74de315 cScale1: '#00ff00'
6dd74de316 cScale2: '#0000ff'
6dd74de317 cScaleLabel2: '#ffffff'
6dd74de318---
6dd74de319 timeline
6dd74de320 title History of Social Media Platform
6dd74de321 2002 : LinkedIn
6dd74de322 2004 : Facebook : Google
6dd74de323 2005 : YouTube
6dd74de324 2006 : Twitter
6dd74de325 2007 : Tumblr
6dd74de326 2008 : Instagram
6dd74de327 2010 : Pinterest
6dd74de328
6dd74de329```
6dd74de330
6dd74de331See how the colors are changed to the values specified in the theme variables.
6dd74de332
6dd74de333## Themes
6dd74de334
6dd74de335Mermaid supports a bunch of pre-defined themes which you can use to find the right one for you. PS: you can actually override an existing theme's variable to get your own custom theme going. Learn more about [theming your diagram](../config/theming.md).
6dd74de336
6dd74de337The following are the different pre-defined theme options:
6dd74de338
6dd74de339- `base`
6dd74de340- `forest`
6dd74de341- `dark`
6dd74de342- `default`
6dd74de343- `neutral`
6dd74de344
6dd74de345**NOTE**: To change theme you can either use the `initialize` call or _directives_. Learn more about [directives](../config/directives.md)
6dd74de346Let's put them to use, and see how our sample diagram looks in different themes:
6dd74de347
6dd74de348### Base Theme
6dd74de349
6dd74de350```mermaid-example
6dd74de351---
6dd74de352config:
6dd74de353 logLevel: 'debug'
6dd74de354 theme: 'base'
6dd74de355---
6dd74de356 timeline
6dd74de357 title History of Social Media Platform
6dd74de358 2002 : LinkedIn
6dd74de359 2004 : Facebook : Google
6dd74de360 2005 : YouTube
6dd74de361 2006 : Twitter
6dd74de362 2007 : Tumblr
6dd74de363 2008 : Instagram
6dd74de364 2010 : Pinterest
6dd74de365```
6dd74de366
6dd74de367```mermaid
6dd74de368---
6dd74de369config:
6dd74de370 logLevel: 'debug'
6dd74de371 theme: 'base'
6dd74de372---
6dd74de373 timeline
6dd74de374 title History of Social Media Platform
6dd74de375 2002 : LinkedIn
6dd74de376 2004 : Facebook : Google
6dd74de377 2005 : YouTube
6dd74de378 2006 : Twitter
6dd74de379 2007 : Tumblr
6dd74de380 2008 : Instagram
6dd74de381 2010 : Pinterest
6dd74de382```
6dd74de383
6dd74de384### Forest Theme
6dd74de385
6dd74de386```mermaid-example
6dd74de387---
6dd74de388config:
6dd74de389 logLevel: 'debug'
6dd74de390 theme: 'forest'
6dd74de391---
6dd74de392 timeline
6dd74de393 title History of Social Media Platform
6dd74de394 2002 : LinkedIn
6dd74de395 2004 : Facebook : Google
6dd74de396 2005 : YouTube
6dd74de397 2006 : Twitter
6dd74de398 2007 : Tumblr
6dd74de399 2008 : Instagram
6dd74de400 2010 : Pinterest
6dd74de401```
6dd74de402
6dd74de403```mermaid
6dd74de404---
6dd74de405config:
6dd74de406 logLevel: 'debug'
6dd74de407 theme: 'forest'
6dd74de408---
6dd74de409 timeline
6dd74de410 title History of Social Media Platform
6dd74de411 2002 : LinkedIn
6dd74de412 2004 : Facebook : Google
6dd74de413 2005 : YouTube
6dd74de414 2006 : Twitter
6dd74de415 2007 : Tumblr
6dd74de416 2008 : Instagram
6dd74de417 2010 : Pinterest
6dd74de418```
6dd74de419
6dd74de420### Dark Theme
6dd74de421
6dd74de422```mermaid-example
6dd74de423---
6dd74de424config:
6dd74de425 logLevel: 'debug'
6dd74de426 theme: 'dark'
6dd74de427---
6dd74de428 timeline
6dd74de429 title History of Social Media Platform
6dd74de430 2002 : LinkedIn
6dd74de431 2004 : Facebook : Google
6dd74de432 2005 : YouTube
6dd74de433 2006 : Twitter
6dd74de434 2007 : Tumblr
6dd74de435 2008 : Instagram
6dd74de436 2010 : Pinterest
6dd74de437```
6dd74de438
6dd74de439```mermaid
6dd74de440---
6dd74de441config:
6dd74de442 logLevel: 'debug'
6dd74de443 theme: 'dark'
6dd74de444---
6dd74de445 timeline
6dd74de446 title History of Social Media Platform
6dd74de447 2002 : LinkedIn
6dd74de448 2004 : Facebook : Google
6dd74de449 2005 : YouTube
6dd74de450 2006 : Twitter
6dd74de451 2007 : Tumblr
6dd74de452 2008 : Instagram
6dd74de453 2010 : Pinterest
6dd74de454```
6dd74de455
6dd74de456### Default Theme
6dd74de457
6dd74de458```mermaid-example
6dd74de459---
6dd74de460config:
6dd74de461 logLevel: 'debug'
6dd74de462 theme: 'default'
6dd74de463---
6dd74de464 timeline
6dd74de465 title History of Social Media Platform
6dd74de466 2002 : LinkedIn
6dd74de467 2004 : Facebook : Google
6dd74de468 2005 : YouTube
6dd74de469 2006 : Twitter
6dd74de470 2007 : Tumblr
6dd74de471 2008 : Instagram
6dd74de472 2010 : Pinterest
6dd74de473```
6dd74de474
6dd74de475```mermaid
6dd74de476---
6dd74de477config:
6dd74de478 logLevel: 'debug'
6dd74de479 theme: 'default'
6dd74de480---
6dd74de481 timeline
6dd74de482 title History of Social Media Platform
6dd74de483 2002 : LinkedIn
6dd74de484 2004 : Facebook : Google
6dd74de485 2005 : YouTube
6dd74de486 2006 : Twitter
6dd74de487 2007 : Tumblr
6dd74de488 2008 : Instagram
6dd74de489 2010 : Pinterest
6dd74de490```
6dd74de491
6dd74de492### Neutral Theme
6dd74de493
6dd74de494```mermaid-example
6dd74de495---
6dd74de496config:
6dd74de497 logLevel: 'debug'
6dd74de498 theme: 'neutral'
6dd74de499---
6dd74de500 timeline
6dd74de501 title History of Social Media Platform
6dd74de502 2002 : LinkedIn
6dd74de503 2004 : Facebook : Google
6dd74de504 2005 : YouTube
6dd74de505 2006 : Twitter
6dd74de506 2007 : Tumblr
6dd74de507 2008 : Instagram
6dd74de508 2010 : Pinterest
6dd74de509```
6dd74de510
6dd74de511```mermaid
6dd74de512---
6dd74de513config:
6dd74de514 logLevel: 'debug'
6dd74de515 theme: 'neutral'
6dd74de516---
6dd74de517 timeline
6dd74de518 title History of Social Media Platform
6dd74de519 2002 : LinkedIn
6dd74de520 2004 : Facebook : Google
6dd74de521 2005 : YouTube
6dd74de522 2006 : Twitter
6dd74de523 2007 : Tumblr
6dd74de524 2008 : Instagram
6dd74de525 2010 : Pinterest
6dd74de526```
6dd74de527
6dd74de528## Integrating with your library/website
6dd74de529
6dd74de530Timeline uses experimental lazy loading & async rendering features which could change in the future.The lazy loading is important in order to be able to add additional diagrams going forward.
6dd74de531
6dd74de532You can use this method to add mermaid including the timeline diagram to a web page:
6dd74de533
6dd74de534```html
6dd74de535<script type="module">
6dd74de536 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
6dd74de537</script>
6dd74de538```
6dd74de539
6dd74de540You can also refer the [implementation in the live editor](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done.