npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chroniton

v1.1.0

Published

a timeline and time selector component

Downloads

5

Readme

chroniton

A time slider input for time-based visualizations and data.

Features

  • Customizable label formatting
  • API and UI for playing & pausing time
  • Smart label position for current value
  • APIs for setting and retrieving time data
  • Touch-compatible for phones and such
  • Keybindings for navigating with ← and →

Installation

The most recommended technique is to use browserify and use var chroniton = require('chroniton') to get the library.

$ npm install --save chroniton

Otherwise, download chroniton-bundle.js for chroniton with d3 included, or chroniton-only.js if you already are included d3 on your page as a global variable. Use the latter, for instance, if you have a script-tag include like <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>. You'll need to copy these files to your server.

There's an example of the necessary CSS to style chroniton in chroniton-example.css.

API

This follows the d3 reusable charts pattern and uses d3 internally, so documentation from that library is useful to complement this documentation.

chroniton()

Constructs a new timeline instance with default values.

All of the following API methods beginning with . are called on an instance created with chroniton().

This exposes a function that can either be called in a chain with d3's selection.call method or called directly as chroniton()(selection).

Example

// using d3
d3.select(document.body)
    .append('div')
    .call(chroniton());

// or not using d3
var div = document.body.appendChild(document.createElement('div'));
chroniton()(div);

.domain([start, end])

Given an array of two Date objects, set these as the earliest and latest date selectable through the input.

Example

d3.select(document.body)
  .append('div')
  .call(
    chroniton()
      .domain([new Date(+new Date() - 60 * 1000), new Date()])

.keybinding(true or false)

Turn on and off the default keybindings that link arrow left & right keys to moving the value forward and backward.

.labelFormat(function)

Use a different format to show the 'now' label in the input. The default value is d3.time.format("%Y-%m-%d"). The function should take a Date object as an argument and return a string. See d3.time.format documentation for hints.

Example

d3.select(document.body)
  .append('div')
  .call(
    chroniton()
      // hours and minutes - time format
      .labelFormat(d3.time.format('%X')));

.hideLabel()

The equvalent of calling .labelFormat(function() { return ''; }): this hides the label that shows what the current value is.

.width(number), .height(number)

Change these dimensions of the graph.

.tapAxis(function)

Call an arbitrary function on the input's axis object. Useful for calling any of the d3.svg.axis methods before the thing is constructed.

Example

d3.select(document.body)
  .append('div')
  .call(
    chroniton()
      .tapAxis(function(axis) { axis.ticks(5); }));

.on('change', function)

Listen for changes in the input. Programmatic changes also fire this event. Calls the given callback function with a current value as a Date object.

Example

d3.select(document.body)
  .append('div')
  .call(
    chroniton()
    .on('change', function(d) { alert(d); }));

.setValue(Date object, transition?)

Set the value of the input to a given Date object, redraw it, and fire a change event.

The transition argument, by default false, is whether the timeline should smoothly transition between the current date and the given date. If it's true, it'll transition with default options. Otherwise, you can give an object with options:

.isAtEnd() & .isAtStart()

Return a boolean true or false value for whether the input is at the beginning or end of its permitted date range.

.playbackRate(number)

Set the playback rate multiplier. The default is for the slider to move at 10px per second: this will change that by a given multiplier.

.play()

Start playing: this animates the slider and emits change events as its value changes.

.pause()

Pause playing, keeping the playhead in its current place.

.playButton(true or false)

Set whether to show a play / pause button on the input. Clicking the button plays or pauses.

.playPause()

Toggles chart between playing and pausing status.

.stop()

Pause playing and return the playhead to the beginning.

.isPlaying()

Returns a boolean for whether the control is currently playing.

.loop(true or false)

By default loop is set to false. You can call this function so that when you call .play() the input loops once it hits the end rather than stopping.

Development

$ git clone [email protected]:tmcw/chroniton.git
$ npm install

Run npm start to rebuild the source and start a development server on localhost:1337. There's a testing page at example/index.html.

Run npm run bundle to regenerate the bundle and standalone files.