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

Arquero shorthand #449

Closed
mbostock opened this issue Jul 7, 2021 · 3 comments
Closed

Arquero shorthand #449

mbostock opened this issue Jul 7, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Jul 7, 2021

Currently to use Arquero, you say:

Plot.plot({
  marks: [
    Plot.tickX(table.indices(), {y: table.column("age"), x: table.column("percent")})
  ]
})

But with a little magic, we could support shorthand for Arquero, treating it like an array of objects:

Plot.plot({
  marks: [
    Plot.tickX(table, {y: "age", x: "percent"})
  ]
})

Specifically:

  1. If data is an Arquero table, then data is data.indices().
  2. If data is an Arquero table, then field names are interpreted as data.column(field).
@mbostock mbostock added the enhancement New feature or request label Jul 7, 2021
@Fil
Copy link
Contributor

Fil commented Jul 9, 2021

It seems to me that the shorthand notation already works.

However, it's not optimal in the sense that:

  1. Plot calls arrayify on the table (running the iterator)—using table.indices() would avoid that step, but respecting an arquero table as being "arrayified" would work too;
  2. Plot instantiates the channels in valueof with Array.from(data, field("fieldname"))—it could just call table.column("field") if it was passed an arquero table.

If we want that optimization, we need a good method to detect an arquero-like table. Maybe when typeof data.column === "function"? Then, arrayify would pass it unchanged, and valueof would call data.column()?

@mbostock
Copy link
Member Author

mbostock commented Jul 9, 2021

Sorry, I should have clarified; you’re right that it already works, but I want it to be faster by being equivalent to the longer one.

FWIW, Inputs.table depends typeof data.columnNames === "function", but I think here we’d maybe want to use typeof data.indices === "function" && typeof data.column === "function", if those are the functions we’d use to implement it:

https://github.com/observablehq/inputs/blob/8fbbcf76f40445346637a764825454e4f7fcc76f/src/table.js#L351

@Fil Fil self-assigned this Jul 9, 2021
Fil added a commit that referenced this issue Jul 9, 2021
optimizes accesses to arquero tables through *Table*.column(fieldname)

closes #449
@Fil Fil mentioned this issue Jul 9, 2021
@mbostock
Copy link
Member Author

Duplicate of #191.

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

Successfully merging a pull request may close this issue.

2 participants