1601350620
billboard.js is a re-usable, easy interface JavaScript chart library, based on D3 v4+.
The name “billboard” comes from the famous billboard chart
which everybody knows.
Play with the diverse options generating on the fly!
If you have any questions, checkout the previous posts or create a new one at:
Download dist files from the repo directly or install it via npm.
You can download the uncompressed files for development
You can download the compressed files for production
Packaged version is not an official distribution. It’s to provide an easy way to load ‘billboard.js’ with dependency.
If you want apply themes, simply load one of the theme css file provided instead of the default css file.
Nightly version is the latest build from the master branch. With nightly, you can try upcoming changes prior the official release.
The version info will be given as the build datetime:
x.x.x-nightly-yyyymmddhhmmss
There’re two ways to install from nightly
branch directly.
// Specify on 'package.json' file
"dependencies": {
...
"billboard.js": "git://github.com/naver/billboard.js.git#nightly"
},
# Run install command from shell
$ npm install git+https://github.com/naver/billboard.js.git#nightly --save
Next version is the ‘release candidate’ build, prior the latest official release.
# Run install command from shell
$ npm install billboard.js@next --save
$ npm install billboard.js
If you want to use ‘billboard.js’ without installation, load files directly from one of the CDN providers.
Basically will work on all SVG supported browsers.
Internet Explorer | Chrome | Firefox | Safari | iOS | Android |
---|---|---|---|---|---|
9+ | Latest | Latest | Latest | 8+ | 4+ |
D3 (required) |
---|
4+ |
Load billboard.js after D3.js.
<!-- 1) Load D3.js and billboard.js separately -->
<!-- Load D3 -->
<script src="https://d3js.org/d3.v5.min.js"></script>
<!-- Load billboard.js with base(or theme) style -->
<link rel="stylesheet" href="$YOUR_PATH/billboard.css">
<script src="$YOUR_PATH/billboard.js"></script>
<!-- 2) or Load billboard.js packaged with D3.js -->
<link rel="stylesheet" href="$YOUR_PATH/billboard.css">
<script src="$YOUR_PATH/billboard.pkgd.js"></script>
or use importing ESM.
// 1) import billboard.js
// as named import with desired shapes and interaction modules
// https://github.com/naver/billboard.js/wiki/CHANGELOG-v2#modularization-by-its-functionality
import {bb, area, bar, zoom} from "billboard.js";
// or as importing default
import bb, {area, bar, zoom} from "billboard.js";
// 2) import css if your dev-env supports. If don't, include them via <link>
import "billboard.js/dist/billboard.css";
// or theme style. Find more themes from 'theme' folder
import "billboard.js/dist/theme/insight.css"
Note
- For migration from C3.js, checkout the migration guide.
- If has an issue bundling for legacy browsers, checkout “How to bundle for legacy browsers?”.
<div id="chart"></div>
// generate the chart
var chart = bb.generate({
bindto: "#chart",
data: {
// for ESM import usage, import 'line' module and execute it as
// type: line(),
type: "line",
columns: [
["data1", 30, 200, 100, 400, 150, 250]
]
},
zoom: {
// for ESM import usage, import 'zoom' module and execute it as
// enabled: zoom()
enabled: true
}
});
// call some API
chart.load( ... );
For anyone interested in developing billboard.js, follow the instructions below.
Required Node.js version:
10.10.0+
Clone the billboard.js repository and install the dependency modules.
# Create a folder and move.
$ mkdir billboard.js && cd billboard.js
# Clone the repository.
$ git clone https://github.com/naver/billboard.js.git
npm
and Yarn
are supported.
# Install the dependency modules.
$ npm install
# or
$ yarn
Use npm script to build billboard.js
# Run webpack-dev-server for development
$ npm start
# Build
$ npm run build
# Generate jsdoc
$ npm run jsdoc
Two folders will be created after the build is completed.
To maintain the same code style and quality, we adopted ESLint. The rules are based on the Airbnb JavaScript Style Guide with some modifications. Setup your editor for check or run the below command for linting.
$ npm run lint
Once you created a branch and finished the development, you must perform a test with npm test
command before the push to a remote repository.
$ npm test
Running the npm test
command will start Mocha tests via Karma-runner.
If you find a bug, please report to us by posting issues on GitHub.
Author: naver
Demo: https://naver.github.io/billboard.js/
Source Code: https://github.com/naver/billboard.js
#javascript
1632537859
Not babashka. Node.js babashka!?
Ad-hoc CLJS scripting on Node.js.
Experimental. Please report issues here.
Nbb's main goal is to make it easy to get started with ad hoc CLJS scripting on Node.js.
Additional goals and features are:
Nbb requires Node.js v12 or newer.
CLJS code is evaluated through SCI, the same interpreter that powers babashka. Because SCI works with advanced compilation, the bundle size, especially when combined with other dependencies, is smaller than what you get with self-hosted CLJS. That makes startup faster. The trade-off is that execution is less performant and that only a subset of CLJS is available (e.g. no deftype, yet).
Install nbb
from NPM:
$ npm install nbb -g
Omit -g
for a local install.
Try out an expression:
$ nbb -e '(+ 1 2 3)'
6
And then install some other NPM libraries to use in the script. E.g.:
$ npm install csv-parse shelljs zx
Create a script which uses the NPM libraries:
(ns script
(:require ["csv-parse/lib/sync$default" :as csv-parse]
["fs" :as fs]
["path" :as path]
["shelljs$default" :as sh]
["term-size$default" :as term-size]
["zx$default" :as zx]
["zx$fs" :as zxfs]
[nbb.core :refer [*file*]]))
(prn (path/resolve "."))
(prn (term-size))
(println (count (str (fs/readFileSync *file*))))
(prn (sh/ls "."))
(prn (csv-parse "foo,bar"))
(prn (zxfs/existsSync *file*))
(zx/$ #js ["ls"])
Call the script:
$ nbb script.cljs
"/private/tmp/test-script"
#js {:columns 216, :rows 47}
510
#js ["node_modules" "package-lock.json" "package.json" "script.cljs"]
#js [#js ["foo" "bar"]]
true
$ ls
node_modules
package-lock.json
package.json
script.cljs
Nbb has first class support for macros: you can define them right inside your .cljs
file, like you are used to from JVM Clojure. Consider the plet
macro to make working with promises more palatable:
(defmacro plet
[bindings & body]
(let [binding-pairs (reverse (partition 2 bindings))
body (cons 'do body)]
(reduce (fn [body [sym expr]]
(let [expr (list '.resolve 'js/Promise expr)]
(list '.then expr (list 'clojure.core/fn (vector sym)
body))))
body
binding-pairs)))
Using this macro we can look async code more like sync code. Consider this puppeteer example:
(-> (.launch puppeteer)
(.then (fn [browser]
(-> (.newPage browser)
(.then (fn [page]
(-> (.goto page "https://clojure.org")
(.then #(.screenshot page #js{:path "screenshot.png"}))
(.catch #(js/console.log %))
(.then #(.close browser)))))))))
Using plet
this becomes:
(plet [browser (.launch puppeteer)
page (.newPage browser)
_ (.goto page "https://clojure.org")
_ (-> (.screenshot page #js{:path "screenshot.png"})
(.catch #(js/console.log %)))]
(.close browser))
See the puppeteer example for the full code.
Since v0.0.36, nbb includes promesa which is a library to deal with promises. The above plet
macro is similar to promesa.core/let
.
$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)' 0.17s user 0.02s system 109% cpu 0.168 total
The baseline startup time for a script is about 170ms seconds on my laptop. When invoked via npx
this adds another 300ms or so, so for faster startup, either use a globally installed nbb
or use $(npm bin)/nbb script.cljs
to bypass npx
.
Nbb does not depend on any NPM dependencies. All NPM libraries loaded by a script are resolved relative to that script. When using the Reagent module, React is resolved in the same way as any other NPM library.
To load .cljs
files from local paths or dependencies, you can use the --classpath
argument. The current dir is added to the classpath automatically. So if there is a file foo/bar.cljs
relative to your current dir, then you can load it via (:require [foo.bar :as fb])
. Note that nbb
uses the same naming conventions for namespaces and directories as other Clojure tools: foo-bar
in the namespace name becomes foo_bar
in the directory name.
To load dependencies from the Clojure ecosystem, you can use the Clojure CLI or babashka to download them and produce a classpath:
$ classpath="$(clojure -A:nbb -Spath -Sdeps '{:aliases {:nbb {:replace-deps {com.github.seancorfield/honeysql {:git/tag "v2.0.0-rc5" :git/sha "01c3a55"}}}}}')"
and then feed it to the --classpath
argument:
$ nbb --classpath "$classpath" -e "(require '[honey.sql :as sql]) (sql/format {:select :foo :from :bar :where [:= :baz 2]})"
["SELECT foo FROM bar WHERE baz = ?" 2]
Currently nbb
only reads from directories, not jar files, so you are encouraged to use git libs. Support for .jar
files will be added later.
The name of the file that is currently being executed is available via nbb.core/*file*
or on the metadata of vars:
(ns foo
(:require [nbb.core :refer [*file*]]))
(prn *file*) ;; "/private/tmp/foo.cljs"
(defn f [])
(prn (:file (meta #'f))) ;; "/private/tmp/foo.cljs"
Nbb includes reagent.core
which will be lazily loaded when required. You can use this together with ink to create a TUI application:
$ npm install ink
ink-demo.cljs
:
(ns ink-demo
(:require ["ink" :refer [render Text]]
[reagent.core :as r]))
(defonce state (r/atom 0))
(doseq [n (range 1 11)]
(js/setTimeout #(swap! state inc) (* n 500)))
(defn hello []
[:> Text {:color "green"} "Hello, world! " @state])
(render (r/as-element [hello]))
Working with callbacks and promises can become tedious. Since nbb v0.0.36 the promesa.core
namespace is included with the let
and do!
macros. An example:
(ns prom
(:require [promesa.core :as p]))
(defn sleep [ms]
(js/Promise.
(fn [resolve _]
(js/setTimeout resolve ms))))
(defn do-stuff
[]
(p/do!
(println "Doing stuff which takes a while")
(sleep 1000)
1))
(p/let [a (do-stuff)
b (inc a)
c (do-stuff)
d (+ b c)]
(prn d))
$ nbb prom.cljs
Doing stuff which takes a while
Doing stuff which takes a while
3
Also see API docs.
Since nbb v0.0.75 applied-science/js-interop is available:
(ns example
(:require [applied-science.js-interop :as j]))
(def o (j/lit {:a 1 :b 2 :c {:d 1}}))
(prn (j/select-keys o [:a :b])) ;; #js {:a 1, :b 2}
(prn (j/get-in o [:c :d])) ;; 1
Most of this library is supported in nbb, except the following:
:syms
.-x
notation. In nbb, you must use keywords.See the example of what is currently supported.
See the examples directory for small examples.
Also check out these projects built with nbb:
See API documentation.
See this gist on how to convert an nbb script or project to shadow-cljs.
Prequisites:
To build:
bb release
Run bb tasks
for more project-related tasks.
Download Details:
Author: borkdude
Download Link: Download The Source Code
Official Website: https://github.com/borkdude/nbb
License: EPL-1.0
#node #javascript
1601350620
billboard.js is a re-usable, easy interface JavaScript chart library, based on D3 v4+.
The name “billboard” comes from the famous billboard chart
which everybody knows.
Play with the diverse options generating on the fly!
If you have any questions, checkout the previous posts or create a new one at:
Download dist files from the repo directly or install it via npm.
You can download the uncompressed files for development
You can download the compressed files for production
Packaged version is not an official distribution. It’s to provide an easy way to load ‘billboard.js’ with dependency.
If you want apply themes, simply load one of the theme css file provided instead of the default css file.
Nightly version is the latest build from the master branch. With nightly, you can try upcoming changes prior the official release.
The version info will be given as the build datetime:
x.x.x-nightly-yyyymmddhhmmss
There’re two ways to install from nightly
branch directly.
// Specify on 'package.json' file
"dependencies": {
...
"billboard.js": "git://github.com/naver/billboard.js.git#nightly"
},
# Run install command from shell
$ npm install git+https://github.com/naver/billboard.js.git#nightly --save
Next version is the ‘release candidate’ build, prior the latest official release.
# Run install command from shell
$ npm install billboard.js@next --save
$ npm install billboard.js
If you want to use ‘billboard.js’ without installation, load files directly from one of the CDN providers.
Basically will work on all SVG supported browsers.
Internet Explorer | Chrome | Firefox | Safari | iOS | Android |
---|---|---|---|---|---|
9+ | Latest | Latest | Latest | 8+ | 4+ |
D3 (required) |
---|
4+ |
Load billboard.js after D3.js.
<!-- 1) Load D3.js and billboard.js separately -->
<!-- Load D3 -->
<script src="https://d3js.org/d3.v5.min.js"></script>
<!-- Load billboard.js with base(or theme) style -->
<link rel="stylesheet" href="$YOUR_PATH/billboard.css">
<script src="$YOUR_PATH/billboard.js"></script>
<!-- 2) or Load billboard.js packaged with D3.js -->
<link rel="stylesheet" href="$YOUR_PATH/billboard.css">
<script src="$YOUR_PATH/billboard.pkgd.js"></script>
or use importing ESM.
// 1) import billboard.js
// as named import with desired shapes and interaction modules
// https://github.com/naver/billboard.js/wiki/CHANGELOG-v2#modularization-by-its-functionality
import {bb, area, bar, zoom} from "billboard.js";
// or as importing default
import bb, {area, bar, zoom} from "billboard.js";
// 2) import css if your dev-env supports. If don't, include them via <link>
import "billboard.js/dist/billboard.css";
// or theme style. Find more themes from 'theme' folder
import "billboard.js/dist/theme/insight.css"
Note
- For migration from C3.js, checkout the migration guide.
- If has an issue bundling for legacy browsers, checkout “How to bundle for legacy browsers?”.
<div id="chart"></div>
// generate the chart
var chart = bb.generate({
bindto: "#chart",
data: {
// for ESM import usage, import 'line' module and execute it as
// type: line(),
type: "line",
columns: [
["data1", 30, 200, 100, 400, 150, 250]
]
},
zoom: {
// for ESM import usage, import 'zoom' module and execute it as
// enabled: zoom()
enabled: true
}
});
// call some API
chart.load( ... );
For anyone interested in developing billboard.js, follow the instructions below.
Required Node.js version:
10.10.0+
Clone the billboard.js repository and install the dependency modules.
# Create a folder and move.
$ mkdir billboard.js && cd billboard.js
# Clone the repository.
$ git clone https://github.com/naver/billboard.js.git
npm
and Yarn
are supported.
# Install the dependency modules.
$ npm install
# or
$ yarn
Use npm script to build billboard.js
# Run webpack-dev-server for development
$ npm start
# Build
$ npm run build
# Generate jsdoc
$ npm run jsdoc
Two folders will be created after the build is completed.
To maintain the same code style and quality, we adopted ESLint. The rules are based on the Airbnb JavaScript Style Guide with some modifications. Setup your editor for check or run the below command for linting.
$ npm run lint
Once you created a branch and finished the development, you must perform a test with npm test
command before the push to a remote repository.
$ npm test
Running the npm test
command will start Mocha tests via Karma-runner.
If you find a bug, please report to us by posting issues on GitHub.
Author: naver
Demo: https://naver.github.io/billboard.js/
Source Code: https://github.com/naver/billboard.js
#javascript
1656185340
d3-funnel
d3-funnel is an extensible, open-source JavaScript library for rendering funnel charts using the D3.js library.
d3-funnel is focused on providing practical and visually appealing funnels through a variety of customization options. Check out the examples page to get a showcasing of the several possible options.
Installation
To install this library, simply include both D3.js and D3Funnel:
<script src="/path/to/d3.js"></script>
<script src="/path/to/dist/d3-funnel.js"></script>
Alternatively, if you are using Webpack or Browserify, you can install the npm package and import
the module. This will include a compatible version of D3.js for you:
npm install d3-funnel --save
import D3Funnel from 'd3-funnel';
Usage
To use this library, you must create a container element and instantiate a new funnel chart. By default, the chart will assume the width and height of the parent container:
<div id="funnel"></div>
<script>
const data = [
{ label: 'Inquiries', value: 5000 },
{ label: 'Applicants', value: 2500 },
{ label: 'Admits', value: 500 },
{ label: 'Deposits', value: 200 },
];
const options = {
block: {
dynamicHeight: true,
minHeight: 15,
},
};
const chart = new D3Funnel('#funnel');
chart.draw(data, options);
</script>
Option | Description | Type | Default |
---|---|---|---|
chart.width | The width of the chart in pixels or a percentage. | mixed | Container's width |
chart.height | The height of the chart in pixels or a percentage. | mixed | Container's height |
chart.bottomWidth | The percent of total width the bottom should be. | number | 1 / 3 |
chart.bottomPinch | How many blocks to pinch on the bottom to create a funnel "neck". | number | 0 |
chart.inverted | Whether the funnel direction is inverted (like a pyramid). | bool | false |
chart.animate | The load animation speed in milliseconds. | number | 0 (disabled) |
chart.curve.enabled | Whether the funnel is curved. | bool | false |
chart.curve.height | The curvature amount. | number | 20 |
chart.totalCount | Override the total count used in ratio calculations. | number | null |
block.dynamicHeight | Whether the block heights are proportional to their weight. | bool | false |
block.dynamicSlope | Whether the block widths are proportional to their value decrease. | bool | false |
block.barOverlay | Whether the blocks have bar chart overlays proportional to its weight. | bool | false |
block.fill.scale | The background color scale as an array or function. | mixed | d3.schemeCategory10 |
block.fill.type | Either 'solid' or 'gradient' . | string | 'solid' |
block.minHeight | The minimum pixel height of a block. | number | 0 |
block.highlight | Whether the blocks are highlighted on hover. | bool | false |
label.enabled | Whether the block labels should be displayed. | bool | true |
label.fontFamily | Any valid font family for the labels. | string | null |
label.fontSize | Any valid font size for the labels. | string | '14px' |
label.fill | Any valid hex color for the label color. | string | '#fff' |
label.format | Either function(label, value) or a format string. See below. | mixed | '{l}: {f}' |
tooltip.enabled | Whether tooltips should be enabled on hover. | bool | false |
tooltip.format | Either function(label, value) or a format string. See below. | mixed | '{l}: {f}' |
events.click.block | Callback function(data) for when a block is clicked. | function | null |
The option label.format
can either be a function or a string. The following keys will be substituted by the string formatter:
Key | Description |
---|---|
'{l}' | The block's supplied label. |
'{v}' | The block's raw value. |
'{f}' | The block's formatted value. |
Block-based events are passed a data
object containing the following elements:
Key | Type | Description |
---|---|---|
index | number | The index of the block. |
node | object | The DOM node of the block. |
value | number | The numerical value. |
fill | string | The background color. |
label.raw | string | The unformatted label. |
label.formatted | string | The result of options.label.format . |
label.color | string | The label color. |
Example:
{
index: 0,
node: { ... },
value: 150,
fill: '#c33',
label: {
raw: 'Visitors',
formatted: 'Visitors: 150',
color: '#fff',
},
},
You may wish to override the default chart options. For example, you may wish for every funnel to have proportional heights. To do this, simply modify the D3Funnel.defaults
property:
D3Funnel.defaults.block.dynamicHeight = true;
Should you wish to override multiple properties at a time, you may consider using lodash's _.merge
or jQuery's $.extend
:
D3Funnel.defaults = _.merge(D3Funnel.defaults, {
block: {
dynamicHeight: true,
fill: {
type: 'gradient',
},
},
label: {
format: '{l}: ${f}',
},
});
In the examples above, both label
and value
were just to describe a block within the funnel. A complete listing of the available options is included below:
Option | Type | Description | Example |
---|---|---|---|
label | mixed | Required. The label to associate with the block. | 'Students' |
value | number | Required. The value (or count) to associate with the block. | 500 |
backgroundColor | string | A row-level override for block.fill.scale . Hex only. | '#008080' |
formattedValue | mixed | A row-level override for label.format . | 'USD: $150' |
hideLabel | bool | Whether to hide the formatted label for this block. | true |
labelColor | string | A row-level override for label.fill . Hex only. | '#333' |
Additional methods beyond draw()
are accessible after instantiating the chart:
Method | Description |
---|---|
destroy() | Removes the funnel and its events from the DOM. |
Author: jakezatecky
Source Code: https://github.com/jakezatecky/d3-funnel
License: MIT license
1598065860
In this article, we’ll review five JavaScript libraries that allow you to create online organizational charts. To make this info useful for different categories of readers, we’ve gathered together libraries with different functionality and pricing policy. To help you decide whether one of them is worthy of your attention or not, we’ll take a look at the main features and check if the documentation is user-friendly.
The DHTMLX diagram library allows creating easily configurable graphs for visualization of hierarchical data. Besides org charts, you can create almost any type of hierarchical diagrams. You can choose from organizational charts, flowcharts, block and network diagrams, decision trees, mind maps, UML Class diagrams, mixed diagrams, and any other types of diagrams. This variety of diagrams can be generated using a built-in set of shapes or with the help of custom shapes.
You can set up any diagram shape you need with text, icons, images, and any other custom content via templates in a few lines of code. All these parameters can be later changed from the UI via the sidebar options in the editor.
The edit mode gives an opportunity to make changes on-the-fly without messing with the source code. An interactive interface of the editor supports drag-and-drop and permits you to change each item of your diagram. You can drag diagram items with your mouse and set the size and position property of an item via the editor. The multiselection feature can help to speed up your work in the editor, as it enables you to manipulate several shapes.
The library has an exporting feature. You can export your diagram to a PDF, PNG, or JSON format. Zooming and scrolling options will be useful in case you work with diagrams containing a big number of items. There is also a search feature that helps you to quickly find the necessary shape and make your work with complex diagrams even more convenient by expanding and collapsing shapes when necessary. To show the structure of an organization compactly, you can use the vertical mode.
The documentation page will appeal both to beginners and experienced developers. A well-written beginner’s guide contains the source code with explanations. A bunch of guides will help with further configuration, so you’ll be able to create a diagram that better suits your needs. At the moment, there are three types of licenses available. The commercial license for the team of five or fewer developers costs $599, the enterprise license goes for $1299 per company, and the ultimate license has a price tag of $2899.
#javascript #web dev #data visualization #libraries #web app development #front end development #javascript libraries #org chart creator
1656213120
A basic implementation of a Gantt Chart using D3.js. Here is an example [Example 1] (http://bl.ocks.org/dk8996/5534835) and another one [Example 2] (http://bl.ocks.org/dk8996/5449641).
Here is an [example] (http://static.mentful.com/d3ganttchart/example.html) of loading external data, in JSON format, into the Gantt Chart, you need to watch out for [cross-domain restrictions] (http://en.wikipedia.org/wiki/Same-origin_policy).
Create an array of all your data.
var tasks = [
{
"startDate": new Date("Sun Dec 09 01:36:45 EST 2012"),
"endDate": new Date("Sun Dec 09 02:36:45 EST 2012"),
"taskName": "E Job",
"status": "FAILED"
},
{
"startDate": new Date("Sun Dec 09 04:56:32 EST 2012"),
"endDate": new Date("Sun Dec 09 06:35:47 EST 2012"),
"taskName": "A Job",
"status": "RUNNING"
}];
Create a map between task status and css class, this is optional.
var taskStatus = {
"SUCCEEDED": "bar",
"FAILED": "bar-failed",
"RUNNING": "bar-running",
"KILLED": "bar-killed"
};
.bar {
fill: #33b5e5;
}
.bar-failed {
fill: #CC0000;
}
.bar-running {
fill: #669900;
}
.bar-succeeded {
fill: #33b5e5;
}
.bar-killed {
fill: #ffbb33;
}
Create an array of task names, they will be display on they y-axis in the order given to the array.
var taskNames = [ "D Job", "P Job", "E Job", "A Job", "N Job" ];
Create a simple Gantt-Chart
var gantt = d3.gantt().taskTypes(taskNames).taskStatus(taskStatus);
gantt(tasks);
Relies on the fantastic D3 visualization library to do lots of the heavy lifting for stacking and rendering to SVG.
Author: dk8996
Source Code: https://github.com/dk8996/Gantt-Chart
License: Apache-2.0 license