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

Captions are not drawn relative to model origin #469

Open
hjfreyer opened this issue Aug 2, 2020 · 1 comment
Open

Captions are not drawn relative to model origin #469

hjfreyer opened this issue Aug 2, 2020 · 1 comment
Labels

Comments

@hjfreyer
Copy link

hjfreyer commented Aug 2, 2020

Maybe this is working as intended, but I found it surprising.

Steps to reproduce

  1. Write a script with a top-level model that includes sub-models with captions. For example:
var m = require("makerjs");

function box1() {
  return {
    paths: {},
    origin: [0, 0],
    models: {
      inner: new m.models.Rectangle(10, 10)
    },
    caption: {
      text: "B1",
      anchor: new m.paths.Line([5, 5], [5, 5])
    }
  };
}

function box2() {
  return {
    paths: {},
    origin: [11, 0],
    models: {
      inner: new m.models.Rectangle(10, 10)
    },
    caption: {
      text: "B2",
      anchor: new m.paths.Line([5, 5], [5, 5])
    }
  };
}

function main() {
  return {
    paths: {},
    models: {
      box1: box1(),
      box2: box2()
    }
  };
}

module.exports = main();
  1. Render the script in the playground or with SVG.

Expected result

Each caption is in the middle of its box.

Actual result

Captions are displayed on top of each other.

Workaround

Calling originate() on the overall model puts the captions into their proper places:

function main() {
  return originate({
    paths: {},
    models: {
      box1: box1(),
      box2: box2()
    }
  });
}

Commentary

I think this is very confusing, considering everything else is drawn relative to the model's origin.

If I put the caption in its own sub-model, then it works as I expected:

function box2() {
  return {
    paths: {},
    origin: [11, 0],
    models: {
      inner: new m.models.Rectangle(10, 10),
      cap: {
        caption: {
          text: "B2",
          anchor: new m.paths.Line([5, 5], [5, 5])
        }
      }
    }
  };
}

Is this the intended use case? If so addCaption is a little weird for not doing it that way.

@danmarshall
Copy link
Contributor

Thanks for pointing this out @hjfreyer - I believe your expectation is correct, I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants