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

asciidoctor-chart

v0.3.0

Published

Asciidoctor Chart extension

Downloads

8

Readme

:bar_chart: Asciidoctor Chart Extension

Travis build status

An extension for Asciidoctor.js to render charts.

Install

Node.js

Install the dependencies:

$ npm install asciidoctor.js asciidoctor-chart

Create a file named chart.js with the following content and run it:

const asciidoctor = require('asciidoctor.js')()
const chart = require('asciidoctor-chart')

const input = `
[chart,line]
....
January,February,March
28,48,40
65,59,80
....`

chart.register(asciidoctor.Extensions)
console.log(asciidoctor.convert(input)) // <1>

const registry = asciidoctor.Extensions.create()
chart.register(registry)
console.log(asciidoctor.convert(input, {'extension_registry': registry})) // <2>

<1> Register the extension in the global registry <2> Register the extension in a dedicated registry

IMPORTANT

To effectively render the chart in your HTML page you will need to add the Chartist CSS and JavaScript:

<!DOCTYPE html>
<html>
  <head>
    <link href="node_modules/chartist/dist/chartist.min.css" rel="stylesheet">
  </head>
  <body>
    <!-- Site content goes here !-->
    <script src="node_modules/chartist/dist/chartist.min.js"></script>
  </body>
</html>

You will also need to add this JavaScript (after chartist.min.js) to generate all the charts in your <body>:

document.body.querySelectorAll('div.ct-chart').forEach((node) => {
  const options = {
    height: node.dataset['chartHeight'],
    width: node.dataset['chartWidth'],
    colors: node.dataset['chartColors'].split(',')
  }
  const dataset = Object.assign({}, node.dataset)
  const series = Object.values(Object.keys(dataset)
    .filter(key => key.startsWith('chartSeries-'))
    .reduce((obj, key) => {
      obj[key] = dataset[key]
      return obj
    }, {})).map(value => value.split(','))
  const data = {
    labels: node.dataset['chartLabels'].split(','),
    series: series
  }
  Chartist[node.dataset['chartType']](node, data, options)
})

You can also render a chart from a csv file.

Create a file named sales.csv with the following content:

January,February,March
28,48,40
65,59,80

And use the following syntax:

chart::sales.csv[bar,800,500]

Browser

Install the dependencies:

$ npm install asciidoctor.js asciidoctor-chart

Create a file named chart.html with the following content and open it in your browser:

<html>
  <head>
    <script src="node_modules/asciidoctor.js/dist/browser/asciidoctor.js"></script>
    <script src="node_modules/asciidoctor-chart/dist/browser/asciidoctor-chart.js"></script>
    <link href="node_modules/chartist/dist/chartist.min.css" rel="stylesheet">
  </head>
  <body>
    <div id="content"></div>
    <script>
      var input = '[chart,line]\n' +
        '....\n' +
        'January,February,March\n' +
        '28,48,40\n' +
        '65,59,80\n' +
        '....'

      var asciidoctor = Asciidoctor()
      var chart = AsciidoctorChart

      const registry = asciidoctor.Extensions.create()
      chart.register(registry)
      var result = asciidoctor.convert(input, {'extension_registry': registry})
      document.getElementById('content').innerHTML = result
    </script>
    <script src="node_modules/chartist/dist/chartist.min.js"></script>
    <script>
      document.body.querySelectorAll('div.ct-chart').forEach((node) => {
        const options = {
          height: node.dataset['chartHeight'],
          width: node.dataset['chartWidth'],
          colors: node.dataset['chartColors'].split(',')
        }
        const dataset = Object.assign({}, node.dataset)
        const series = Object.values(Object.keys(dataset)
          .filter(key => key.startsWith('chartSeries-'))
          .reduce((obj, key) => {
            obj[key] = dataset[key]
            return obj
          }, {})).map(value => value.split(','))
        const data = {
          labels: node.dataset['chartLabels'].split(','),
          series: series
        }
        Chartist[node.dataset['chartType']](node, data, options)
      })
    </script>
  </body>
</html>

<1> Register the extension in the global registry <2> Register the extension in a dedicated registry

Usage

You can configure the type (line or bar), the height and the width in pixel:

Using positional attributes

// in this order: type, width, height
chart::sales.csv[bar,800,500]

Using named attributes

chart::sales.csv[height=500,width=800,type=line]

By default the chart will be a 600px * 400px line chart.

How ?

This extension is using Chartist.js to render responsives charts.