diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-30 13:19:58 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-30 13:19:58 +0100 |
commit | f4531868a190af69c4ecdcf6d7be6d3fc59f5d46 (patch) | |
tree | 1fc76780ad6918ef7b6eb0e302a55f1b043d8bc5 /spec/helpers.js | |
parent | d64b964d21e1399b198e44555be68a12378053e7 (diff) | |
parent | efc82b0eafa72902b35c2b22cd9e86bdbdd3edfb (diff) | |
download | svg.js-f4531868a190af69c4ecdcf6d7be6d3fc59f5d46.tar.gz svg.js-f4531868a190af69c4ecdcf6d7be6d3fc59f5d46.zip |
Merge branch '3.0.0' into 790-color-spaces
Diffstat (limited to 'spec/helpers.js')
-rw-r--r-- | spec/helpers.js | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/spec/helpers.js b/spec/helpers.js new file mode 100644 index 0000000..a584b6a --- /dev/null +++ b/spec/helpers.js @@ -0,0 +1,160 @@ +import { getWindow } from '../src/utils/window.js' + +function tag(name, attrs, children) { + let doc = getWindow().document + var el = doc.createElement(name) + + for(var i in attrs){ + el.setAttribute(i, attrs[i]) + } + + for(var i in children){ + if(typeof children[i] == 'string') + children[i] = doc.createTextNode(children[i]) + + el.appendChild(children[i]) + } + + return el +} + +export function fixtures () { + return tag('svg', { + height:0, + width:0, + id:'inlineSVG' + },[ + tag('defs', {}, [ + tag('linearGradient', {}, [ + tag('stop', {offset: '5%', 'stop-color': 'green'}), + tag('stop', {offset: '95%', 'stop-color': 'gold'}), + ]), + tag('radialGradient', {}, [ + tag('stop', {offset: '5%', 'stop-color': 'green'}), + tag('stop', {offset: '95%', 'stop-color': 'gold'}), + ]) + ]), + tag('desc', {}, ['Some description']), + tag('path', { + id: 'lineAB', + d: 'M 100 350 l 150 -300', + stroke: 'red', + 'stroke-width': '3', + fill: 'none' + }), + tag('path', { + id: 'lineBC', + d: 'M 250 50 l 150 300', + stroke: 'red', + 'stroke-width': '3', + fill: 'none' + }), + tag('path', { + d: 'M 175 200 l 150 0', + stroke: 'green', + 'stroke-width': '3', + fill: 'none' + }), + tag('path', { + d: 'M 100 350 q 150 -300 300 0', + stroke: 'blue', + 'stroke-width': '5', + fill: 'none' + }), + tag('g', { + stroke: 'black', + 'stroke-width': '2', + fill: 'black', + id: 'pointGroup' + },[ + tag('circle', { + id: 'pointA', + cx: '100', + cy: '350', + r: '3', + }), + tag('circle', { + id: 'pointB', + cx: '250', + cy: '50', + r: '50', + }), + tag('circle', { + id: 'pointC', + cx: '400', + cy: '350', + r: '50', + }) + ]), + tag('g', { + 'font-size': '30', + font: 'sans-serif', + fill: 'black', + stroke: 'none', + 'text-anchor': 'middle', + id: 'labelGroup' + },[ + tag('text', { + x: '100', + y: '350', + dy: '-30', + }, ['A']), + tag('text', { + x: '250', + y: '50', + dy: '-10', + }, ['B']), + tag('text', { + x: '400', + y: '350', + dx: '30', + }, ['C']) + ]), + tag('polygon', {points: '200,10 250,190 160,210'}), + tag('polyline', {points: '20,20 40,25 60,40 80,120 120,140 200,180'}) + ]) +} + +export function buildFixtures () { + let doc = getWindow().document + let body = doc.body || doc.documentElement + + let div = doc.createElement('div') + div.id = 'fixtures' + + try { + // FIXME: doesnt work in svgdom + div.style.position = 'absolute' + div.style.top = 0 + div.style.left = 0 + } catch (e) {} + + div.appendChild(fixtures()) + body.appendChild(div) +} + +export function buildCanvas () { + let doc = getWindow().document + let body = doc.body || doc.documentElement + + let div = doc.createElement('div') + div.id = 'canvas' + + try { + // FIXME: doesnt work in svgdom + div.style.position = 'absolute' + div.style.top = 0 + div.style.left = 0 + } catch (e) {} + body.appendChild(div) +} + +export function clear () { + let doc = getWindow().document + let canvas = doc.getElementById('canvas') + let fixtures = doc.getElementById('fixtures') + + // remove if present + fixtures && fixtures.parentNode.removeChild(fixtures) + canvas.parentNode.removeChild(canvas) +} |