-
Notifications
You must be signed in to change notification settings - Fork 477
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
Implement non-measured layers of nodes to plexus #420
Implement non-measured layers of nodes to plexus #420
Conversation
Nodes can now be rendered as layers of non-measurable nodes. This means they take the position and size of nodes in as parameters to the render function. This is handy for decorating the main nodes with highlights or metadata. Other changes: - Add a comparison of using SVG vs HTML for borders and emphasis on nodes to the demo; show as both medium and small sized graphs - Consolidate common code to the HtmlLayer and SvgLayer components - Switch to the more succinct prop instead of for internal components - Allow SvgEdgesLayer to have defs prop when it's a standalone layer Signed-off-by: Joe Farro <joef@uber.com>
Codecov Report
@@ Coverage Diff @@
## master #420 +/- ##
==========================================
- Coverage 91.63% 91.58% -0.06%
==========================================
Files 176 176
Lines 3994 3994
Branches 921 921
==========================================
- Hits 3660 3658 -2
- Misses 296 298 +2
Partials 38 38
Continue to review full report at Codecov.
|
Signed-off-by: Joe Farro <joef@uber.com>
79d5f3c
to
a208da8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, but was pretty dense to get through. As discussed yesterday, documentation once the implementation is tested and settled will be worthwhile!
I added two questions that may not result in any changes.
@@ -143,8 +146,8 @@ export type TLayer<T = {}, U = {}> = TOneOfFour< | |||
>; | |||
|
|||
export type TMeasurableNodeProps<T = {}> = Omit<TMeasurableNodeRenderer<T>, 'measurable'> & { | |||
classNamePrefix?: string; | |||
hidden?: boolean; | |||
getClassName: (name: string) => string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why were these made mandatory? what could it be name
would be provided to this function?(name: string) => string | string
?
Edit as I saw use cases for name
. I think this can be optional and default to an identity function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Damn, my first comment was lost due to flaky internet)
The public API is clasNamePrefix
which defaults to plexus
.
Only internal components use getClassName
which is basically just:
const { classNamePrefix: prefix = 'plexus' } = this.props;
const getClassName = (name: string) = `${prefix} ${prefix}--LayeredDigraph--${name}`;
// e.g.
getClassName(`SvgEdge`) === 'plexus plexus--LayeredDigraph--SvgEdge';
It just serves to shorten and the class name generation and ensure consistency.
</g> | ||
); | ||
if (extraWrapper) { | ||
content = <g {...extraWrapper}>{content}</g>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the consumer can add props to the "standard" g
, what is the use case for the extra g
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately, this results in:
<svg>
<g className={ consumerDefinedClassName } style={ CONSTANT_STYLE }>
<g className={ anotherConsumerDefinedClassName } transform={ basedOnZoomManager }>
<g { ...extraWrapperPropsDefinedByConsumer }>
<g { ...containerPropsAlsoDefinedByConsumer }>
{defs /* ... */}
{children}
</g>
</g>
</g>
</g>
</svg>
I don't know if there is a downside to having multiple nested <g>
s, but it seems like this is more complicated than necessary. It leaves me wondering when a consumer would define something through setOnContainer
vs extraWrapper
, and which of the two classNames
that I defined I should style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extraWrapper
is for internal use only; it's not part of the public API.. So, the public API is not ambiguous, the user would use setOnContainer
.
Mainly, extraWrapper
so the edges can have the stroke
defaulted to #000
without it inadvertently overriding the CSS styling set through the public API. E.g. the container the user applies setOnContainer
to inherits the stroke="#000"
but can override it via CSS styling.
Right now there is a <g>
for each thing that needs to be accomplished. To reduce the nesting would entail combining some <g>
elements, which will be a bit more complex to map the code to the DOM elements.
I agree the levels of nesting could be reduced. But I'm pretty sure it's still very light as this happens on the scale of the number of layers not the number of vertices or edges in the graph. I would think the perf impact is negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, when we document this, we may also want to update what is public
v private
v protected
Implement non-measured layers of nodes to plexus Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
Which problem is this PR solving?
Add support for rendering supplemental layers of nodes in plexus graphs.
Short description of the changes
Nodes can now also be rendered as layers of non-measured nodes. Non-measured means they take the position and size of nodes in as parameters to the render function. This is handy for decorating the main nodes with supplemental visual elements, such as UX based highlights or borders that scale well when zoom is being used.
Other changes:
Add a comparison of using SVG vs HTML for borders and emphasis on nodes to the demo; show as both medium and small sized graphs
Consolidate common code to the
HtmlLayer
andSvgLayer
componentsSwitch to the more succinct
getClassName
prop instead ofclassNamePrefix
for internal componentsAllow
SvgEdgesLayer
to havedefs
prop when it's a standalone layerScreenshots
For the screenshots, we're adding a 1 pixel border to the nodes and highlighting nodes with labels that start with a vowel.
The HTML version of the border and emphasis is rendered with a 1 pixel border on the node and the vowel emphasis is via a padded, striped background with a one pixel dashed outline.
For the version which uses SVG to look better when zoomed out:
The rationale for the SVG + HTML version is the HTML background will be visible when the node is not zoomed out. When it is zoomed out, the HTML padded background will become small and the strokes will stay viewable. This allows the detailed styling of the HTML version to be seen while near normal scale but for the emphasis, in general, to still be visible when the scale is small.
The HTML version
Normal zoom ↓
Zoomed out to a medium size ↓
Zoomed out to a small size ↓
The SVG + HTML version
Normal zoom ↓
Zoomed out to a medium size ↓
Zoomed out to a small size ↓