pattern-fill.src.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  3. *
  4. * Module for adding patterns and images as point fills.
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Hønsi, Øystein Moseng
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/pattern-fill', ['highcharts'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'Extensions/PatternFill.js', [_modules['Core/Globals.js'], _modules['Core/Series/Point.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js']], function (H, Point, SVGRenderer, U) {
  33. /* *
  34. *
  35. * Module for using patterns or images as point fills.
  36. *
  37. * (c) 2010-2020 Highsoft AS
  38. * Author: Torstein Hønsi, Øystein Moseng
  39. *
  40. * License: www.highcharts.com/license
  41. *
  42. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  43. *
  44. * */
  45. var addEvent = U.addEvent,
  46. animObject = U.animObject,
  47. erase = U.erase,
  48. getOptions = U.getOptions,
  49. merge = U.merge,
  50. pick = U.pick,
  51. removeEvent = U.removeEvent,
  52. wrap = U.wrap;
  53. /**
  54. * Pattern options
  55. *
  56. * @interface Highcharts.PatternOptionsObject
  57. */ /**
  58. * Background color for the pattern if a `path` is set (not images).
  59. * @name Highcharts.PatternOptionsObject#backgroundColor
  60. * @type {Highcharts.ColorString}
  61. */ /**
  62. * URL to an image to use as the pattern.
  63. * @name Highcharts.PatternOptionsObject#image
  64. * @type {string}
  65. */ /**
  66. * Width of the pattern. For images this is automatically set to the width of
  67. * the element bounding box if not supplied. For non-image patterns the default
  68. * is 32px. Note that automatic resizing of image patterns to fill a bounding
  69. * box dynamically is only supported for patterns with an automatically
  70. * calculated ID.
  71. * @name Highcharts.PatternOptionsObject#width
  72. * @type {number}
  73. */ /**
  74. * Analogous to pattern.width.
  75. * @name Highcharts.PatternOptionsObject#height
  76. * @type {number}
  77. */ /**
  78. * For automatically calculated width and height on images, it is possible to
  79. * set an aspect ratio. The image will be zoomed to fill the bounding box,
  80. * maintaining the aspect ratio defined.
  81. * @name Highcharts.PatternOptionsObject#aspectRatio
  82. * @type {number}
  83. */ /**
  84. * Horizontal offset of the pattern. Defaults to 0.
  85. * @name Highcharts.PatternOptionsObject#x
  86. * @type {number|undefined}
  87. */ /**
  88. * Vertical offset of the pattern. Defaults to 0.
  89. * @name Highcharts.PatternOptionsObject#y
  90. * @type {number|undefined}
  91. */ /**
  92. * Either an SVG path as string, or an object. As an object, supply the path
  93. * string in the `path.d` property. Other supported properties are standard SVG
  94. * attributes like `path.stroke` and `path.fill`. If a path is supplied for the
  95. * pattern, the `image` property is ignored.
  96. * @name Highcharts.PatternOptionsObject#path
  97. * @type {string|Highcharts.SVGAttributes}
  98. */ /**
  99. * SVG `patternTransform` to apply to the entire pattern.
  100. * @name Highcharts.PatternOptionsObject#patternTransform
  101. * @type {string}
  102. * @see [patternTransform demo](https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/series/pattern-fill-transform)
  103. */ /**
  104. * Pattern color, used as default path stroke.
  105. * @name Highcharts.PatternOptionsObject#color
  106. * @type {Highcharts.ColorString}
  107. */ /**
  108. * Opacity of the pattern as a float value from 0 to 1.
  109. * @name Highcharts.PatternOptionsObject#opacity
  110. * @type {number}
  111. */ /**
  112. * ID to assign to the pattern. This is automatically computed if not added, and
  113. * identical patterns are reused. To refer to an existing pattern for a
  114. * Highcharts color, use `color: "url(#pattern-id)"`.
  115. * @name Highcharts.PatternOptionsObject#id
  116. * @type {string|undefined}
  117. */
  118. /**
  119. * Holds a pattern definition.
  120. *
  121. * @sample highcharts/series/pattern-fill-area/
  122. * Define a custom path pattern
  123. * @sample highcharts/series/pattern-fill-pie/
  124. * Default patterns and a custom image pattern
  125. * @sample maps/demo/pattern-fill-map/
  126. * Custom images on map
  127. *
  128. * @example
  129. * // Pattern used as a color option
  130. * color: {
  131. * pattern: {
  132. * path: {
  133. * d: 'M 3 3 L 8 3 L 8 8 Z',
  134. * fill: '#102045'
  135. * },
  136. * width: 12,
  137. * height: 12,
  138. * color: '#907000',
  139. * opacity: 0.5
  140. * }
  141. * }
  142. *
  143. * @interface Highcharts.PatternObject
  144. */ /**
  145. * Pattern options
  146. * @name Highcharts.PatternObject#pattern
  147. * @type {Highcharts.PatternOptionsObject}
  148. */ /**
  149. * Animation options for the image pattern loading.
  150. * @name Highcharts.PatternObject#animation
  151. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>|undefined}
  152. */ /**
  153. * Optionally an index referencing which pattern to use. Highcharts adds
  154. * 10 default patterns to the `Highcharts.patterns` array. Additional
  155. * pattern definitions can be pushed to this array if desired. This option
  156. * is an index into this array.
  157. * @name Highcharts.PatternObject#patternIndex
  158. * @type {number|undefined}
  159. */
  160. ''; // detach doclets above
  161. // Add the predefined patterns
  162. H.patterns = (function () {
  163. var patterns = [],
  164. colors = getOptions().colors;
  165. [
  166. 'M 0 0 L 10 10 M 9 -1 L 11 1 M -1 9 L 1 11',
  167. 'M 0 10 L 10 0 M -1 1 L 1 -1 M 9 11 L 11 9',
  168. 'M 3 0 L 3 10 M 8 0 L 8 10',
  169. 'M 0 3 L 10 3 M 0 8 L 10 8',
  170. 'M 0 3 L 5 3 L 5 0 M 5 10 L 5 7 L 10 7',
  171. 'M 3 3 L 8 3 L 8 8 L 3 8 Z',
  172. 'M 5 5 m -4 0 a 4 4 0 1 1 8 0 a 4 4 0 1 1 -8 0',
  173. 'M 10 3 L 5 3 L 5 0 M 5 10 L 5 7 L 0 7',
  174. 'M 2 5 L 5 2 L 8 5 L 5 8 Z',
  175. 'M 0 0 L 5 10 L 10 0'
  176. ].forEach(function (pattern, i) {
  177. patterns.push({
  178. path: pattern,
  179. color: colors[i],
  180. width: 10,
  181. height: 10
  182. });
  183. });
  184. return patterns;
  185. })();
  186. /**
  187. * Utility function to compute a hash value from an object. Modified Java
  188. * String.hashCode implementation in JS. Use the preSeed parameter to add an
  189. * additional seeding step.
  190. *
  191. * @private
  192. * @function hashFromObject
  193. *
  194. * @param {object} obj
  195. * The javascript object to compute the hash from.
  196. *
  197. * @param {boolean} [preSeed=false]
  198. * Add an optional preSeed stage.
  199. *
  200. * @return {string}
  201. * The computed hash.
  202. */
  203. function hashFromObject(obj, preSeed) {
  204. var str = JSON.stringify(obj),
  205. strLen = str.length || 0,
  206. hash = 0,
  207. i = 0,
  208. char,
  209. seedStep;
  210. if (preSeed) {
  211. seedStep = Math.max(Math.floor(strLen / 500), 1);
  212. for (var a = 0; a < strLen; a += seedStep) {
  213. hash += str.charCodeAt(a);
  214. }
  215. hash = hash & hash;
  216. }
  217. for (; i < strLen; ++i) {
  218. char = str.charCodeAt(i);
  219. hash = ((hash << 5) - hash) + char;
  220. hash = hash & hash;
  221. }
  222. return hash.toString(16).replace('-', '1');
  223. }
  224. /**
  225. * Set dimensions on pattern from point. This function will set internal
  226. * pattern._width/_height properties if width and height are not both already
  227. * set. We only do this on image patterns. The _width/_height properties are set
  228. * to the size of the bounding box of the point, optionally taking aspect ratio
  229. * into account. If only one of width or height are supplied as options, the
  230. * undefined option is calculated as above.
  231. *
  232. * @private
  233. * @function Highcharts.Point#calculatePatternDimensions
  234. *
  235. * @param {Highcharts.PatternOptionsObject} pattern
  236. * The pattern to set dimensions on.
  237. *
  238. * @return {void}
  239. *
  240. * @requires modules/pattern-fill
  241. */
  242. Point.prototype.calculatePatternDimensions = function (pattern) {
  243. if (pattern.width && pattern.height) {
  244. return;
  245. }
  246. var bBox = this.graphic && (this.graphic.getBBox &&
  247. this.graphic.getBBox(true) ||
  248. this.graphic.element &&
  249. this.graphic.element.getBBox()) || {},
  250. shapeArgs = this.shapeArgs;
  251. // Prefer using shapeArgs, as it is animation agnostic
  252. if (shapeArgs) {
  253. bBox.width = shapeArgs.width || bBox.width;
  254. bBox.height = shapeArgs.height || bBox.height;
  255. bBox.x = shapeArgs.x || bBox.x;
  256. bBox.y = shapeArgs.y || bBox.y;
  257. }
  258. // For images we stretch to bounding box
  259. if (pattern.image) {
  260. // If we do not have a bounding box at this point, simply add a defer
  261. // key and pick this up in the fillSetter handler, where the bounding
  262. // box should exist.
  263. if (!bBox.width || !bBox.height) {
  264. pattern._width = 'defer';
  265. pattern._height = 'defer';
  266. return;
  267. }
  268. // Handle aspect ratio filling
  269. if (pattern.aspectRatio) {
  270. bBox.aspectRatio = bBox.width / bBox.height;
  271. if (pattern.aspectRatio > bBox.aspectRatio) {
  272. // Height of bBox will determine width
  273. bBox.aspectWidth = bBox.height * pattern.aspectRatio;
  274. }
  275. else {
  276. // Width of bBox will determine height
  277. bBox.aspectHeight = bBox.width / pattern.aspectRatio;
  278. }
  279. }
  280. // We set the width/height on internal properties to differentiate
  281. // between the options set by a user and by this function.
  282. pattern._width = pattern.width ||
  283. Math.ceil(bBox.aspectWidth || bBox.width);
  284. pattern._height = pattern.height ||
  285. Math.ceil(bBox.aspectHeight || bBox.height);
  286. }
  287. // Set x/y accordingly, centering if using aspect ratio, otherwise adjusting
  288. // so bounding box corner is 0,0 of pattern.
  289. if (!pattern.width) {
  290. pattern._x = pattern.x || 0;
  291. pattern._x += bBox.x - Math.round(bBox.aspectWidth ?
  292. Math.abs(bBox.aspectWidth - bBox.width) / 2 :
  293. 0);
  294. }
  295. if (!pattern.height) {
  296. pattern._y = pattern.y || 0;
  297. pattern._y += bBox.y - Math.round(bBox.aspectHeight ?
  298. Math.abs(bBox.aspectHeight - bBox.height) / 2 :
  299. 0);
  300. }
  301. };
  302. /* eslint-disable no-invalid-this */
  303. /**
  304. * Add a pattern to the renderer.
  305. *
  306. * @private
  307. * @function Highcharts.SVGRenderer#addPattern
  308. *
  309. * @param {Highcharts.PatternObject} options
  310. * The pattern options.
  311. *
  312. * @param {boolean|Partial<Highcharts.AnimationOptionsObject>} [animation]
  313. * The animation options.
  314. *
  315. * @return {Highcharts.SVGElement|undefined}
  316. * The added pattern. Undefined if the pattern already exists.
  317. *
  318. * @requires modules/pattern-fill
  319. */
  320. SVGRenderer.prototype.addPattern = function (options, animation) {
  321. var pattern,
  322. animate = pick(animation,
  323. true),
  324. animationOptions = animObject(animate),
  325. path,
  326. defaultSize = 32,
  327. width = options.width || options._width || defaultSize,
  328. height = (options.height || options._height || defaultSize),
  329. color = options.color || '#343434',
  330. id = options.id,
  331. ren = this,
  332. rect = function (fill) {
  333. ren.rect(0, 0,
  334. width,
  335. height)
  336. .attr({ fill: fill })
  337. .add(pattern);
  338. }, attribs;
  339. if (!id) {
  340. this.idCounter = this.idCounter || 0;
  341. id = 'highcharts-pattern-' + this.idCounter + '-' + (this.chartIndex || 0);
  342. ++this.idCounter;
  343. }
  344. if (this.forExport) {
  345. id += '-export';
  346. }
  347. // Do nothing if ID already exists
  348. this.defIds = this.defIds || [];
  349. if (this.defIds.indexOf(id) > -1) {
  350. return;
  351. }
  352. // Store ID in list to avoid duplicates
  353. this.defIds.push(id);
  354. // Calculate pattern element attributes
  355. var attrs = {
  356. id: id,
  357. patternUnits: 'userSpaceOnUse',
  358. patternContentUnits: options.patternContentUnits || 'userSpaceOnUse',
  359. width: width,
  360. height: height,
  361. x: options._x || options.x || 0,
  362. y: options._y || options.y || 0
  363. };
  364. if (options.patternTransform) {
  365. attrs.patternTransform = options.patternTransform;
  366. }
  367. pattern = this.createElement('pattern').attr(attrs).add(this.defs);
  368. // Set id on the SVGRenderer object
  369. pattern.id = id;
  370. // Use an SVG path for the pattern
  371. if (options.path) {
  372. path = options.path;
  373. // The background
  374. if (options.backgroundColor) {
  375. rect(options.backgroundColor);
  376. }
  377. // The pattern
  378. attribs = {
  379. 'd': path.d || path
  380. };
  381. if (!this.styledMode) {
  382. attribs.stroke = path.stroke || color;
  383. attribs['stroke-width'] = pick(path.strokeWidth, 2);
  384. attribs.fill = path.fill || 'none';
  385. }
  386. if (path.transform) {
  387. attribs.transform = path.transform;
  388. }
  389. this.createElement('path').attr(attribs).add(pattern);
  390. pattern.color = color;
  391. // Image pattern
  392. }
  393. else if (options.image) {
  394. if (animate) {
  395. this.image(options.image, 0, 0, width, height, function () {
  396. // Onload
  397. this.animate({
  398. opacity: pick(options.opacity, 1)
  399. }, animationOptions);
  400. removeEvent(this.element, 'load');
  401. }).attr({ opacity: 0 }).add(pattern);
  402. }
  403. else {
  404. this.image(options.image, 0, 0, width, height).add(pattern);
  405. }
  406. }
  407. // For non-animated patterns, set opacity now
  408. if (!(options.image && animate) && typeof options.opacity !== 'undefined') {
  409. [].forEach.call(pattern.element.childNodes, function (child) {
  410. child.setAttribute('opacity', options.opacity);
  411. });
  412. }
  413. // Store for future reference
  414. this.patternElements = this.patternElements || {};
  415. this.patternElements[id] = pattern;
  416. return pattern;
  417. };
  418. // Make sure we have a series color
  419. wrap(H.Series.prototype, 'getColor', function (proceed) {
  420. var oldColor = this.options.color;
  421. // Temporarely remove color options to get defaults
  422. if (oldColor &&
  423. oldColor.pattern &&
  424. !oldColor.pattern.color) {
  425. delete this.options.color;
  426. // Get default
  427. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  428. // Replace with old, but add default color
  429. oldColor.pattern.color =
  430. this.color;
  431. this.color = this.options.color = oldColor;
  432. }
  433. else {
  434. // We have a color, no need to do anything special
  435. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  436. }
  437. });
  438. // Calculate pattern dimensions on points that have their own pattern.
  439. addEvent(H.Series, 'render', function () {
  440. var isResizing = this.chart.isResizing;
  441. if (this.isDirtyData || isResizing || !this.chart.hasRendered) {
  442. (this.points || []).forEach(function (point) {
  443. var colorOptions = point.options && point.options.color;
  444. if (colorOptions &&
  445. colorOptions.pattern) {
  446. // For most points we want to recalculate the dimensions on
  447. // render, where we have the shape args and bbox. But if we
  448. // are resizing and don't have the shape args, defer it, since
  449. // the bounding box is still not resized.
  450. if (isResizing &&
  451. !(point.shapeArgs &&
  452. point.shapeArgs.width &&
  453. point.shapeArgs.height)) {
  454. colorOptions.pattern._width =
  455. 'defer';
  456. colorOptions.pattern._height =
  457. 'defer';
  458. }
  459. else {
  460. point.calculatePatternDimensions(colorOptions.pattern);
  461. }
  462. }
  463. });
  464. }
  465. });
  466. // Merge series color options to points
  467. addEvent(Point, 'afterInit', function () {
  468. var point = this,
  469. colorOptions = point.options.color;
  470. // Only do this if we have defined a specific color on this point. Otherwise
  471. // we will end up trying to re-add the series color for each point.
  472. if (colorOptions && colorOptions.pattern) {
  473. // Move path definition to object, allows for merge with series path
  474. // definition
  475. if (typeof colorOptions.pattern.path === 'string') {
  476. colorOptions.pattern.path = {
  477. d: colorOptions.pattern.path
  478. };
  479. }
  480. // Merge with series options
  481. point.color = point.options.color = merge(point.series.options.color, colorOptions);
  482. }
  483. });
  484. // Add functionality to SVG renderer to handle patterns as complex colors
  485. addEvent(SVGRenderer, 'complexColor', function (args) {
  486. var color = args.args[0],
  487. prop = args.args[1],
  488. element = args.args[2],
  489. chartIndex = (this.chartIndex || 0);
  490. var pattern = color.pattern,
  491. value = '#343434';
  492. // Handle patternIndex
  493. if (typeof color.patternIndex !== 'undefined' && H.patterns) {
  494. pattern = H.patterns[color.patternIndex];
  495. }
  496. // Skip and call default if there is no pattern
  497. if (!pattern) {
  498. return true;
  499. }
  500. // We have a pattern.
  501. if (pattern.image ||
  502. typeof pattern.path === 'string' ||
  503. pattern.path && pattern.path.d) {
  504. // Real pattern. Add it and set the color value to be a reference.
  505. // Force Hash-based IDs for legend items, as they are drawn before
  506. // point render, meaning they are drawn before autocalculated image
  507. // width/heights. We don't want them to highjack the width/height for
  508. // this ID if it is defined by users.
  509. var forceHashId = element.parentNode &&
  510. element.parentNode.getAttribute('class');
  511. forceHashId = forceHashId &&
  512. forceHashId.indexOf('highcharts-legend') > -1;
  513. // If we don't have a width/height yet, handle it. Try faking a point
  514. // and running the algorithm again.
  515. if (pattern._width === 'defer' || pattern._height === 'defer') {
  516. Point.prototype.calculatePatternDimensions.call({ graphic: { element: element } }, pattern);
  517. }
  518. // If we don't have an explicit ID, compute a hash from the
  519. // definition and use that as the ID. This ensures that points with
  520. // the same pattern definition reuse existing pattern elements by
  521. // default. We combine two hashes, the second with an additional
  522. // preSeed algorithm, to minimize collision probability.
  523. if (forceHashId || !pattern.id) {
  524. // Make a copy so we don't accidentally edit options when setting ID
  525. pattern = merge({}, pattern);
  526. pattern.id = 'highcharts-pattern-' + chartIndex + '-' +
  527. hashFromObject(pattern) + hashFromObject(pattern, true);
  528. }
  529. // Add it. This function does nothing if an element with this ID
  530. // already exists.
  531. this.addPattern(pattern, !this.forExport && pick(pattern.animation, this.globalAnimation, { duration: 100 }));
  532. value = "url(" + this.url + "#" + (pattern.id + (this.forExport ? '-export' : '')) + ")";
  533. }
  534. else {
  535. // Not a full pattern definition, just add color
  536. value = pattern.color || value;
  537. }
  538. // Set the fill/stroke prop on the element
  539. element.setAttribute(prop, value);
  540. // Allow the color to be concatenated into tooltips formatters etc.
  541. color.toString = function () {
  542. return value;
  543. };
  544. // Skip default handler
  545. return false;
  546. });
  547. // When animation is used, we have to recalculate pattern dimensions after
  548. // resize, as the bounding boxes are not available until then.
  549. addEvent(H.Chart, 'endResize', function () {
  550. if ((this.renderer && this.renderer.defIds || []).filter(function (id) {
  551. return (id &&
  552. id.indexOf &&
  553. id.indexOf('highcharts-pattern-') === 0);
  554. }).length) {
  555. // We have non-default patterns to fix. Find them by looping through
  556. // all points.
  557. this.series.forEach(function (series) {
  558. series.points.forEach(function (point) {
  559. var colorOptions = point.options && point.options.color;
  560. if (colorOptions &&
  561. colorOptions.pattern) {
  562. colorOptions.pattern._width =
  563. 'defer';
  564. colorOptions.pattern._height =
  565. 'defer';
  566. }
  567. });
  568. });
  569. // Redraw without animation
  570. this.redraw(false);
  571. }
  572. });
  573. // Add a garbage collector to delete old patterns with autogenerated hashes that
  574. // are no longer being referenced.
  575. addEvent(H.Chart, 'redraw', function () {
  576. var usedIds = {},
  577. renderer = this.renderer,
  578. // Get the autocomputed patterns - these are the ones we might delete
  579. patterns = (renderer.defIds || []).filter(function (pattern) {
  580. return (pattern.indexOf &&
  581. pattern.indexOf('highcharts-pattern-') === 0);
  582. });
  583. if (patterns.length) {
  584. // Look through the DOM for usage of the patterns. This can be points,
  585. // series, tooltips etc.
  586. [].forEach.call(this.renderTo.querySelectorAll('[color^="url("], [fill^="url("], [stroke^="url("]'), function (node) {
  587. var id = node.getAttribute('fill') ||
  588. node.getAttribute('color') ||
  589. node.getAttribute('stroke');
  590. if (id) {
  591. var sanitizedId = id.replace(renderer.url, '').replace('url(#', '').replace(')', '');
  592. usedIds[sanitizedId] = true;
  593. }
  594. });
  595. // Loop through the patterns that exist and see if they are used
  596. patterns.forEach(function (id) {
  597. if (!usedIds[id]) {
  598. // Remove id from used id list
  599. erase(renderer.defIds, id);
  600. // Remove pattern element
  601. if (renderer.patternElements[id]) {
  602. renderer.patternElements[id].destroy();
  603. delete renderer.patternElements[id];
  604. }
  605. }
  606. });
  607. }
  608. });
  609. });
  610. _registerModule(_modules, 'masters/modules/pattern-fill.src.js', [], function () {
  611. });
  612. }));