patternfly / patternfly-timeline

A time based / event series interactive visualization using d3.js. Use drag and zoom to navigate in time.
MIT License
136 stars 39 forks source link

patternfly-timeline

A time based/event series interactive visualization using d3.js. Use drag and zoom to navigate in time. View the demo here.

Based on the EventDrops timeline.

Usage

Include the src/timeline.js script in your page after d3:

<script src="https://github.com/patternfly/patternfly-timeline/raw/master/path/to/d3.js"></script>
<script src="https://github.com/patternfly/patternfly-timeline/raw/master/src/timeline.js"></script>

In the HTML source, create a new timeline chart, bind data to a DOM element, then call the chart on the element. Important: In order for the zoom slider to work correctly, the placeholder element must have position: relative or position: absolute styling.

var timelineChart = d3.chart.timeline();
d3.select('#chart_placeholder')
  .datum(data)
  .call(timelineChart);

The data must be an array of named time series with an optional details payload. For instance:

var json = [
  {
    "name":"Power Activity",
    "data":[
      {"date": "2016-04-08T15:07:37.374Z", "details": {"event": "vmPowerOn", "object": "vmName"}},
      {"date": "2016-04-08T15:07:37.374Z", "details": {"event": "vmPowerOn", "object": "vmName"}},
      {"date": "2016-04-15T21:04:16.247Z", "details": {"event": "vmPowerOn", "object": "vmName"}}
    ]
  },
  {
    "name":"Alarm/Error",
    "data":[
      {"date": "2016-04-21T01:06:19.126Z", "details": {"event": "vmPowerOn", "object": "vmName"}},
      {"date": "2016-04-16T13:07:15.205Z", "details": {"event": "vmPowerOff", "object": "hostName"}},
      {"date": "2016-04-07T22:35:41.145Z", "details": {"event": "vmPowerOff", "object": "hostName"}}
    ]
  }
];

Configuration

Patternfly-timeline follows the d3.js reusable charts pattern to let you customize the chart at will:

var timelineChart = d3.chart.timeline()
  .width(1200)
  .context(false)

Configurable values:

Styling

You can style all elements of the chart in CSS. Check the source to see the available selectors.

Extending / Development

First, install the dependencies:

npm install

For development purpose, you can use the following command:

npm start

It serves the demo at http://localhost:8080.

When your changes are done, ensure that all tests pass with:

npm test

Finally, if everything is fine, you can rebuild the library using:

npm run build

License

Patternfly Timeline is released under the MIT License