Skip to content

Test nested connections and add nested connection #91

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 12 commits into from
Nov 21, 2017

Conversation

bpostlethwaite
Copy link
Member

@alexcjohnson This PR removes the modifyPlotProps system in favour of supplyPlotProps. It also introduces BoxGap - a component that talks to Layout though nested within a trace context.

supplyPlotProps is more general in that a component has the responsibility of returning plotProps rather than just modifying them. This adds a line of boilerplate to all components requiring additional behaviour const plotProps = unpackPlotProps(props, context); but the advantage is that there is more control.

For example <BoxGap> uses this functionality to forcibly assign fullLayout to fullContainer which gets around the problem of having a layoutConnected component inside a <Section> inside a traceConnected component.

The problem is that <Section> can only see the trace context so it hands unpackPlotProps a fullContainer that is fullData not fullLayout. The Layout connected component nested within does not recompute plotProps as we do not want to compute plotProps twice for every component in a <Section>. The Layout connected component is therefore broken. Now <BoxGap> supplies a layout fullContainer and we have a workaround.

PR review comment suggested that until override via props is necessary
we implement only the necessary context
Instead of modifyPlotProps we have a more general supplyPlotProps. If
a supplyPlotProps is present it is run. Most implementations of
supplyPlotProps will run `unpackPlotProps` first and then alter
plotProps as necessary. However, this enables us to now alter `props`
and `context` _before_ running unpackPlotProps. This will allows us to
"fix" the problem of nested layout fields within a trace context. See
#58 (comment)
for background.
@bpostlethwaite bpostlethwaite force-pushed the testNestedConnectionsAndAddNestedConnection branch from a5f8d5e to 04c83ef Compare November 20, 2017 02:54
WrappedComponent.modifyPlotProps(props, context, plotProps);
static supplyPlotProps(props, context) {
if (supplyPlotProps) {
return supplyPlotProps(props, context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not blocking by any means, this will work fine, but for symmetry and to avoid multiple things with the bare name supplyPlotProps I might have written this as

if (config.supplyPlotProps) {
  return config.supplyPlotProps(props, context);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

True, that might be an easier read. I'll make the change

<BoxGap
label={_('Box Padding')}
attr="boxgroupgap"
showArrows={false}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need this? It's already a NumericNoArrows component...

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope! Forgot to take it out

@@ -145,6 +147,21 @@ class DefaultEditor extends Component {
<ColorPicker label={_('Border Color')} attr="marker.line.color" />
</TraceMarkerSection>

<Section name={_('Size and Spacing')}>
<BoxGap label={_('Bar Width')} attr="bargap" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, what do we call this component? I feel like its name should indicate that it's numeric and that the attr you specify is in layout, not in a trace. But it's not specific to boxes or gaps.

Also, the label 'Bar Width' isn't quite right, is it? ie an increased bargap decreases the width, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

TraceLayoutNumericSansArrows.
I copied the workspace descriptions but looks like it is doing a transformation on the input. Maybe (1-x)*100. I'll implement this transform (and the reverse onUpdate) in this PR and tag you on the commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

With the transformation it will again be a hyper specific component so perhaps BoxGap is more applicable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though BoxWidth is probably clearer

@bpostlethwaite
Copy link
Member Author

@alexcjohnson okay implemented your suggestions. Also cb1a95a reintroduces modifyPlotProps. More info in the commit message.

We now have modifyPlotProps and supplyPlotProps. We have need of both
and trying to overload any one of them for both behaviours results in
complicated code.
@bpostlethwaite bpostlethwaite force-pushed the testNestedConnectionsAndAddNestedConnection branch from fad2cb5 to 1c137f3 Compare November 20, 2017 19:41
@@ -52,6 +52,9 @@ export default class Section extends Component {
} else if (isAttr) {
if (child.type.supplyPlotProps) {
plotProps = child.type.supplyPlotProps(child.props, context);
if (child.type.modifyPlotProps) {
child.type.modifyPlotProps(child.props, context, plotProps);
}
} else {
plotProps = unpackPlotProps(child.props, context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you see a use for this unpack, then wouldn't the if (child.type.modifyPlotProps) block possibly be relevant in that case too? ie should it be moved outside that if/else block, so the existences of supply and modify are independent?

src/shame.js Outdated
});
};

export const BoxWidth = connectLayoutToPlot(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps FractionalWidth? Or LayoutWidthFraction? Violin is going to use this too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep works for me 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

something like 1bebf70 ?

src/shame.js Outdated
}
};

plotProps.max = 100;
Copy link
Collaborator

Choose a reason for hiding this comment

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

right now all of these have min: 0, max: 1, so setting just max = 100 works. But I'd feel more comfortable about future-proofing if we at least explicitly supply min = 0, and maybe even better do the same (1-v) * 100 transform (which would actually switch min / max)

Copy link
Member Author

Choose a reason for hiding this comment

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

good point will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bpostlethwaite bpostlethwaite force-pushed the testNestedConnectionsAndAddNestedConnection branch from 1bebf70 to 94a27c1 Compare November 20, 2017 20:04
@alexcjohnson
Copy link
Collaborator

nice, lets go! 💃

@bpostlethwaite bpostlethwaite merged commit 76efee6 into develop Nov 21, 2017
@bpostlethwaite bpostlethwaite deleted the testNestedConnectionsAndAddNestedConnection branch November 21, 2017 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants