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

Closes #157; Add Multi-axis Support #198

Merged
merged 6 commits into from Oct 10, 2015
Merged

Closes #157; Add Multi-axis Support #198

merged 6 commits into from Oct 10, 2015

Conversation

rsandor
Copy link
Collaborator

@rsandor rsandor commented Oct 7, 2015

Description

screen shot 2015-10-07 at 2 20 10 am

This adds left/right multi-axis support to all real-time plots, and specific support for the real-time line chart. We abstract the range option to allow the programmer to supply a left and right range if they so desire.

TODO

  • Add support for basic line charts with multi-axes
  • Test: Epoch.Time.Plot
  • Test: Epoch.Time.Line
  • Test: Epoch.Util.flatten

Code Example

// Specify the left and right ranges
var leftRange = [0, 100];
var rightRange = [-10, 10];

// Setup two series, each using a different range
var data = [
  {
    label: 'Left Ranged Series',
    values: [
      { time: 0, y: 0 },
      { time: 1, y: 10 },
      { time: 2, y: 99 },
      ...
    ],
    // This is how your tell a layer to use a specific range...
    range: leftRange
  },
  {
    label: 'Right Ranged Series',
    values: [
      { time: 0, y: -9.8 },
      { time: 1, y: 2.4 },
      { time: 2, y: -0.5 },
      ...
    ],
    // Again, we must define the range for this particular series...
    range: rightRange
  }
];

// Create the real-time line plot with two ranges
var chart = new Epoch.Time.Line({
  range: {
    left: leftRange,
    right: rightRange
  },
  data: data,
  axes: ['left', 'right', 'bottom']
});

This adds left/right  multiaxis support to all real-time plots, and specific support for the real-time line chart. We abstract the `range` option to allow the programmer to supply a `left` and `right` range if they so desire. For example:

```js
// Specifiy the left and right ranges
var leftRange = [0, 100];
var rightRange = [-10, 10];

// Setup two series, each using a different range
var data = [
  {
    label: 'Left Ranged Series',
    values: [
      { time: 0, y: 0 },
      { time: 1, y: 10 },
      { time: 2, y: 99 },
      ...
    ],
    range: leftRange
  },
  {
    label: 'Right Ranged Series',
    values: [
      { time: 0, y: -9.8 },
      { time: 1, y: 2.4 },
      { time: 2, y: -0.5 },
      ...
    ],
    range: rightRange
  }
];

// Create the real-time line plot with two ranges
var chart = new Epoch.Time.Line({
  range: {
    left: leftRange,
    right: rightRange
  },
  data: data,
  axes: ['left', 'right', 'bottom']
});

```
@rsandor
Copy link
Collaborator Author

rsandor commented Oct 7, 2015

I am considering allowing the programmer to use the names left and right when defining data for the series, like so:

var data = [
  { range: 'left', values: [...] },
  { range: 'right', values: [...]}
];

What do you guys think about this?

@rca
Copy link
Contributor

rca commented Oct 7, 2015

Awesome! 🙌

+1 being able to specify the range right in the data array.

Based on the code sample above, it looks like a fixed range needs to be given; is it possible to auto-scale? Not sure what the implementation would look like, possibly specify true rather than a [min, max] arrray?

var chart = new Epoch.Time.Line({
  range: {
    left: true,
    right: true
  },
  [...]
});

Do you have any thoughts on how to go about suggesting what dataset is associated with a particular axis, either by color coding the labels the same color as the dataset or some other means? For instance, in the example above, I have no idea what the range of either dataset is. Color coding becomes ambiguous as soon as there are multiple datasets on an axis, though. Maybe the answer is axis titles and a legend?

In any case, this looks great!

@rca
Copy link
Contributor

rca commented Oct 7, 2015

Also, with respect to fixed vs. dynamic ranges, would it be possible to reconfigure the range when data is being updated?

@rsandor
Copy link
Collaborator Author

rsandor commented Oct 9, 2015

@rca - In the visualizations I have seen (mostly static, mind you) they usually use the context of the data with an associated legend. I don't think you can clearly understand a multi-axis chart without these. Thus I think it is up to the visualization designer to clearly communicate the data or trend they are trying to show with any real-time line chart.

To this end there is an effort currently under way to add a new "legends" plugin for Epoch that can help when creating visualizations such as these (see #2 and #146). I have always been of the belief that legends and labels are outside the scope of the project. Recently I have been thinking that there should be "helpers" that make it easy to generate markup and basic styles that can be mutated to fit a particular design. Any help with legends and labels support would be greatly appreciated.

@rsandor rsandor changed the title Closes #157; Add Multiaxis Support Closes #157; Add Multi-axis Support Oct 9, 2015
@rsandor
Copy link
Collaborator Author

rsandor commented Oct 9, 2015

@rca - Added the ability to automatically generate the axes ranges by using labels. Here's how it works, define you data like so:

var data = [
  { label: 'Layer 1', range: 'range-a', data: [...] },
  { label: 'Layer 2', range: 'range-b', data: [...] },
  { label: 'Layer 3', range: 'range-a', data: [...] }
];

Each layer in the data is as associated with a "range label" which can then be applied to the left or right side of the chart when you make it:

var chart = new Epoch.Time.Line({
  data: data,
  range: {
    left: 'range-a',
    right: 'range-b'
  }
});

The left axis will automatically fit the min and max of the collected values from both layers 1 and 3. The right side will use the min and max of layer 2 only.

Does this suffice for the "automatic" ranges?

@rca
Copy link
Contributor

rca commented Oct 9, 2015

I see your point about legends and labels being out of scope. Helpers would definitely be useful, for example "what's the color of the first dataset", "give me the label for the first dataset", etc.

@rca
Copy link
Contributor

rca commented Oct 9, 2015

Taking a look at dynamic range definitions now, nice! :)

@rca
Copy link
Contributor

rca commented Oct 9, 2015

By the way, given the discussion about legends and axis labels not being part of Epoch itself, what is the purpose of making label part of the chartData array?

@rsandor
Copy link
Collaborator Author

rsandor commented Oct 10, 2015

The label field harkens way back to the early days when I had intended to create legend helpers. I decided against focusing on it, and now I'm coming back around :) It has also been used to apply specific classes to layers so you can style semantically.

@rsandor
Copy link
Collaborator Author

rsandor commented Oct 10, 2015

This is ready to go. Merging.

rsandor added a commit that referenced this pull request Oct 10, 2015
Closes #157; Add Multi-axis Support
@rsandor rsandor merged commit 670f00a into master Oct 10, 2015
@rsandor rsandor deleted the multiaxes branch October 10, 2015 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants