Comments (5)
SVG reproduction when using CSS classes / variables will require some extra processing to fully reproduce visual.
from layerchart.
Mike Bostock's examples of serialize()
and rasterize()
for SVG look straight forward (using document.createTreeWalker()
.
Likely how Download SVG
and Download PNG
are implemented (or at least the basics).
see also: https://talk.observablehq.com/t/svg-to-png/6957
from layerchart.
See discussion for approach with SVG
function downloadSVG() {
const svgEl = document.querySelector('.layercake-layout-svg');
if (svgEl) {
svgEl?.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svgEl.querySelector('.svg_text')?.classList.remove('hidden');
const svgString = new XMLSerializer().serializeToString(svgEl);
const a = document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([svgString]));
a.download = 'download.svg';
a.click();
a.remove();
svgEl?.removeAttribute('xmlns');
svgEl.querySelector('.svg_text')?.classList.add('hidden');
}
};
from layerchart.
See discussion for approach with Canvas
function downloadPNG() {
const canvas = document.querySelector('.layercake-layout-canvas') as HTMLCanvasElement;
const ctx = canvas.getContext('2d');
const dataUrl = ctx?.canvas.toDataURL('image/png', 1);
const a = document.createElement('a');
a.href = dataUrl;
a.download = 'download.png';
a.click();
a.remove();
};
from layerchart.
save as svg and png looks good to me...
from layerchart.
Related Issues (20)
- Chart improvements HOT 3
- [TransformContext] Improve `translateOnScale`
- Expose `on:tick` from `ForceSimulation` to allow for dynamic simulation tuning HOT 1
- `ForceSimulation` keeps redundantly re-initializing all forces any time any of their parameters change HOT 1
- `ForceSimulation` does not update its `alpha` prop based on the internal d3 simulation
- `ForceSimulation`'s `cloneData` should probably be `export const`
- `ForceSimulation` keeps redundantly re-initializing all forces any time any other (non-force) props change
- `ForceSimulation` never evicts obsolete forces HOT 1
- Handle svelte-check warnings HOT 1
- [Tooltip] A11y and interaction improvements HOT 1
- Simplified Chart components HOT 2
- Combo Line/Bar HOT 3
- [Tooltip] Improve structure and default styles HOT 1
- Add serialization notice to View data dialog
- Cloudflare Worker size limit
- @tailwindcss/forms compatibility (and possibly Skeleton) HOT 1
- Setting the width of bar chart bars HOT 1
- [Canvas] Support for data marks
- Support Tailwind prefixed classes HOT 1
- Hover Display Not Aligning with Mouse Position HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from layerchart.