How to use d3-voronoi - 10 common examples

To help you get started, we’ve selected a few d3-voronoi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / d3-voronoi / d3-voronoi-tests.ts View on Github external
voronoiPolygon[1][1] = 10; // y-coordinate of second point
voronoiPolygon[2][0] = 30; // x-coordinate of third point
voronoiPolygon[2][1] = 30; // y-coordinate of third point
voronoiPolygon[3][0] = 5; // x-coordinate of fourth point
voronoiPolygon[3][1] = 40; // y-coordinate of fourth point

voronoiPolygon.data = { x: 15, y: 25 };

// ---------------------------------------------------------------------
// VoronoiLayout
// ---------------------------------------------------------------------

// Create layout =======================================================

let defaultVoronoiLayout: d3Voronoi.VoronoiLayout<[number, number]>;
defaultVoronoiLayout = d3Voronoi.voronoi();

let voronoiLayout: d3Voronoi.VoronoiLayout;
voronoiLayout = d3Voronoi.voronoi();

// Configure layout ====================================================

//  x(...) -------------------------------------------------------------

voronoiLayout = voronoiLayout.x(function (d) {
    return d.x; // data type of d is VoronoiTestDatum
});

numberAccessor = voronoiLayout.x();

//  y(...) -------------------------------------------------------------
github DefinitelyTyped / DefinitelyTyped / types / d3-voronoi / d3-voronoi-tests.ts View on Github external
voronoiPolygon[1][1] = 10; // y-coordinate of second point
voronoiPolygon[2][0] = 30; // x-coordinate of third point
voronoiPolygon[2][1] = 30; // y-coordinate of third point
voronoiPolygon[3][0] = 5; // x-coordinate of fourth point
voronoiPolygon[3][1] = 40; // y-coordinate of fourth point

voronoiPolygon.data = { x: 15, y: 25 };

// ---------------------------------------------------------------------
// VoronoiLayout
// ---------------------------------------------------------------------

// Create layout =======================================================

let defaultVoronoiLayout: d3Voronoi.VoronoiLayout<[number, number]>;
defaultVoronoiLayout = d3Voronoi.voronoi();

let voronoiLayout: d3Voronoi.VoronoiLayout;
voronoiLayout = d3Voronoi.voronoi();

// Configure layout ====================================================

//  x(...) -------------------------------------------------------------

voronoiLayout = voronoiLayout.x(d => d.x); // data type of d is VoronoiTestDatum

numberAccessor = voronoiLayout.x();

//  y(...) -------------------------------------------------------------

voronoiLayout = voronoiLayout.y(d => d.y); // data type of d is VoronoiTestDatum
github antvis / data-set / src / transform / diagram / voronoi.ts View on Github external
if (!isArray(as) || as.length !== 2) {
    throw new TypeError('Invalid as: must be an array with two strings!');
  }
  const xField = as[0];
  const yField = as[1];

  const fields = getFields(options);
  if (!isArray(fields) || fields.length !== 2) {
    throw new TypeError('Invalid fields: must be an array with two strings!');
  }
  const x = fields[0];
  const y = fields[1];

  const rows = dataView.rows;
  const data: [number, number][] = rows.map((row) => [row[x], row[y]]);
  const voronoi = d3Voronoi.voronoi();
  if (options.extend) {
    voronoi.extent(options.extend);
  }
  if (options.size) {
    voronoi.size(options.size);
  }
  const polygons = voronoi(data).polygons();
  rows.forEach((row, i) => {
    const polygon = polygons[i].filter((point) => !!point); // some points are null
    row[xField] = polygon.map((point) => point[0]);
    row[yField] = polygon.map((point) => point[1]);
  });
}
github mcnuttandrew / forum-explorer / src / layouts.js View on Github external
bottom: 20,
      right: 20
    },
    ...state.get('graphPanelDimensions').toJS()
  };

  const layout = computeGraphLayout(state);
  const xScale = usedLayout.getXScale(windowProps, layout);
  const yScale = usedLayout.getYScale(windowProps, layout);

  const positioning = usedLayout.positioning(xScale, yScale);
  const nodes = layout.descendants();
  const labels = layout.labels && layout.labels() || [];

  // probably could get some speed up by not recomputing the voronoi all the time
  const voronoiEval = voronoi().extent([[0, 0], [windowProps.width + 1, windowProps.height + 1]]);
  const voronois = voronoiEval.polygons(nodes.map(d => [...positioning(d), d])).filter(d => d.length);
  return {
    labels,
    nodes,
    positioning,
    voronois,
    layout,
    xScale,
    yScale
  };
};
github vega / vega-dataflow / src / layout / Voronoi.js View on Github external
prototype.transform = function(_, pulse) {
  var as = _.as || 'path',
      data = pulse.source,
      diagram, polygons, key, i, n;

  // configure and construct voronoi diagram
  diagram = voronoi();
  for (i=0, n=PARAMS.length; i
github protectwise / troika / packages / troika-examples / globe / CountryBufferGeometry.js View on Github external
if (intersect) inside = !inside
  }
  return inside
}

function isTriangleInPoly(trianglePoints, polyPoints) {
  // Use any point that lies within the triangle
  let [x1, y1] = trianglePoints[0]
  let [x2, y2] = trianglePoints[1]
  let [x3, y3] = trianglePoints[2]
  let edgeX = x2 + (x3 - x2) / 2
  let edgeY = y2 + (y3 - y2) / 2
  return isPointInPolygon2(x1 + (edgeX - x1) / 2, y1 + (edgeY - y1) / 2, polyPoints)
}

const voronoiInstance = voronoi()

export default class CountryBufferGeometry extends BufferGeometry {
  /**
   *
   * @param {Array} coords in geojson `coordinates` format
   */
  setCoordinates(coords) {
    var xyPositions = []
    var indexes = []

    // General approach adapted from example at https://forum.processing.org/one/topic/drawing-countries-on-top-of-a-3d-sphere-from-set-of-boundaries.html
    let handleCoordsGroup = coordsGroup => {
      // Normalize the incoming multi-dimensional polygon arrays
      let [mainPoly, ...holePolys] = coordsGroup
      for (let i = 0, iLen = coordsGroup.length; i < iLen; i++) {
        for (let j = 0, jLen = coordsGroup[i].length; j < jLen; j++) {
github FormidableLabs / victory / src / components / victory-voronoi-tooltip / helper-methods.js View on Github external
getPolygons(range, scale, data) {
    const minRange = [Math.min(...range.x), Math.min(...range.y)];
    const maxRange = [Math.max(...range.x), Math.max(...range.y)];
    const voronoi = d3Voronoi()
      .x((d) => scale.x(d._x1 !== undefined ? d._x1 : d._x))
      .y((d) => scale.y(d._y1 !== undefined ? d._y1 : d._y))
      .extent([minRange, maxRange]);
    return voronoi.polygons(data);
  },
github FormidableLabs / victory-native / lib / helpers / native-voronoi-helpers.js View on Github external
getVoronoi(props, mousePosition) {
    const {width, height, voronoiPadding} = props;
    const padding = voronoiPadding || 0;
    const voronoiFunction = d3Voronoi()
      .x((d) => d.x)
      .y((d) => d.y)
      .extent([[padding, padding], [width - padding, height - padding]]);
    const datasets = this.getDatasets(props);
    const voronoi = voronoiFunction(this.mergeDatasets(props, datasets));
    const size = props.dimension ? undefined : props.radius;
    return voronoi.find(mousePosition.x, mousePosition.y, size);
  },
github chartshq / muze / packages / muze-utils / src / common-utils.js View on Github external
constructor (data = []) {
        this._voronoi = voronoi().x(d => d.x).y(d => d.y);
        this.data(data);
    }

d3-voronoi

Compute the Voronoi diagram of a set of two-dimensional points.

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

55 / 100
Full package analysis

Popular d3-voronoi functions