1.0.1 • Published 2 years ago

@mhjuma/timeline v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

D3 Timeline

GitHub npm (scoped) GitHub code size in bytes

d3 timeline with brush axis.

Screenshot

Installation

NPM

npm install @mhjuma/timeline

CDN

<script type="text/javascript" src="https://unpkg.com/@mhjuma/timeline"></script>

Usage

const domElement = document.getElementById('app');

const chart = timeline()
    .width(1920)
    .height(1020)
    .data(myData)
    .render(domElement);

Data Contract

The data object passed to the timeline chart must be an array of the following type:

interface Data {
    name: string;
    start: string;
    end?: string;
    group?: string;
    track?: number;
}

Where the start and end values are either Date objects or a string that is ISO8601 compliant.

PropertyTypeRequiredDescription
namestringYesDatapoint label
startDate or stringYesStart time for datapoint
endDate or stringNoEnd time for interval datapoint
groupstringNoGroup the datapoint belongs to
tracknumberNoTrack (row) the datapoint will be drawn on within the group

Example:

const myData = [
    {
        name: 'foo',
        start: '2022-01-01T00:00:00.000Z',
        end: '2022-01-10T00:00:00.000Z',
    },
    {
        name: 'foo',
        start: '2022-01-01T00:00:00.000Z',
        end: '2022-01-10T00:00:00.000Z',
    }
];

API

FunctionDescriptionDefault
width(width?: number)Chart width in px960
height(width?: number)Chart height in px500
margin(margin?: { top: number, right: number, bottom: number, left: number })Chart margins in px{ top: 20, right: 20, bottom: 20, left: 20 }
backgroundColor(color?: string)Chart background color'#FFFFFF'
gridColor(color?: string)Gridlines color'#EAEAEA'
nodeColor(color: (d: Data) => string)Callback to set datapoint background colorschemeAccent
textColor(color: (d: Data) => color)Callback to set datapoint text color'black'
text(text: (d: Data) => string)Callback to set datapoint labeld.name
tooltips(tooltips: boolean or (domElement: SVGGElement, visible: boolean, data: Data) => void)Boolean to show default tooltip or callback to set custom tooltipfalse
xAxis(xAxis?: boolean)Boolean to show xAxis for timeline and brushfalse
xBrush(xBrush?: boolean)Boolean to show brushfalse
click(click: (d: Data) => void)Callback when a datapoint is clickedundefined
highlight(click: (d: Data) => boolean)Callback to determine if datapoint is highlightedundefined
data(data: Data[])Data array[]
render(domElement: HTMLElement)Renders the chartundefined

Credit

This project was inspired by the following projects:

Changelog

View recent updates

License

MIT