GithubHelp home page GithubHelp logo

alibaba-bizcharts / automatic-scatter-labelling Goto Github PK

View Code? Open in Web Editor NEW

This project forked from furstenheim/automatic-scatter-labelling

0.0 1.0 1.0 1.53 MB

Implementation of an algorithm for automatic labelling of scatter plots

JavaScript 99.14% HTML 0.86%

automatic-scatter-labelling's Introduction

Automatic scatter labelling

Compute the positions of labels in a scatter plot. It implements the NOLOOKAHEAD algorithm described in:

Theophil S., Schödl A. An Efficient Algorithm for Scatter Chart Labeling AAAI

example

Install

$ npm install --save automatic-scatter-labelling

It requires of a webworker so right now it only works for the browser.

Example

Running npm run gulp will launch a full working example in the browser

Basic usage

With browserify or webpack

const algorithm = require('automatic-scatter-labelling')
const pointsToLabel = [
  {id: 1,
  position: {
    x: 10,
    y: -20
    },
  label: {
    height: 30,
    width: 20
    }
  },
  {
    id: 2,
    position: {
      x: 10,
      y: -20
    },
  label: {
    height: 30,
    width: 20
  }
]

mainAlgorithm(pointsToLabel)
  .then(function (rectangles) {
    const rectangle = rectangles[0]
    const id = rectangle.id // Corresponding to the id provided in the algorithm
    // Coordinates to place the rectangle 
    const {left, right, top, bottom} = rectangle.rectangle
  })

Advanced usage

Additionally to the points we want to label we can provide extra arguments to tweak the algorithm. radius is used to indicate that some space should be left around the points. bbox to indicate where the labels should be restricted (so that they don't go offscreen).

Example:

  const result = await algorithm(pointsToLabel, {
    radius: 5,
    bbox: {
      top: margin.top,
      bottom: -margin.top + height,
      left: margin.left,
      right: margin.left + width,
      width,
      height: height
    }
  })

automatic-scatter-labelling's People

Contributors

furstenheim avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.