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

adaptive-linechart

v1.3.0

Published

Independent library to draw line-chart in browser.

Downloads

19

Readme

adaptive-linechart :chart_with_upwards_trend:

Version 1.3.0

This is a small library to draw charts in the browser. All elements of chart will be set up automaticaly based on data. You can adjust the layout of the chart by usinf external CSS styles for classes .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend, .chart-legend-item, .chart-legend-color. Maximal 10 lines in the chart. The values on axis-x may be Unix time-stamp or numercal. The chart uses the global variable isMobil (Boolean). If false, live data are shown by "mouse-over". By click on item in the legend hide/show line on chart. The library has own simple logger that writes messages to the console. If needed, you can rewrite this logger and redirect messages to another target.

Additional supplied function to convert CSV to time-series.

Example

This example creates a chart with 3 lines in parent element with ID 'charts':

var chartData = [
    {
        obj_name: 'Stock preis',
        par_name: ' Open',
        values: '1565301600/138.6100;1565560800/137.0700;1565647200/136.0500;1565733600/136.3600;1565820000/134.3900'
    },
    {
        obj_name: 'Stock preis',
        par_name: ' Hight',
        vaues: '1565301600/139.3800;1565560800/137.8600;1565647200/138.8000;1565733600/136.9200;1565820000/134.5800'
    },
    {
        obj_name: 'Stock preis',
        par_name: ' Low',
        values:  '1565301600/136.4600;1565560800/135.2400;1565647200/135.0000;1565733600/133.6700;1565820000/132.2500'
    }
];

var lchart =  new LineChart(document.getElementById('charts'),null, null, 'Example Chart-Line', null);

for(i=0; i < chartData.length; i++) {
    lchart.addLine(chartData[i]);
}
            
lchart.draw();

Live example

Public methods

LineChart(container, chartId, width, title, className) - create an object of type LineChart and HTML code for the chart.

  • container - Reference to parent element for chart. If null: use BODY as parent element.
  • chartId - String. Identifier for the chart. Optional. If not defined use random integer.
  • width - Integer. Width in pixel. Optional. Default use available width in parent element. Height set automaticaly.
  • title - String. Title of chart. Optional. If null: don't create title.
  • className - String. Class for div of chart. Optional. Default "linechart".
  • axisXType String. For time based values on axis X set "time" (Default). For number based values "numer".

addLine(lineData) - add data for a new line and automatically create a new item in the legend. Return true if no problem detected, otherwise false.

lineData - The object represents data for one line in the chart.

  • obj_name - String. Name of object related to the chart. Used in legend.
  • par_name - String. Name of the parameter that represents the current line. Used in legend.
  • par_id - Integer. Optional ID of this line. May be used to request data from backend.
  • values - String. If axisXType "time" format "Unix-Timestamp/Value;Unix-Timestamp/Value;..". If axisXType "number" format "Number X/Number Y; Number X/Number Y/..." For number the step min. 1E-09 max. 1E18.
  • connectIfMissing - Boolean. If false don't draw line where data are missing, else connect begin and end of range where data are mising. Default false.

draw() - draw graphic. Skip lines if properties hidden=true or isEmpty=true.

clear() - clear graphic. Legend stays visible.

resize(difWidth, difHeight) - Change size of chart and redraw. May be used if size of parent panel changed but data in lines stay the same.

  • difWidth - Signed integer. Difference in width.
  • difHeight - Signed integer. Difference in height.

updateLines(lines) - Update data in chart and redraw this one. Return true if no problem detected, else false. May be used if data inlines changed.

  • lines - Array of lineData.

isEmpty() - Return true if all lines are empty

avgStep - Set time interval of measurement data on graph. Several measured values are combined to flatten peaks in the graph. value in seconds. Optional.

lines[] - array containing all lines

chartId - chart Id. Used to reference exactly to object or HTML element.

Utility

scvToTimeSeries(csv) - process CSV and return array of objects

{name: "Name of serie", data: "Unix-Timestamp/Value;Unix-Timestamp/Value"}.

Assume the first column contains data-time as string. The CSV may contain many columns. Name of serie taken from header. Values may be empty. This function needs the package Moment.js

Contact

If you have any questions, please contact me [email protected]

License

MIT © Andrej Koslov