diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 21:19:14 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-09 21:19:14 +1000 |
commit | 02cbd2998c3c36b88701ce83089df8947be1de9f (patch) | |
tree | 668e6cf5db5bfbdb37a774363757970c4cb655b0 /src | |
parent | 25461a4733d7dcfc6f8127e8419f5eddbbb4b4aa (diff) | |
download | svg.js-02cbd2998c3c36b88701ce83089df8947be1de9f.tar.gz svg.js-02cbd2998c3c36b88701ce83089df8947be1de9f.zip |
added test for Gradient
Diffstat (limited to 'src')
-rw-r--r-- | src/elements/Gradient.js | 42 | ||||
-rw-r--r-- | src/elements/Stop.js | 10 | ||||
-rw-r--r-- | src/main.js | 1 |
3 files changed, 29 insertions, 24 deletions
diff --git a/src/elements/Gradient.js b/src/elements/Gradient.js index d5ae8b7..4e09cbd 100644 --- a/src/elements/Gradient.js +++ b/src/elements/Gradient.js @@ -7,7 +7,6 @@ import { import { registerMethods } from '../utils/methods.js' import Box from '../types/Box.js' import Container from './Container.js' -import Stop from './Stop.js' import baseFind from '../modules/core/selector.js' import * as gradiented from '../modules/core/gradiented.js' @@ -19,9 +18,23 @@ export default class Gradient extends Container { ) } - // Add a color stop - stop (offset, color, opacity) { - return this.put(new Stop()).update(offset, color, opacity) + // custom attr to handle transform + attr (a, b, c) { + if (a === 'transform') a = 'gradientTransform' + return super.attr(a, b, c) + } + + bbox () { + return new Box() + } + + targets () { + return baseFind('svg [fill*="' + this.id() + '"]') + } + + // Alias string conversion to fill + toString () { + return this.url() } // Update gradient @@ -39,26 +52,7 @@ export default class Gradient extends Container { // Return the fill id url () { - return 'url(#' + this.id() + ')' - } - - // Alias string convertion to fill - toString () { - return this.url() - } - - // custom attr to handle transform - attr (a, b, c) { - if (a === 'transform') a = 'gradientTransform' - return super.attr(a, b, c) - } - - targets () { - return baseFind('svg [fill*="' + this.id() + '"]') - } - - bbox () { - return new Box() + return 'url("#' + this.id() + '")' } } diff --git a/src/elements/Stop.js b/src/elements/Stop.js index d258b86..d29090c 100644 --- a/src/elements/Stop.js +++ b/src/elements/Stop.js @@ -1,6 +1,7 @@ import { nodeOrNew, register } from '../utils/adopter.js' import Element from './Element.js' import SVGNumber from '../types/SVGNumber.js' +import { registerMethods } from '../utils/methods.js' export default class Stop extends Element { constructor (node, attrs = node) { @@ -26,4 +27,13 @@ export default class Stop extends Element { } } +registerMethods({ + Gradient: { + // Add a color stop + stop: function (offset, color, opacity) { + return this.put(new Stop()).update(offset, color, opacity) + } + } +}) + register(Stop, 'Stop') diff --git a/src/main.js b/src/main.js index a8da19f..f95ccf5 100644 --- a/src/main.js +++ b/src/main.js @@ -156,6 +156,7 @@ extend(Dom, getMethodsFor('Dom')) extend(Element, getMethodsFor('Element')) extend(Shape, getMethodsFor('Shape')) extend([ Container, Fragment ], getMethodsFor('Container')) +extend(Gradient, getMethodsFor('Gradient')) extend(Runner, getMethodsFor('Runner')) |