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

Chore: Set dimensions on parent element, Preserve graph container contents #24

Merged
merged 4 commits into from
Oct 7, 2022

Conversation

cizl
Copy link
Contributor

@cizl cizl commented Oct 5, 2022

container.style.display = 'block';
console.warn("[Orb] Graph container doesn't have defined 'display' property. Setting 'display' to 'block'...");
}
if (!style.width || style.width === '0px') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this covering cases like '0rem', '0', '0 px' if those are possible values for .width and .height (down below)?

Copy link
Contributor Author

@cizl cizl Oct 6, 2022

Choose a reason for hiding this comment

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

Good point. In firefox the getComputedSize returns a 0px specifically. I can check if it startsWith('0') or something like that. Would that make sense?

Another point is, what if the user programmatically is switching sizes, then we override that with this condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that should do the trick. I just tried this:

<div id="testing-height" style="height: 010px"></div>
document.getElementById("testing-height").style.height // outputs '10px'

All in all, 010px is a valid style, but luckily browser will take out the leading zeros.

Regarding user switching sizes, could we maybe then add settings param for it? Which is enabled by default. What do you think?

Copy link
Contributor Author

@cizl cizl Oct 7, 2022

Choose a reason for hiding this comment

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

@tonilastre That definitely makes sense! Justin Case - I added a regex to capture all "collapsed" style dimensions.

I've been meaning to talk to you about our settings. I'm not very happy with the current implementation. It's tricky to consume settings from a DX perspective - the types are especially tricky. Plus, now they have duplicated fields. We could add a base interface for ViewSettings in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with you regarding settings. I think we should do that along with the following fix: #16. With that in mind, we could create a baseline interface as well as AbstractView.

@@ -389,6 +388,17 @@ export class DefaultView<N extends INodeBase, E extends IEdgeBase> implements IO
}
};

private _initCanvas(): HTMLCanvasElement {
const canvas = document.createElement('canvas');
canvas.id = 'orbCanvas';
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if there is a HTMLElement with the same id in the application using Orb? Do we want to introduce uuid for these kind of ids?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good comment, I was just wondering that. I'm assigning uuids in ngx-orb, but we may want to have those in here as well. But I'm not sure wether this is the responsibility of the user or the library. It also makes sense to me that the user takes care of his own container and orb instances.

This is effectively a leftover so I'll delete it. I used this to get the canvas element but then i realized that I already have a reference to the element (this._canvas)

@tonilastre tonilastre added the bug Something isn't working label Oct 6, 2022
@cizl cizl changed the title Chore: Set dimensions on parent element when undefined, Preserve grap… Chore: Set dimensions on parent element, Preserve graph container contents Oct 6, 2022
@cizl cizl marked this pull request as ready for review October 6, 2022 10:00
@cizl cizl requested a review from tonilastre October 7, 2022 10:58
}
};

export const collapsedDimensionRegex = /^\s*0+\s*(?:px|rem|em|vh|vw)?\s*$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

If px, rem, em can be the upper case then you need to add an ignore-case flag at the end of the regex, /..../i;

@cizl cizl merged commit 38e83e3 into release/0.1.2 Oct 7, 2022
@cizl cizl deleted the fix-collapsing-canvas-size branch October 7, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants