diff options
Diffstat (limited to 'spec/helpers.js')
-rw-r--r-- | spec/helpers.js | 225 |
1 files changed, 126 insertions, 99 deletions
diff --git a/spec/helpers.js b/spec/helpers.js index 7d63dfa..b5b29c3 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -1,7 +1,7 @@ import { getWindow } from '../src/utils/window.js' import { svg } from '../src/modules/core/namespaces.js' -function tag (name, attrs, children) { +function tag(name, attrs, children) { const doc = getWindow().document const el = doc.createElementNS(svg, name) let i @@ -11,7 +11,9 @@ function tag (name, attrs, children) { } for (i in children) { - if (typeof children[i] === 'string') { children[i] = doc.createTextNode(children[i]) } + if (typeof children[i] === 'string') { + children[i] = doc.createTextNode(children[i]) + } el.appendChild(children[i]) } @@ -19,104 +21,128 @@ function tag (name, attrs, children) { 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' }) +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('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('desc', {}, ['Some description']), + tag('path', { + id: 'lineAB', + d: 'M 100 350 l 150 -300', + stroke: 'red', + 'stroke-width': '3', + fill: 'none' }), - tag('circle', { - id: 'pointB', - cx: '250', - cy: '50', - r: '50' + tag('path', { + id: 'lineBC', + d: 'M 250 50 l 150 300', + stroke: 'red', + 'stroke-width': '3', + fill: 'none' }), - 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' }) - ]) + 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 () { +export function buildFixtures() { const doc = getWindow().document const body = doc.body || doc.documentElement @@ -134,7 +160,7 @@ export function buildFixtures () { body.appendChild(div) } -export function buildCanvas () { +export function buildCanvas() { const doc = getWindow().document const body = doc.body || doc.documentElement @@ -150,7 +176,7 @@ export function buildCanvas () { body.appendChild(div) } -export function clear () { +export function clear() { const doc = getWindow().document const canvas = doc.getElementById('canvas') const fixtures = doc.getElementById('fixtures') @@ -158,6 +184,7 @@ export function clear () { // remove if present fixtures && fixtures.parentNode.removeChild(fixtures) canvas.parentNode.removeChild(canvas) - - ;[ ...doc.querySelectorAll('svg') ].forEach((el) => el.parentNode.removeChild(el)) + ;[...doc.querySelectorAll('svg')].forEach((el) => + el.parentNode.removeChild(el) + ) } |