Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!