Skip to content

Should facets work on a Map? #247

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

Closed
Fil opened this issue Mar 16, 2021 · 2 comments
Closed

Should facets work on a Map? #247

Fil opened this issue Mar 16, 2021 · 2 comments
Labels
bug Something isn’t working

Comments

@Fil
Copy link
Contributor

Fil commented Mar 16, 2021

If the data is a Map (for example obtained with d3.rollup), faceting doesn't work. Documentation or bug?

data = d3.rollup()

Plot.plot({
  facet: {
    data,
    x: "0"
  },
  marks: [Plot.barY(data, { x:"0", y: "1" })]
})

https://observablehq.com/d/a3de0aa6815cab5c

const markFacets = mark.data === this.data ? facetsIndex : undefined;

@mbostock mbostock added the bug Something isn’t working label Mar 16, 2021
@mbostock
Copy link
Member

This is a bug caused by the greedy arrayify here:

this.data = arrayify(data);

@Fil
Copy link
Contributor Author

Fil commented Mar 17, 2021

Removing it doesn't break any test.

diff --git a/src/mark.js b/src/mark.js
index 504f93b..5b2a611 100644
--- a/src/mark.js
+++ b/src/mark.js
@@ -8,7 +8,7 @@ const objectToString = Object.prototype.toString;
 export class Mark {
   constructor(data, channels = [], options = {}) {
     const names = new Set();
-    this.data = arrayify(data);
+    this.data = data;
     this.transform = maybeTransform(options);
     this.channels = channels.filter(channel => {
       const {name, value, optional} = channel;

maybe for safety we can add it later, before we pass it to this.transform (but I doubt it's necessary?):

@@ -29,7 +29,7 @@ export class Mark {
     });
   }
   initialize(facets) {
-    let data = this.data;
+    let data = arrayify(this.data);
     let index = facets === undefined && data != null ? range(data) : facets;
     if (data !== undefined && this.transform !== undefined) {
       if (facets === undefined) index = index.length ? [index] : [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

No branches or pull requests

2 participants