Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR TypeError: Cannot read property 'fromObject' of undefined #35

Open
ashishradadia opened this issue Jun 16, 2021 · 0 comments
Open

Comments

@ashishradadia
Copy link

i am adding custom object like arrow from blow code drow arrow is working fine
but when i retrieved from json it will gives me error

ERROR TypeError: Cannot read property 'fromObject' of undefined
at fabric.js:1062

below is my code for draw arrow


 this.LineWithArrow = fabric.util.createClass(fabric.Line, {
      type: 'lineWithArrow',
      hasBorders: false,
      hasControls: true,

      _getCacheCanvasDimensions() {
        var dim = this.callSuper('_getCacheCanvasDimensions');
        dim.width += 15; 
        dim.height += 15;
        return dim;
      },

      _render(ctx) {
        this.callSuper('_render', ctx);
        ctx.save();
        const xDiff = this.x2 - this.x1;
        const yDiff = this.y2 - this.y1;
        const angle = Math.atan2(yDiff, xDiff);
        ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
        ctx.rotate(angle);
        ctx.beginPath();
        // Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
        ctx.moveTo(this.strokeWidth * 2, 0);
        ctx.lineTo(this.strokeWidth * -1.5, this.strokeWidth * 1.5);
        ctx.lineTo(this.strokeWidth * -1.5, this.strokeWidth * -1.5);
        ctx.closePath();
        ctx.fillStyle = this.stroke;
        ctx.fill();
        ctx.restore();
      },
    });

    this.LineWithArrow.fromObject = (object, callback) => {
      callback && callback(new this.LineWithArrow([object.x1, object.y1, object.x2, object.y2], object));
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant