{"id":13552104,"url":"https://github.com/walterra/d3-milestones","last_synced_at":"2025-12-30T00:05:23.832Z","repository":{"id":28081031,"uuid":"116027550","full_name":"walterra/d3-milestones","owner":"walterra","description":"A d3 based timeline visualization.","archived":false,"fork":false,"pushed_at":"2023-01-24T15:42:00.000Z","size":5481,"stargazers_count":136,"open_issues_count":13,"forks_count":25,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-04-15T00:50:20.342Z","etag":null,"topics":["d3js","dataviz","timeline","visualization"],"latest_commit_sha":null,"homepage":"https://walterra.github.io/d3-milestones","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/walterra.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-02T15:10:15.000Z","updated_at":"2024-04-08T10:34:34.000Z","dependencies_parsed_at":"2023-02-13T22:50:13.875Z","dependency_job_id":null,"html_url":"https://github.com/walterra/d3-milestones","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walterra%2Fd3-milestones","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walterra%2Fd3-milestones/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walterra%2Fd3-milestones/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walterra%2Fd3-milestones/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/walterra","download_url":"https://codeload.github.com/walterra/d3-milestones/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246925612,"owners_count":20855913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["d3js","dataviz","timeline","visualization"],"created_at":"2024-08-01T12:01:58.993Z","updated_at":"2025-12-30T00:05:23.821Z","avatar_url":"https://github.com/walterra.png","language":"JavaScript","funding_links":[],"categories":["HTML","others","JavaScript"],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/d3-milestones.svg?maxAge=2592000)](https://www.npmjs.com/package/d3-milestones)\n[![npm](https://img.shields.io/npm/l/d3-milestones.svg?maxAge=2592000)](https://www.npmjs.com/package/d3-milestones)\n[![npm](https://img.shields.io/npm/dt/d3-milestones.svg?maxAge=2592000)](https://www.npmjs.com/package/d3-milestones)\n[![github ci](https://github.com/walterra/d3-milestones/actions/workflows/ci.yml/badge.svg)](https://github.com/walterra/d3-milestones/actions/workflows/ci.yml)\n\n# d3-milestones\n\nA d3 based timeline visualization.\n\n![The Viking Timeline](https://github.com/walterra/d3-milestones/raw/main/src/stories/assets/vikings.png)\n\n- NPM: https://www.npmjs.com/package/d3-milestones\n- Github: https://github.com/walterra/d3-milestones\n- Storybook demos: https://walterra.github.io/d3-milestones\n\nIf you're using `d3-milestones` out in the wild I'd love to see what you came up with, just ping me on [twitter.com/walterra](https://www.twitter.com/walterra).\n\n## Installing\n\n`yarn add d3-milestones`.\n\nThe most quick way to get going is to use `unpkg.com` as a CDN to include the library directly into your HTML file.\n\n```html\n\u003clink rel=\"stylesheet\" href=\"https://unpkg.com/d3-milestones/build/d3-milestones.css\"\u003e\n\u003cscript src=\"https://unpkg.com/d3-milestones/build/d3-milestones.min.js\"\u003e\u003c/script\u003e\n\n\u003cdiv id=\"timeline\"\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n  milestones('#timeline')\n    .mapping({\n      'timestamp': 'year',\n      'text': 'title'\n    })\n    .parseTime('%Y')\n    .aggregateBy('year')\n    .render([\n      { year: 789, title: 'Vikings begin attacks on England.' },\n      { year: 840, title: 'Vikings found Dublin in Ireland.' }\n      ...\n      { year: 1050, title: 'The city of Oslo is founded in Norway.' },\n      { year: 1066, title: 'Battle of Hastings.' }\n    ]);\n\u003c/script\u003e\n```\n\nHead over here to see this example in action: https://beta.observablehq.com/@walterra/vikings-timeline.\n\n## Examples\n\nExamples are included using storybook:\n\n- [Vikings Timeline](https://walterra.github.io/d3-milestones/?path=/story/d3-milestones--vikings)\n- [Windows/macOS Timeline](https://walterra.github.io/d3-milestones/?path=/story/d3-milestones--os-category-labels)\n- [Ordinal Scale Example](https://walterra.github.io/d3-milestones/?path=/story/d3-milestones--ordinal-scale-example) - Demonstrates using an ordinal scale instead of time scale\n- [Ordinal Scale with Categories](https://walterra.github.io/d3-milestones/?path=/story/d3-milestones--ordinal-scale-categories-example) - Shows how to use ordinal scales with multiple categories\n\n## API Reference\n\n### General Usage\n\nTo initialize *d3-milestones*, pass a DOM Id to its main factory:\n\n```javascript\n  const vis = milestones('#wrapper');\n```\n\nThe returned object exposes the following API:\n\n\u003ca name=\"aggregateBy\" href=\"#aggregateBy\"\u003e#\u003c/a\u003e vis.\u003cb\u003eaggregateBy\u003c/b\u003e(\u003ci\u003einterval\u003c/i\u003e)\n\nSets the aggregation interval for the event data, where *interval* can be one of `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter` or `year`.\n\n\u003ca name=\"distribution\" href=\"#distribution\"\u003e#\u003c/a\u003e vis.\u003cb\u003edistribution\u003c/b\u003e(\u003ci\u003estring\u003c/i\u003e)\n\nSets the label distribution, can be `top-bottom`, `top` or `bottom`. Defaults to `top-bottom`. The options don't change for vertical layouts. `top` refers to labels on the left and `bottom` to labels on the right for that layout.\n\n\u003ca name=\"mapping\" href=\"#mapping\"\u003e#\u003c/a\u003e vis.\u003cb\u003emapping\u003c/b\u003e(\u003ci\u003econfigObject\u003c/i\u003e)\n\nSets overrides for the default attributes for the expected data structure of an event. This defaults to:\n\n```js\n  {\n    category: undefined,\n    entries: undefined,\n    timestamp: 'timestamp',  // Used only for time based scales\n    value: 'value',          // Used only for ordinal scale values\n    text: 'text',\n    url: 'url',\n    id: 'id',\n    textStyle: undefined,    // Field name for custom text styling\n    categoryStyle: undefined, // Field name for custom category label styling\n    bulletStyle: undefined   // Field name for custom bullet styling\n  };\n```\n\nThe method allows you to override single or multiple attributes to map them to fields in your original data with a single call like:\n\n```js\n    vis.mapping({\n      'timestamp': 'year',\n      'text': 'title'\n    })\n```\n\n**Custom Styling Fields:**\n\n- `textStyle`: Maps to a field in your data containing an object with CSS property-value pairs for event text labels.\n- `categoryStyle`: Maps to a field in your data containing an object with CSS property-value pairs for category labels.\n- `bulletStyle`: Maps to a field in your data containing an object with CSS property-value pairs for bullets (e.g., `background-color`, `border-color`, `padding`, `border-width`).\n\nExample with custom styling:\n\n```js\nvis.mapping({\n  'timestamp': 'year',\n  'text': 'title',\n  'bulletStyle': 'bulletStyle',\n  'categoryStyle': 'categoryStyle'\n})\n.render([\n  {\n    year: 1990,\n    title: \"Custom Red Bullet\",\n    bulletStyle: { \n      \"background-color\": \"#E12800\", \n      \"border-color\": \"#E12800\", \n      \"padding\": \"10px\" \n    }\n  }\n]);\n```\n\n\u003ca name=\"optimize\" href=\"#optimize\"\u003e#\u003c/a\u003e vis.\u003cb\u003eoptimize\u003c/b\u003e(\u003ci\u003eboolean\u003c/i\u003e)\n\nEnables/Disables the label optimizer. When enabled, the optimizer attempts to avoid label overlap by vertically displacing labels.\n\n\u003ca name=\"autoResize\" href=\"#autoResize\"\u003e#\u003c/a\u003e vis.\u003cb\u003eautoResize\u003c/b\u003e(\u003ci\u003eboolean\u003c/i\u003e)\n\nEnables/Disables auto resizing. Enabled by default, this adds listeners to resizing events of the browser window.\n\n\u003ca name=\"orientation\" href=\"#orientation\"\u003e#\u003c/a\u003e vis.\u003cb\u003eorientation\u003c/b\u003e(\u003ci\u003estring\u003c/i\u003e)\n\nSets the orientation of the timeline, can be either `horizontal` or `vertical`. Defaults to `horizontal`.\n\n\u003ca name=\"scaleType\" href=\"#scaleType\"\u003e#\u003c/a\u003e vis.\u003cb\u003escaleType\u003c/b\u003e(\u003ci\u003estring\u003c/i\u003e)\n\nSets the scale type of the timeline, can be either `time` or `ordinal`. Defaults to `time`.\n\n- `time`: Uses a time scale for chronological data with timestamps\n- `ordinal`: Uses an ordinal scale for categorical data without timestamps\n\n\u003ca name=\"parseTime\" href=\"#parseTime\"\u003e#\u003c/a\u003e vis.\u003cb\u003eparseTime\u003c/b\u003e(\u003ci\u003especifier\u003c/i\u003e)\n\nSpecifies the formatter for the timestamp field. The specifier string is expected to resemble a format described here: https://github.com/d3/d3-time-format#locale_format\n\n\u003ca name=\"labelFormat\" href=\"#labelFormat\"\u003e#\u003c/a\u003e vis.\u003cb\u003elabelFormat\u003c/b\u003e(\u003ci\u003especifier\u003c/i\u003e)\n\nThe `labelFormat` for the time label for each milestones defaults to `'%Y-%m-%d %H:%M'`. Using `aggregateBy`, `labelFormat` will be set automatically to a reasonable format corresponding to the aggregation level. Still, this method is available to override this behavior with a custom `labelFormat`.\n\n\u003ca name=\"urlTarget\" href=\"#urlTarget\"\u003e#\u003c/a\u003e vis.\u003cb\u003eurlTarget\u003c/b\u003e(\u003ci\u003estring\u003c/i\u003e)\n\nCustomizes the `target` attribute when labels are provided with a URL. Can be `_blank`, `_self`, `_parent` or  `_top`.\n\n\u003ca name=\"useLabels\" href=\"#useLabels\"\u003e#\u003c/a\u003e vis.\u003cb\u003euseLabels\u003c/b\u003e(\u003ci\u003eboolean\u003c/i\u003e)\n\nEnables/Disables the display of labels.\n\n\u003ca name=\"render\" href=\"#render\"\u003e#\u003c/a\u003e vis.\u003cb\u003erender\u003c/b\u003e(\u003ci\u003e[data]\u003c/i\u003e)\n\nWhen called without `data` this triggers re-rendering the existing visualization.\n\n`data` is expected to be an array of event objects with fields matching either the expected defaults (`timestamp` and `text` attribute) or the provided mapping via `.mapping()`.\n\n\u003ca name=\"renderCallback\" href=\"#renderCallback\"\u003e#\u003c/a\u003e vis.\u003cb\u003erenderCallback\u003c/b\u003e(\u003ci\u003efunction\u003c/i\u003e)\n\nSets a callback function that is executed after the visualization is fully rendered, allowing you to apply custom styling or modifications to the rendered elements. The callback is called after both initial renders and automatic re-renders due to window resizing.\n\n```js\nvis.renderCallback(function() {\n  // Apply additional customizations after rendering is complete\n  d3.select(\".milestones\").style(\"margin-left\", \"10%\");\n}).render(data);\n```\n\n\u003ca name=\"onEventClick\" href=\"#onEventClick\"\u003e#\u003c/a\u003e vis.\u003cb\u003eonEventClick\u003c/b\u003e(\u003ci\u003efunction\u003c/i\u003e)\n\nSet a callback which is executed when the text or image is clicked.\n\n```js\n  vis.onEventClick((d) =\u003e {\n    console.log('click', d);\n    alert(`\n      ${d.text} | ${d.timestamp}\n      ${JSON.stringify(d.attributes)}\n    `);\n  })\n```\n\n\u003ca name=\"onEventMouseOver\" href=\"#onEventMouseOver\"\u003e#\u003c/a\u003e vis.\u003cb\u003eonEventMouseOver\u003c/b\u003e(\u003ci\u003efunction\u003c/i\u003e)\n\nSet a callback which is executed when the mouse cursor is over text or image.\n\n```js\n  vis.onEventMouseOver((d) =\u003e {\n    console.log('mouseover', d);\n  })\n```\n\n\u003ca name=\"onEventMouseLeave\" href=\"#onEventMouseLeave\"\u003e#\u003c/a\u003e vis.\u003cb\u003eonEventMouseLeave\u003c/b\u003e(\u003ci\u003efunction\u003c/i\u003e)\n\nSet a callback which is executed when the mouse cursor is leaving text or image.\n\n```js\n  vis.onEventMouseLeave((d) =\u003e {\n    console.log('mouseleave', d);\n  })\n```\n\n## Disclaimer on DevOps/CI Observability\n\nThis repository uses [Elastic APM](https://www.elastic.co/observability/application-performance-monitoring) to track performance of functional tests. It uses `@elastic/apm-rum` as a `devDependency` to be run only as part of the tests. No telemetry library is part of the published package.\n\n\n## More\n\n`d3-milestones` is also available as a visualization plugin for Kibana here: https://github.com/walterra/kibana-milestones-vis\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalterra%2Fd3-milestones","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwalterra%2Fd3-milestones","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalterra%2Fd3-milestones/lists"}