statgen / locuszoom

A Javascript/d3 embeddable plugin for interactively visualizing statistical genetic data from customizable sources.
https://statgen.github.io/locuszoom/
MIT License
154 stars 29 forks source link

Layout array syntax #69

Closed Frencil closed 8 years ago

Frencil commented 8 years ago

This branch refactors the layout syntax for panels and data layers to be arrays of objects. This addresses Issue #68.

Essentially where before we had this:

var layout = {
  ...
  panels: {
    panel_1_id: {
      ...
      data_layers: {
        data_layer_1_id: {
          ...
        }
      }
    },
    panel_2_id: {
      ...
    }
  }
};

We now have something like this:

var layout = {
  ...
  panels: [
    {
      id: "panel_1_id",
      data_layers: [
        {
          id: "data_layer_1_id",
          ...
        }
      ]
    },
    {
      id: "panel_2_id",
      ...
    }
  ]
};

This is more internally consistent as with this change all customizable data (i.e. panel IDs and data layer IDs, in addition to all the other layout "values") are consistently to the right side of the colon in any place in the layout. The left side of the colon anywhere in the layout is now, consistently, a documented supported property of the layout.

Methods for adding panels and data layers got slightly simpler as they now just take a layout and do sanity checking to make sure an ID is present in the layout (before they took ID and layout separately).

MrFlick commented 8 years ago

Looks good. Do we really need to require an ID? Can we assign some random name if they don't supply one? If naming things is hard, it might be nice not to require it if it's not necessary.

Frencil commented 8 years ago

Do we really need to require an ID? Can we assign some random name if they don't supply one? If naming things is hard, it might be nice not to require it if it's not necessary.

Good call. I just pushed an update that will generate an ID if not present in the layout (with tests) and will still throw an error if passed a panel layout that explicitly specifies a panel ID that's already in use (also with a test). ID generation is of the form "p" followed by a pseudorandom 8 digit number.