MCPcopy
hub / github.com/jwilber/roughViz

github.com/jwilber/roughViz @main sqlite

repository ↗ · DeepWiki ↗
185 symbols 477 edges 27 files 110 documented · 59%
README

roughViz.js

roughViz.js is a reusable JavaScript library for creating sketchy/hand-drawn styled charts in the browser, based on D3v5, roughjs, and handy.

roughViz.js

Why?

Use these charts where the communication goal is to show intent or generality, and not absolute precision. Or just because they're fun and look weird.

Chart Types

Chart Type API
Bar roughViz.Bar
Horizontal Bar roughViz.BarH
Donut roughViz.Donut
Line roughViz.Line
Pie roughViz.Pie
Scatter roughViz.Scatter
Stacked Bar roughViz.StackedBar

Visit this link for interactive examples of each chart.

Features

Apply the features of roughjs to each chart:

roughness:

roughness examples

fillStyle fillStyle examples

fillWeight fillStyle examples

As well as additional chart-specific options (see API below)

Installation

Via CDN (expose the roughViz global in html):

<script src="https://unpkg.com/rough-viz@2.0.5"></script>

Via npm:

npm install rough-viz

Want to use with React? There's a wrapper!:

npm install react-roughviz

Want to use with Vue? There's a wrapper!:

npm install vue-roughviz

Want to use it with Python? Go crazy:

pip install py-roughviz

How to use

If you're using ESM, make sure to import the library:

import roughViz from "rough-viz";

Create some container elements, one for each chart:












In the javascript, just create charts, referencing the desired container:

// create Bar chart from csv file, using default options
 new roughViz.Bar({
    element: '#viz0', // container selection
    data: 'https://raw.githubusercontent.com/jwilber/random_data/master/flavors.csv',
    labels: 'flavor',
    values: 'price'
});

// create Donut chart using defined data & customize plot options
new roughViz.Donut(
  {
    element: '#viz1',
    data: {
      labels: ['North', 'South', 'East', 'West'],
      values: [10, 5, 8, 3]
    },
    title: "Regions",
    width: window.innerWidth / 4,
    roughness: 8,
    colors: ['red', 'orange', 'blue', 'skyblue'],
    stroke: 'black',
    strokeWidth: 3,
    fillStyle: 'cross-hatch',
    fillWeight: 3.5,
  }
);

API

roughViz.Bar

Required - element [string]: Id or class of container element. - data: Data with which to construct chart. Can be either an object or string.

  • If object: must contain labels and values keys:

    js new roughViz.Bar({ element: '.viz', data: {labels: ['a', 'b'], values: [10, 20]} })

  • If string: must be a path/url to a csv or tsv, and you must also specify the labels and values as separate attributes that represent columns in said file: js new roughViz.Bar({ element: '#viz0', data: 'stringToDataUrl.csv', labels: 'nameOfLabelsColumn', values: 'nameOfValuesColumn', })

Optional - axisFontSize [string]: Font-size for axes' labels. Default: '1rem'. - axisRoughness [number]: Roughness for x & y axes. Default: 0.5. - axisStrokeWidth [number]: Stroke-width for x & y axes. Default: 0.5. - bowing [number]: Chart bowing. Default: 0. - color [string]: Color for each bar. Default: 'skyblue'. - fillStyle [string]: Bar fill-style. Should be one of fillStyles shown above. - fillWeight [number]: Weight of inner paths' color. Default: 0.5. - font: Font-family to use. You can use 0 or gaegu to use Gaegu, or 1 or indie flower to use Indie Flower. Or feed it something else. Default: Gaegu. - highlight [string]: Color for each bar on hover. Default: 'coral'. - innerStrokeWidth [number]: Stroke-width for paths inside bars. Default: 1. - interactive [boolean]: Whether or not chart is interactive. Default: true. - labelFontSize [string]: Font-size for axes' labels. Default: '1rem'. - margin [object]: Margin object. Default: {top: 50, right: 20, bottom: 70, left: 100} - padding [number]: Padding between bars. Default: 0.1. - roughness [number]: Roughness level of chart. Default: 1. - simplification [number]: Chart simplification. Default 0.2. - stroke [string]: Color of bars' stroke. Default: black. - strokeWidth [number]: Size of bars' stroke. Default: 1. - title [string]: Chart title. Optional. - titleFontSize [string]: Font-size for chart title. Default: '1rem'. - tooltipFontSize [string]: Font-size for tooltip. Default: '0.95rem'. - xLabel [string]: Label for x-axis. - yLabel [string]: Label for y-axis.

roughViz.BarH

Required - element [string]: Id or class of container element. - data: Data with which to construct chart. Can be either an object or string.

  • If object: must contain labels and values keys:

    js new roughViz.BarH({ element: '.viz', data: {labels: ['a', 'b'], values: [10, 20]} })

  • If string: must be a path/url to a csv or tsv, and you must also specify the labels and values as separate attributes that represent columns in said file: js new roughViz.BarH({ element: '#viz0', data: 'stringToDataUrl.csv', labels: 'nameOfLabelsColumn', values: 'nameOfValuesColumn', })

Optional - axisFontSize [string]: Font-size for axes' labels. Default: '1rem'. - axisRoughness [number]: Roughness for x & y axes. Default: 0.5. - axisStrokeWidth [number]: Stroke-width for x & y axes. Default: 0.5. - bowing [number]: Chart bowing. Default: 0. - color [string]: Color for each bar. Default: 'skyblue'. - fillStyle [string]: Bar fill-style. Should be one of fillStyles shown above. - fillWeight [number]: Weight of inner paths' color. Default: 0.5. - font: Font-family to use. You can use 0 or gaegu to use Gaegu, or 1 or indie flower to use Indie Flower. Or feed it something else. Default: Gaegu. - highlight [string]: Color for each bar on hover. Default: 'coral'. - innerStrokeWidth [number]: Stroke-width for paths inside bars. Default: 1. - interactive [boolean]: Whether or not chart is interactive. Default: true. - labelFontSize [string]: Font-size for axes' labels. Default: '1rem'. - margin [object]: Margin object. Default: {top: 50, right: 20, bottom: 70, left: 100} - padding [number]: Padding between bars. Default: 0.1. - roughness [number]: Roughness level of chart. Default: 1. - simplification [number]: Chart simplification. Default 0.2. - stroke [string]: Color of bars' stroke. Default: black. - strokeWidth [number]: Size of bars' stroke. Default: 1. - title [string]: Chart title. Optional. - titleFontSize [string]: Font-size for chart title. Default: '1rem'. - tooltipFontSize [string]: Font-size for tooltip. Default: '0.95rem'. - xLabel [string]: Label for x-axis. - yLabel [string]: Label for y-axis.

roughViz.Donut

Required - element [string]: Id or class of container element. - data: Data with which to construct chart. Can be either an object or string.

  • If object: must contain labels and values keys:

    js new roughViz.Donut({ element: '.viz', data: {labels: ['a', 'b'], values: [10, 20]} })

  • If string: must be a path/url to a csv, json, or tsv, and you must also specify the labels and values as separate attributes that represent columns in said file: js new roughViz.Donut({ element: '#viz0', data: 'stringToDataUrl.csv', labels: 'nameOfLabelsColumn', values: 'nameOfValuesColumn', })

Optional - bowing [number]: Chart bowing. Default: 0. - colors [array]: Array of colors for each arc. Default: ['coral', 'skyblue', '#66c2a5', 'tan', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', 'tan', 'orange']. - fillStyle [string]: Bar fill-style. Should be one of fillStyles shown above. - fillWeight [number]: Weight of inner paths' color. Default: 0.85. - font: Font-family to use. You can use 0 or gaegu to use Gaegu, or 1 or indie flower to use Indie Flower. Or feed it something else. Default: Gaegu. - highlight [string]: Color for each arc on hover. Default: 'coral'. - innerStrokeWidth [number]: Stroke-width for paths inside arcs. Default: 0.75. - interactive [boolean]: Whether or not chart is interactive. Default: true. - legend [boolean]: Whether or not to add legend. Default: 'true'. - legendPosition [string]: Position of legend. Should be either 'left' or 'right'. Default: 'right'. - margin [object]: Margin object. Default: {top: 50, right: 20, bottom: 70, left: 100} - padding [number]: Padding between bars. Default: 0.1. - roughness [number]: Roughness level of chart. Default: 1. - simplification [number]: Chart simplification. Default 0.2. - strokeWidth [number]: Size of bars' stroke. Default: 1. - title [string]: Chart title. Optional. - titleFontSize [string]: Font-size for chart title. Default: '1rem'. - tooltipFontSize [string]: Font-size for tooltip. Default: '0.95rem'.

roughViz.Line

Required - element [string]: Id or class of container element. - data: Must be a path/url to a csv or tsv, and you must also specify the each y as separate attributes that represent columns in said file. Each attribute prefaced with y (except yLabel) will receive its own line: js new roughViz.Line({ element: '#viz0', data: 'https://raw.githubusercontent.com/jwilber/random_data/master/profits.csv', y1: 'revenue', y2: 'cost', y3: 'profit' })

Optional - axisFontSize [string]: Font-size for axes' labels. Default: '1rem'. - axisRoughness [number]: Roughness for x & y axes. Default: 0.5. - axisStrokeWidth [number]: Stroke-width for x & y axes. Default: 0.5. - bowing [number]: Chart bowing. Default: 0. - circle [boolean]: Whether or not to add circles to chart. Default: true. - circleRadius [number]: Radius of circles. Default: 10. - circleRoughness [number]: Roughness of circles. Default: 2. - colors [array or string]: Array of colors for each arc. Default: ['coral', 'skyblue', '#66c2a5', 'tan', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', 'tan', 'orange']. If string (e.g. 'blue'), all circles will take that color. - fillStyle [string]: Bar fill-style. Should be one of fillStyles shown above. - fillWeight [number]: Weight of inner paths' color. Default: 0.5. - font: Font-family to use. You can use 0 or gaegu to use Gaegu, or 1 or indie flower to use Indie Flower. Or feed it something else. Default: Gaegu. - interactive [boolean]: Whether or not chart is interactive. Default: true. - labelFontSize [string]: Font-size for axes' labels. Default: '1rem'. - legend [boolean]: Whether or not to add legend. Default: true. - legendPosition [string]: Position of legend. Should be either 'left' or 'right'. Default: 'right'. - margin [object]: Margin object. Default: {top: 50, right: 20, bottom: 70, left: 100} - roughness [number]: Roughness level of chart. Default: 1. - simplification [number]: Chart simplification. Default 0.2. - stroke [string]: Color of lines' stroke. Default: this.colors. - strokeWidth [number]: Size of lines' stroke. Default: 1. - title [string]: Chart title. Optional. - titleFontSize [string]: Font-size for chart title. Default: '0.95rem'. - tooltipFontSize [string]: Font-size for tooltip. Default: '0.95rem'. - xLabel [string]: Label for x-axis. - yLabel [string]: Label for y-axis.

roughViz.Pie

Required - element [string]: Id or class of container element. - data: Data with which to construct chart. Can be either an object or string.

  • If object: must contain labels and values keys:

    js new roughViz.Pie({ element: '.viz', data: {labels: ['a', 'b'], values: [10, 20]} })

  • If string: must be a path/url to a csv, json, or tsv, and you must also specify the labels and values as separate attributes that represent columns in said file: js new roughViz.Pie({ element: '#viz0', data: 'stringToDataUrl.csv', labels: 'nameOfLabelsColumn', values: 'nameOfValuesColumn', })

Optional - bowing [number]: Chart bowing. Default: 0. - colors [array]: Array of colors for each arc. Default: ['coral', 'skyblue', '#66c2a5', 'tan', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', 'tan', 'orange']. - fillStyle [string]: Bar fill-style. Should be one of fillStyles shown a

Core symbols most depended-on inside this repo

resolveFont
called by 18
src/Chart.js
roughCeiling
called by 17
src/utils/roughCeiling.js
setSvg
called by 9
src/Chart.js
redraw
called by 9
src/Pie.js
addLegend
called by 8
src/utils/addLegend.js
createNodes
called by 5
website/roughDemo.js
remove
called by 3
src/Pie.js
drawFromFile
called by 3
src/Pie.js

Shape

Method 151
Class 20
Function 14

Languages

TypeScript100%

Modules by API surface

src/StackedBar.js23 symbols
src/Scatter.js21 symbols
src/BarH.js20 symbols
src/Bar.js20 symbols
src/Line.js19 symbols
src/Pie.js16 symbols
src/Network.js16 symbols
src/Force.js16 symbols
src/Donut.js16 symbols
website/roughDemo.js9 symbols
src/Chart.js5 symbols
src/utils/addFonts.js2 symbols

Dependencies from manifests, versioned

@sveltejs/vite-plugin-svelte3.0.0 · 1×
d3-array2.3.1 · 1×
d3-axis1.0.12 · 1×
d3-fetch1.1.2 · 1×
d3-force3.0.0 · 1×
d3-format1.4.1 · 1×
d3-scale3.2.0 · 1×
d3-scale-chromatic1.5.0 · 1×
d3-selection1.4.0 · 1×
d3-shape1.3.5 · 1×
eslint6.3.0 · 1×
eslint-config-strongloop2.1.0 · 1×

For agents

$ claude mcp add roughViz \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact