Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61d1c7b

Browse filesBrowse files
committed
slurp entire SVG, uses DOMParser instead of innerHTML
1 parent a4d3948 commit 61d1c7b
Copy full SHA for 61d1c7b

File tree

Expand file treeCollapse file tree

3 files changed

+43
-28
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+43
-28
lines changed

‎src/components/modebar/modebar.js

Copy file name to clipboardExpand all lines: src/components/modebar/modebar.js
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var isNumeric = require('fast-isnumeric');
1414

1515
var Lib = require('../../lib');
1616
var Icons = require('../../../build/ploticon');
17-
17+
var Parser = new DOMParser();
1818

1919
/**
2020
* UI controller for interactive plots
@@ -192,8 +192,6 @@ proto.createIcon = function(thisIcon) {
192192

193193
if(thisIcon.path) {
194194
icon = document.createElementNS(svgNS, 'svg');
195-
icon.setAttribute('height', '1em');
196-
icon.setAttribute('width', (thisIcon.width / iconHeight) + 'em');
197195
icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));
198196

199197
var path = document.createElementNS(svgNS, 'path');
@@ -215,10 +213,13 @@ proto.createIcon = function(thisIcon) {
215213
}
216214

217215
if(thisIcon.svg) {
218-
icon = document.createElement('div');
219-
icon.innerHTML = '<svg height="1em" width="' + (thisIcon.width / iconHeight) + 'em" viewbox="0, 0, ' + thisIcon.width + ',' + thisIcon.height + '" xmlns="">' + thisIcon.svg + '</svg>';
216+
var svgDoc = Parser.parseFromString(thisIcon.svg, 'application/xml');
217+
icon = svgDoc.childNodes[0];
220218
}
221219

220+
icon.setAttribute('height', '1em');
221+
icon.setAttribute('width', '1em');
222+
222223
return icon;
223224
};
224225

‎src/fonts/ploticon/ploticon.svg

Copy file name to clipboardExpand all lines: src/fonts/ploticon/ploticon.svg
+31-13Lines changed: 31 additions & 13 deletions
Loading

‎tasks/util/pull_font_svg.js

Copy file name to clipboardExpand all lines: tasks/util/pull_font_svg.js
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs');
22
var xml2js = require('xml2js');
33

44
var parser = new xml2js.Parser();
5-
var builder = new xml2js.Builder({ headless: true, rootName: 'g', renderOpts: {'newline': ''}});
5+
var builder = new xml2js.Builder({ headless: true, rootName: 'svg', renderOpts: {'newline': ''}});
66

77
module.exports = function pullFontSVG(data, pathOut) {
88
parser.parseString(data, function(err, result) {
@@ -29,17 +29,13 @@ module.exports = function pullFontSVG(data, pathOut) {
2929
});
3030

3131
// Load SVG
32-
var svgs = result.svg.defs[0].g;
33-
svgs.forEach(function(g) {
34-
var name = g.$.id,
35-
width = parseFloat(g.$['data-width']),
36-
height = parseFloat(g.$['data-height']);
37-
delete g.$;
32+
var svgs = result.svg.defs[0].svg;
33+
svgs.forEach(function(svg) {
34+
var name = svg.$.id;
35+
delete svg.$.id;
3836
chars[name] = {
3937
name: name,
40-
width: width,
41-
height: height,
42-
svg: builder.buildObject(g)
38+
svg: builder.buildObject(svg)
4339
};
4440
});
4541

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.