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

Add pngFull function to Cytoscape.js Core with Visual Cues Enhancement #15

Merged
merged 12 commits into from
Jan 23, 2024
Merged
4 changes: 3 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ jobs:
chrome-headless:
runs-on: ubuntu-latest
# https://github.com/cypress-io/cypress-docker-images
container: cypress/browsers:node12.18.3-chrome87-ff82
container: cypress/browsers
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Dependencies
run: npm install
- name: Headless Chrome
uses: cypress-io/github-action@v2
timeout-minutes: 10
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://user-images.githubusercontent.com/8426741/151511191-82ee64b9-3709-4cef-a

## API

Adds `setActiveCueInstance` and `getActiveInstanceId` to the **cytoscape core** methods.
Adds `setActiveCueInstance` , `getActiveInstanceId`, and `pngFull` to the **cytoscape core** methods.

#### `cy.setActiveCueInstance(id: number)`

Expand All @@ -26,6 +26,10 @@ Adds `setActiveCueInstance` and `getActiveInstanceId` to the **cytoscape core**

- Gets the active cue instace id.

#### `cy.pngFull(options: any, ignoreElementClasses: string[]): string`

- Gets a base64 encoded PNG of the graph including the cues.

Adds `addCue`, `removeCue`, `updateCue`, `getCueData`, `showCue`, `hideCue` to the **cytoscape collection** methods.

#### `ele.addCue(cueOptions: CueOptions): boolean[]`
Expand Down
2 changes: 2 additions & 0 deletions demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 (whole)</a></li>
<li><a class="dropdown-item" href="#" onclick="exportJson()">JSON</a></li>
<li><a class="dropdown-item" href="#" onclick="exportGraphml()">GraphML</a></li>
<li><a class="dropdown-item" href="#" onclick="exportSif()">SIF</a></li>
Expand Down
39 changes: 39 additions & 0 deletions demo/file-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,45 @@ function exportJson() {
str2file(JSON.stringify(elements, undefined, 4), 'sample-graph.json');
}

function exportPng() {
const options = { bg: 'white', scale: 3, full: false };
let base64png;
base64png = cy.pngFull(options);
base64png.then((result) => {
fetch(result)
.then(res => res.blob())
.then(x => {
const anchor = document.createElement('a');
anchor.download = 'sample.png';
anchor.href = (window.URL).createObjectURL(x);
anchor.click();
return x;
})
}).catch((error) => {
console.error(error); // Handle errors
});
}

function exportPngAll() {
const options = { bg: 'white', scale: 3, full: true };
let base64png;
base64png = cy.pngFull(options);
base64png.then((result) => {
fetch(result)
.then(res => res.blob())
.then(x => {
const anchor = document.createElement('a');
anchor.download = 'sample.png';
anchor.href = (window.URL).createObjectURL(x);
anchor.click();
return x;
})
}).catch((error) => {
console.error(error); // Handle errors
});
}


function exportGraphml() {
str2file(cy.graphml(), 'sample-graph.graphml');
}
Expand Down
Loading
Loading