Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
why d3.path().moveTo() function is undefined?

my function to generate path:

const getPath = (source, target) => {
    // console.log('path', path.moveTo(source.x, source.y));
    const path = d3.path()
      .moveTo(source.x, source.y)
      .lineTo(target.x, source.y)
      .lineTo(target.x, target.y)
      .toString();
    // console.log('path', path);
    return path;
  }

d3 import statement:

import * as d3 from "d3";

source and target structure:

{
  x: Number,
  y: Number
}

this is the error i am getting

why is moveTo undefined what am i doing wrong? i'm on react btw.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

moveTo does not return anything, so its return value is undefined. It does not return the path, so you cannot do method chaining here. You can see this in the source code for moveTo:

moveTo: function(x, y) {
  this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
},

You can adjust your code to this and it should work:

const getPath = (source, target) => {
    const path = d3.path();

    path.moveTo(source.x, source.y);
    path.lineTo(target.x, source.y);
    path.lineTo(target.x, target.y);

    return path.toString();
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda