-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add pngFull function to Cytoscape.js Core with Visual Cues Enhancement #15
Conversation
…ethod overflow added to the canvas
…ethod overflow added to the canvas
…ethod overflow added to the canvas ü
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.
- There is a flood of console logs. Can you get rid of them?
#280 218ms Finished rendering
cytoscape-visual-cues.ts:869 #281 0ms Starting document clone with size 1728x915 scrolled to 0,0
html2canvas.esm.js:7624 #281 176ms Document cloned, element located at 317.1070556640625,740.471435546875 with size 77.43096923828125x78.6600341796875 using computed rendering
html2canvas.esm.js:7624 #281 176ms Starting DOM parsing
- This produces wrong images for "n18" node. See image below generated by this.
versus the image I see on the canvas
- I see this method is computationally very expensive and long and hard to detect errors. Why not call
html2canvas
on the cytoscape.js container element? This seems much faster and smaller. Below code works to get image of what you see. To get the full image of canvas, maybe we need to play with the functionhtml2canvas(
Can you try that?
export async function pngFull(isWholeScreen: boolean): Promise<string> {
const cy = this;
const cyZoom = cy.zoom();
const container = cy.container();
return (
await html2canvas(container, {
backgroundColor: "transparent",
scale: isWholeScreen ? 1 / cyZoom : 1,
})
).toDataURL();
}
demo/demo.html
Outdated
@@ -103,6 +103,8 @@ <h2 class="accordion-header" id="panelsStayOpen-headingOne"> | |||
Save | |||
</button> | |||
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1"> | |||
<li><a class="dropdown-item" href="#" onclick="exportPng()">PNG</a></li> | |||
<li><a class="dropdown-item" href="#" onclick="exportPngAll()">PNG (hall)</a></li> |
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.
nitpick: I guess "(hall)" is a typo, shouldn't it need to be "(all)"?
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.
src/cytoscape-visual-cues.ts
Outdated
* @param {string[]} ignoreElementClasses - Array of classes to ignore. | ||
* @returns combinedBase64 - Base64-encoded PNG of the graph. | ||
*/ | ||
export async function pngFull(options: any, ignoreElementClasses: 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.
suggestion: define type or interface for options
, don't use any
. This will be more clear and type-strict
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.
Thank you for the suggestion, the interface has been defined for PngOptions.
Also, another issue is the pipeline. Why it failed? |
Now the pipeline is running without any issues. I have added the "Install Dependencies" step before running the project. Is this okay? |
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.
How about a different approach: If it's full first save the pan and zoom values of the canvas first. And then fit to canvas. And then wait some time so that the cues are positioned properly and then call html2canvas
. After that revert the cytoscape pan and zoom values. The only disadvantage of this method is small flickering since we are changing pan and zoom values programmatically. But still, it's faster.
/**
*
* @param wait milliseconds to wait
* @returns
*/
export function asyncWait(wait: number): Promise<boolean> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, wait);
});
}
const prevPan = cy.pan();
const prevZoom = cy.zoom();
cy.fit();
await asyncWait(150);
const results = (
await html2canvas(container, { logging: false })
).toDataURL();
cy.zoom(prevZoom);
cy.pan(prevPan);
return results;
What do you think about this approach? Also please, call html2canvas
with logging:false
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.
Nice work! It's great that also considers the cues margins in cy.fit()
call.
Of course, there could be lots of improvements such as adding tests, creating separate files for types and utils, performance tests, code style etc... But I think those are different concerns.
Description:
This pull request proposes the addition of a new
pngFull
function enhancing the capabilities of exporting the graph to a PNG image by integrating visual cues.Changes Made:
pngFull
function as a new Cytoscape.js core function.Notes:
ignoreElementClasses
parameter within thepngFull
method.pngFull(options: any, ignoreElementClasses: string[] = [])
Screenshots
Note