mi función para generar ruta:
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; }declaración de importación d3:
import * as d3 from "d3";estructura de origen y destino:
{ x: Number, y: Number }¿Por qué MoveTo no está definido? ¿Qué estoy haciendo mal? estoy en reaccionar por cierto.
moveTo no devuelve nada, por lo que su valor de retorno no está undefined . No devuelve la ruta, por lo que no puede hacer un encadenamiento de métodos aquí. Puedes ver esto en el código fuente de moveTo :
moveTo: function(x, y) { this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y); },Puede ajustar su código a esto y debería funcionar:
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(); }