JS時間軸庫:Labella.js
Labella.js 是 推ter 開源的時間軸標簽放置工具,可以把標簽沒有重疊的放在時間軸上。
Labella.js
"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. Use the force, jedi-style.
See interactive demo or simple example.
Install
npm install labella --save
or
bower install labella --save
Import to your project
Choice 1. Global
Adding this library via<script>tag is the simplest way. By doing this,labellais available in the global scope.
<script src="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');
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) // Listen when the nodes' positions are updated. .on('end', function(){ // 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 labella.Renderer for this purpose. See the examples draw(force.nodes()); }) // Run simulation at most 100 rounds. It may end earlier if equillibrium is reached. .start(100);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!