Skip to content

Arquero shorthand #449

Description

@mbostock

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).

Activity

  1. Fil commented on Jul 9, 2021

    @Fil
    Contributor

    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()?

  2. mbostock commented on Jul 9, 2021

    @mbostock
    MemberAuthor

    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

  3. self-assigned this
    on Jul 9, 2021
  4. added a commit that references this issue on Jul 9, 2021
    d8e6c79
  5. mbostock commented on Feb 26, 2022

    @mbostock
    MemberAuthor

    Duplicate of #191.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions