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

Shorthand singleton marks #689

Open
mbostock opened this issue Jan 19, 2022 · 1 comment
Open

Shorthand singleton marks #689

mbostock opened this issue Jan 19, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

For single-instance marks, it’d be neat if you could just pass options without data. For example:

Plot.text({
  text: "Hello, world!"
  x: new Date("2016-05-01"),
  y: 100,
  dx: -10,
  dy: 40,
  frameAnchor: "top-left"
})

Could be equivalent to:

Plot.text({length: 1}, {
  text: ["Hello, world!"],
  x: [new Date("2016-05-01")],
  y: [100],
  dx: -10,
  dy: 40,
  frameAnchor: "top-left"
})

It feels like the helper would need to know which options possibly represent channels, though. And there would potentially be ambiguity with alternative representations of data (such as Arquero objects #449); though that could be addressed by checking the number of arguments and whether the first is a plain object (Object.getPrototypeOf === Object.prototype).

@mbostock mbostock added the enhancement New feature or request label Jan 19, 2022
@mbostock
Copy link
Member Author

Possible approach, but I’m unsure how to generalize…

export function text(data, options = {}) {
  if (arguments.length === 1 && Object.getPrototypeOf(data) === Object.prototype) {
    const {x, y, text, ...rest} = data;
    data = {length: 1};
    options = {...rest, x: x == null ? x : [x], y: y == null ? y : [y], text: text == null ? text : [text]};
  }
  const {x, y, ...rest} = options;
  if (options.frameAnchor === undefined) ([x, y] = maybeTuple(x, y));
  return new Text(data, {...rest, x, y});
}

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

No branches or pull requests

1 participant