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

@redsift/d3-rs-lines

v0.8.0

Published

Generates line charts using D3v4.

Downloads

1,161

Readme

d3-rs-lines

Circle CI npm MIT

d3-rs-lines generate a range of line charts via the D3 reusable chart convention. Supports area fills, hovers and highlights.

Example

View @redsift/d3-rs-lines on Codepen

Line chart

Sample bars with a bottom orientation

Multiple series

Sample bars with a left orientation

Usage

Browser

<script src="//static.redsift.io/reusable/d3-rs-lines/latest/d3-rs-lines.umd-es2015.min.js"></script>
<script>
    var chart = d3_rs_lines.html();
    d3.select('body').datum([ 1, 2, 3, 10, 100 ]).call(chart);
</script>

ES6

import { html as chart } from "@redsift/d3-rs-lines";
let eml = chart();
...

Require

var chart = require("@redsift/d3-rs-lines");
var eml = chart.html();
...

Datum

  • Simplest form, array of numbers: [1,2,3,4...]. View Datum result on Bricks
  • Datum includes parameters, Index and Value which form the datum [{ "l": 1,"v":1},{"l": 4,"v":6}], "l" represent the Index and "v" the Value. The simple datum generate a line starting at (1,1) and ending at (4,6). View Datum result on Bricks.
  • A set of line charts that can be achieved using different Value creating the datum [{"l":1,"v":[1,2,3]},{"l":2,"v":[3,2,1]},{"l":3,"v":[2,1,3]}], the advantage of using this datum format is that the different line charts can be stacked using the stacked property. View Datum result on Bricks.
  • Else generating each line separately in a datum array [[{"l":1,"v":3},{"l":2,"v":5}],[{"l":1,"v":1},{"l":6,"v":7}]], great for populating distinct chart. View Datum result on Bricks.
  • Datum also supports Unix timestamp (or epoch time) data-set which can be easily converted into specific calendar date using string specifiers. An example of a datum using epoch datum [ { "l" : 1461456000000, "v" : [ 12, 3 ] }, { "l" : 1461542400000, "v" : [ 5, 11 ] }, { "l" : 1461628800000, "v" : [ 8, 7 ]}], in this example the Index is set to epoch format. View Datum result on Bricks, in the example I used labelTime property to convert the Unix timestamp using the smart formatter call 'multi' and using tickCountIndex property to display only 4 ticks.

Parameters

This section gives an overview of all the properties available and how they can be used. Examples provided are linked to Codepens that can be easily edited.

Property|Description|Transition|Preview --------|-----------|----------|------- classed|String Customise SVG by adding, removing and toggling of CSS classes.|N | background | String, Number Change the background colour of the chart. |Y | Preview of background propertyExamples: Bricks / CodePen theme | String Change the chart theme which includes 'light'(default) and 'dark'. |Y | Preview of theme propertyExamples: Bricks / CodePen height, width | Integer Resize the height and width of chart. Default width: 420 pixels. |Y | Preview of height & width propertiesExamples: Bricks / CodePen size | Integer Resize the chart to a certain size changing both the width and height maintaining the default aspect ratio. |Y | Preview of size propertyExamples: Bricks / CodePen scale | Number Scale the entire chart by the scaling value. Used to zoom the chart or compensate for high DPI displays when rasterized. Default scale: 1.0. |Y| Examples: Bricks / CodePen margin | Number Resize the chart margin inside of the SVG container. Default margin: 26 pixels. |Y | Preview of margin propertyExamples: Bricks / CodePen inset | Number Resize the space inside the chart margin for the main chart element. This excludes items like legends. | Y| Examples: CodePen style| String Custom CSS to inject into chart|N | trim| Integer Trim the datum array, use for slicing the data on the chart. | N | Examples: CodePen minValue,maxValue| Number Sets the minimum and maximum Value range. Note that for log scales, minValue must be > 0.|Y | Preview of minValue & maxValue propertyExamples: Bricks / CodePen minIndex ,maxIndex | Number Sets the minimum and maximum Index range. Note that for log scales, minIndex must be > 0. |Y | Preview of minIndex & maxIndex propertyExamples: Bricks / CodePen tickCountIndex,tickCountValue|Number, String, Interval Function Hints at the number of ticks to set in the corresponding axis. Supports strings for example split time intervals when using Unix timestamp(or epoch time) Index values. Default tickCountIndex: 6 | N | Preview of tickCountIndex & tickCountValue propertiesExamples: Bricks / CodePen tickMinorIndex, tickMinorValue|Number, String, Interval Function Hints at the number of minor ticks to set in the corresponding axis. | N | Preview of tickMinorIndex & tickMinorValue propertiesExamples: Bricks / CodePen tickFormatIndex, tickFormatValue|String, Function Sets the formatting string or function for the ticks. | N| Preview of tickFormatIndex & tickFormatValue propertiesExamples: Bricks / CodePen tickDisplayIndex, tickDisplayValue|String, Integer Customise all tick presentation logic with this function. | N | Preview of tickDisplayIndex & tickDisplayValueExamples: Bricks / CodePen curve|String, Function, Interpolation function for the line. Standard functions excluding closed and open curves are usable by name e.g. 'curveStep'. If a function is supplied, it should implement custom curves. Default curve: 'curveCatmullRom' | Y | Preview of curve propertyExamples: Bricks / CodePen symbol|(Array of) String, Function Change the points connecting the lines into customised symbols or custom symbol types | N | Preview of symbolExamples: Bricks / CodePen symbolSize | Number Resize the symbol to a specific size. Default size: 32 | Y| Preview of symbolSize propertyExamples: Bricks / CodePen fill|String, Array, Function If function, in addition to usual data, index parameters, a 3rd string parameter indicates the context - one of area, stroke, symbol, legend | Y | Preview of fill propertyExamples: Bricks / CodePen fillAreaOpacity | Unit Number Fill the area of the graph to a certain opacity |N| Preview of fillAreaOpacityExamples: Bricks / CodePen fillArea|Boolean, (Array of) Boolean Set the lines fill. | N |Preview of fillArea propertyExamples: Bricks / CodePen fillStroke|Boolean, (Array of) Boolean Set the lines stroke. | N |Preview of fillStroke propertyExamples: Bricks / CodePen stacked | Boolean Enable stacking. Default value: false | Y|Preview of stacked propertyExamples: Bricks / CodePen stackOffset | String, Function Shift the baseline of the chart to give more emphasis on the changing values using different offset properties. |Y | Preview of stackOffset propertyExamples: Bricks / CodePen stackOrder | String, Function Stack the chart using different stack ordering properties. |Y | Preview of stackOrder propertyExamples: Bricks / CodePen animation|String Change the animation interpolating between points. Parameters: reveal, value, default.| Y| Codepen Example tipHtml|String, Function Add information to the tip of the chart. Parameters of the function are (d, i, s) where d is the data element, i is the index, s is the series of the data. | Y |Examples: CodePen animateAxis, animateLabels | Boolean Set the animation of the axis and label. Default value: true. | N |Codepen Example axisDisplayIndex,axisDisplayValue | Boolean Set the axes to display. Default axisDisplayIndex: true, axisDisplayValue: false. |N | Preview of axisDisplayIndex & axisDisplayValue propertiesExamples: Bricks / CodePen axisPaddingValue,axisPaddingIndex | Number Set the padding size of the axis. Default axisPaddingValue: 8, axisPaddingIndex: 8.|N | Preview of axisPaddingIndex & axisPaddingValue propertiesExamples: Bricks / CodePen axisValue | String Changes the axis label of value (on the y-axis) to the left or right. Default value: 'left'.| N | Preview of axisValue propertyExamples: Bricks / CodePen highlightIndex | (Array of)Number, Function Highlight a particular or an array of Index|Y | Preview of highlightIndex propertyExamples: Bricks / CodePen legend | (Array of)String, Number Add a legend for the lines in the chart. |N| Preview of legend propertyExamples: Bricks / CodePen legendOrientation | String Position the legend, positions include top, bottom, left, right or voronoi. Default orientation: 'bottom' | Y | Preview of legendOrientation propertyExamples: Bricks / CodePen legendOrientation('voronoi') | String Position the legend in an area containing the least number of intersecting lines. |N | Preview of legendOrientation property using the voronoi argumentExamples: Bricks / CodePen voronoiAttraction|Number -1...0...1 Use when legendOrientation set to voronoi. Specifies the attraction of the label to the data line. 0 implies no dragging, -1 pushes the labels away. Default value: 0.33 | Y | Preview of the voronoiAttraction propertyExamples: Bricks / CodePen gridIndex, gridValue | Boolean Add guidelines for Index or Value. Default gridIndex: false, gridValue: true. | N| Preview of gridIndex & gridValue property Examples: Bricks / CodePen labelTime | String, Function Interpret the Index value from timestamp and format it using string specifiers or the supplied function. 'multi' (string specifier) smartly displays the time and use the UTC format.| N|Preview of labelTime property Examples: Bricks / CodePen language | String Change the language format of the chart affecting digit, currency and time formats. |N | Examples: Bricks/ CodePen onClick|Function Handler for a click event on a data series. |N | Examples: CodePen legendSize|Number Height of the legend component (if present) |N legendIsToggleable|Boolean If true, the legend's items will have a checkbox that make it able to switch on/off data sets.|N tintColor|String Color of some components, only supports checkbox color for now|N

Time

The two main time formatter available in UTC or Local Time. UTC uses the time standard applied across the world which is unaffected by Daylight Saving Time whereas Local Time is set to your local timezone. To use any of the formatter a function is parsed to labelTime function. To apply UTC format, d3.utcFormat(specifier) is used, argument being the string specifiers and when using Local Time, only the string specifiers can be supply since by default the time format is set to Local Time.

timeMultiFormat is a smart formatter that displays the time in UTC using 'multi' as an argument which is parsed to the labelTime function. Use 'multi-local' to enable local timezone ticks. The tick display can be customised using the tickCountIndex function displaying the number of ticks for the Index. Bricks Example

Additional information about Time format for D3 can be found here.