MCPcopy
hub / github.com/twitter/labella.js

github.com/twitter/labella.js @v1.1.4 sqlite

repository ↗ · DeepWiki ↗ · release v1.1.4 ↗
87 symbols 224 edges 31 files 6 documented · 7%
README

Docs ▸ Introduction | Development | Demo   ////   API Reference ▸ Force | Node | Renderer

Labella.js NPM version Build Status

"Labels should be beautiful."

If you try to place labels for points on a timeline (or any 1D space), one common problem is the labels often overlap. How about making the labels push each other and find where they can stay with overlapping?

Moreover, if you are looking for a ready-to-use timeline component with Labella's smart labeling instead of building your own timeline from scratch, check out d3Kit-timeline.

Note: For users who are upgrading from v0.x.x to v1.x.x. The API has changed. force.start() and force.on() are deprecated. Both are replaced by force.compute() which has to be called slightly differently. Please read the change logs.

Install

npm install labella --save

or

bower install labella --save

Example

// idealPos: The most preferred position for each label
// width:    The width of each label
var nodes = [
  new labella.Node(1, 50), // idealPos, width
  new labella.Node(2, 50),
  new labella.Node(3, 50),
  new labella.Node(3, 50),
  new labella.Node(3, 50),
];

var force = new labella.Force()
  .nodes(nodes)
  .compute();

// The rendering is independent from this library.
// User can use canvas, svg or any library to draw the labels.
// There is also a built-in helper for this purpose. See labella.Renderer
draw(force.nodes());

Import into your project

Choice 1. Global

Adding this library via <script> tag is the simplest way. By doing this, labella is available in the global scope.

<script src="https://github.com/twitter/labella.js/raw/v1.1.4/labella.min.js"></script>
Choice 2: AMD

If you use requirejs, Labella.js support AMD out of the box.

require(['path/to/labella'], function(labella) {
  // do something
});
Choice 3: node.js / browserify

Labella.js also supports usage in commonjs style.

var labella = require('path/to/labella');

Files

The dist directory contains four variations of this library:

  • labella.js and labella.min.js : Core functionalities. This is what you will need for regular use.
  • labella-extra.js and labella-extra.min.js (since v1.1.0) : Same content with the above bundle plus labella.util and labella.metrics, which are special modules for demo/evaluation.

Author

Krist Wongsuphasawat / @kristw

Copyright 2015 Twitter, Inc. Licensed under the Apache License Version 2.0

Core symbols most depended-on inside this repo

createStub
called by 20
src/core/node.js
isStub
called by 19
src/core/node.js
displacement
called by 15
src/core/node.js
overlapWithNode
called by 12
src/core/node.js
currentRight
called by 10
src/core/node.js
getLayerIndex
called by 10
src/core/node.js
distanceFrom
called by 9
src/core/node.js
currentLeft
called by 9
src/core/node.js

Shape

Function 64
Method 21
Class 2

Languages

TypeScript100%

Modules by API surface

src/core/node.js23 symbols
evaluation/labella-extra.min.js9 symbols
evaluation/labella-0.1.1.min.js9 symbols
src/lib/vpsc.js7 symbols
src/lib/intervalTree.js6 symbols
src/core/renderer.js6 symbols
src/core/helper.js4 symbols
evaluation/v0_vs_v1.js4 symbols
src/core/metrics.js3 symbols
examples/js/horizontalTimeline.js3 symbols
evaluation/metrics.js3 symbols
src/lib/extend.js2 symbols

Dependencies from manifests, versioned

babel-cli6.4.5 · 1×
babel-core6.3.21 · 1×
babel-loader6.2.0 · 1×
babel-preset-es20156.3.13 · 1×
bower1.6.5 · 1×
browser-sync2.10.1 · 1×
del2.2.0 · 1×
exports-loader0.6.2 · 1×
gulp3.9.0 · 1×
gulp-gh-pages0.5.4 · 1×
gulp-load-plugins1.1.0 · 1×
gulp-rename1.2.2 · 1×

For agents

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

⬇ download graph artifact