excentric-labeling-interaction
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Excentric Labeling

Introduction

Excentric labeling interaction is based on the excentric labeling layout algrithm. It allows you to augment your scatter plot, bar chart, tree map or any other visualizatoins with labeling technique in a few lines of code!

Live Demo

Usage

import excentricLabeling from "excent";

import eli from "excentric-labeling-interaction";

const {addExcentricLabelingInteraction, computeSizeOfLabels} = eli;

const {mainLayer, coordinatesWithInfo} = renderScatterPlot(g, width, height, data, fieldX, fieldY, fieldColor, interactionParams, setStateFuncs);

  // interaction
const rawInfos = getRawInfos(coordinatesWithInfo, svg, interactionParams.fontSize);
addExcentricLabelingInteraction(mainLayer, width, height, rawInfos, interactionParams, {
    onMove: (rawInfos, nearest) => {
        const rp = randomPoint(rawInfos);
        setStateFuncs.setCurLabel(nearest?.label || "");
        setStateFuncs.setRandomLabel(rp?.label || "");
    }
});

function getRawInfos(points, root, fontSize) {
  const rawInfos = points.map((point) => {
    return {
      ...point,
      labelWidth: 0,
      labelHeight: 0,
    };
  });
  computeSizeOfLabels(rawInfos, root, fontSize);
  return rawInfos;
}

Package Sidebar

Install

npm i excentric-labeling-interaction

Weekly Downloads

0

Version

0.0.2

License

ISC

Unpacked Size

62.9 kB

Total Files

9

Last publish

Collaborators

  • viruspc