score:1
In order to export a SVG, it's essential to have the styles inline. But if you're looking for a workaround for the styles already coming in from an external CSS file, here's an approach to do that.
DEMO IMPLEMENTING EXPORTING OF SVG WITH EXTERNAL CSS STYLING
In the code, the function
named addInlineStyling receives a list of elements and the associated properties, extracts styles/property values using Window.getComputedStyles
method and assigns to the element respectively.
Relevant code:
function addInlineStyling(elements) {
if(elements && elements.length) {
elements.forEach(function(d) {
d3.selectAll(d.el).each(function(){
var element = this;
if(d.properties && d.properties.length) {
d.properties.forEach(function(prop) {
var computedStyle = getComputedStyle(element, null),
value = computedStyle.getPropertyValue(prop);
element.style[prop] = value;
});
}
});
});
}
}
Feel free to modify the way the array is being sent and used to extract styles but I wanted to let you know that this is one approach to doing that. ALTHOUGH IT'S ADVISABLE TO HAVE INLINE STYLING.
And please add the missing styles (if any).
Hope this helps. :)
Source: stackoverflow.com
Related Query
- Export SVG with external CSS to server
- Export leaflet map WITH SVG layer to image
- Error prerendering server of a pie chart with D3.js in svg format
- Positioning svg x/y coordinates with css not working with iOS devices?
- How can I add an external group to an existing svg with d3.js?
- How do I import SVG to Illustrator with CSS without errors?
- Style d3 svg line with css
- Rotate external SVG file with D3.js
- Append multiple external svg in d3 and bind them with data
- d3js - Create a server side SVG with javascript actions
- Why does external css doesnt work on svg elements in IE using D3
- Export SVG with some lines of text in PDF
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- Updating SVG Element Z-Index With D3
- SVG: why does external css override inline style for text?
- How do I show a bootstrap tooltip with an SVG object?
- SVG to PNG Server side - using node.js
- Calculate SVG Path Centroid with D3.js
- How to select a d3 svg path with a particular ID
- (Embed and) Refer to an external SVG via D3 and/or javascript
- Changing number displayed as svg text gradually, with D3 transition
- SVG to Canvas with d3.js
- How to update an svg path with d3.js
- CSS padding property for svg elements
- Appending multiple svg text with d3
- StopPropagation() with SVG element and G
- d3 append an image with svg extension
- Fill SVG element with a repeating linear gradient color
- nvd3.js : unable to bind onClick event with the data points in the svg
- change SVG text to css word wrapping
More Query from same tag
- d3.js, click to link to another URL encoded with variables
- Converting Csv to json in chile/name format
- Change single chord color in chord diagram using D3.js
- How to apply padding between D3 axes and chart?
- D3 x axis value stacked on the left
- How can I append an element after select in d3?
- Optimizing javascript d3 statement
- How to set all descendant nodes and links to same colour as level 2 ancestor?
- d3fc - Add two discontinuityProvider's
- How can I implement 2 x axis in D3 version 4
- d3 autospace overlapping tick labels
- D3 Accessing node attributes inside array
- Simplifying D3js' SVG path generated string
- Color grouped bar chart based on comparison of numbers d3
- d3js: Apply transition on d3js bubble chart
- Uncaught TypeError: .filter is not a function
- D3 Sankey spread functionality
- Apply multiple styles with .style() method in D3.js
- Modify log y-axis scale in dc.js
- D3 data() vs. datum()
- Having trouble making a bar chart bar onClick create changes to scatter chart points using D3
- Recreating collapsible force layout using d3 v4
- Add space above x-caption on D3js multiline chart
- TypeError: Cannot read property 'createElementNS' of undefined
- D3/Raphael js draws 1000+ animated circle with slow fps
- Multi Segments in one segment in a donut chart?
- How to fix the " 'd3' was used before it was defined" error
- Strange Axis Behavior
- Line Graph using D3 is not starting from the date i want it to
- c3js Stacked Bar chart from json array