Skip to content

Range slider second iteration (part 2: on-par range plots !!!) #1017

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

Merged
merged 4 commits into from
Oct 11, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Oct 6, 2016

fixes #472

This PR builds on top of #946 and #962 to bring range plots (the little little subplot within the range slider) on-par with good old cartesian subplots.

That is, ALL cartesian trace types are now supported in the range slider - they now appear as they would in a miniature subplot.

- .. into a plotOne function that works with any sufficiently mocked
  plotinfo objects and calcdata array
by Cartesian.rangePlot which uses the same subplot layer creation
and plot command as 'regular' cartesian subplots.

- rm obsolete rangeslider/range_plot.js and rangeslider/helpers.js
- add test for clipPath deletion
- the new rangePlot routine generates much sharper lines
@etpinard etpinard added bug something broken feature something new status: reviewable labels Oct 6, 2016
@etpinard etpinard added this to the v1.18.0 milestone Oct 6, 2016
@etpinard etpinard changed the title Edit Range slider second iteration (part 2: on-par range plots !!!) Range slider second iteration (part 2: on-par range plots !!!) Oct 6, 2016
});
}

function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the algorithm is as follows:

  1. find all the subplots spanned by the axis where the range slider reside
  2. for each subplot, mock a plotinfo object (which are essentially the cartesian subplot state objects) using range slider options to find the width and height
  3. find all traces in this subplot
  4. Call Cartesian.rangePlot which creates all the required layers and plots / styles the given plotinfo subplot
  5. clip the subplot

@etpinard
Copy link
Contributor Author

etpinard commented Oct 6, 2016

cc @rreusser @mdtusz

Copy link
Contributor

@rreusser rreusser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes required by me. Looks like a nicely done, robust addition—and appears to be mostly a result of removing code (correct me if I'm wrong!). 🎉


var gRangePlot = rangeSlider.selectAll('g.' + constants.rangePlotClassName)
var clipPath = fullLayout._topdefs.selectAll('#' + opts._clipId)
.data([0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manage to factor out the .data([0]) pattern? I suppose it would be a function with a name like var clipPath = createOrAppend(fullLayout._topdefs, '#' + opts._clipId);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I'll do that in a PR of its own. Hopefully this week.

.attr('class', function(id) { return constants.rangePlotClassName + ' ' + id; })
.call(Drawing.setClipUrl, opts._clipId);

rangePlots.order();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice. The order is important to manage (and easy to neglect) with all of these d3 joins.

var oppAxisOpts = Axes.getFromId(gd, id, 'y'),
oppAxisName = oppAxisOpts._name;

var mockFigure = {
Copy link
Contributor

@rreusser rreusser Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. There's something I always like the usage of supplyDefaults for mocking instead of the real thing. Feels robust and lightweight. I liked using it with animations since many things just worked.

exports.rangePlot = function(gd, plotinfo, cdSubplot) {
makeSubplotLayer(plotinfo);
plotOne(gd, plotinfo, cdSubplot);
Plots.style(gd);
Copy link
Contributor

@rreusser rreusser Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only tangentially relevant, but I'm not a huge fan of Plots.style. Long story short, when you transition the position and styles of an element at the same time, you must do them in a single transition operation, otherwise one discards the other.

In other words, for most d3 things that animate, I had to copy the styling into the inner join loop along with positioning instead of just applying styles on a completely separate pass (but to make sure it's robust and since the cost is probably small, I didn't remove styling from module.style).

It's fine as-is, just something to think about since the separate-pass styling approach wasn't fully compatible with what I needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'm not a fan of Plots.style too.

As soon as we'll find a solution for removing this ugly block

if(plotinfo.plot) {
  plotinfo.plot.selectAll('g:not(.scatterlayer)').selectAll('g.trace').remove();
}

in the main cartesian plot routine, we'll get rid of Plots.style

@etpinard
Copy link
Contributor Author

and appears to be mostly a result of removing code (correct me if I'm wrong!).

Yep exactly. This PR makes use of #946 to reuse the cartesian plot step for the range slider range plots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rangeslider does not leave null gaps.
2 participants