From 2c2542fb2f245251c1c13d82372b9f7898abc236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 10 Jun 2016 16:19:59 +0200 Subject: [PATCH] Remove unique IDs from Color objects. --- src/style/Color.js | 3 --- src/svg/SvgExport.js | 12 ++++++++---- src/util/UID.js | 7 +++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/style/Color.js b/src/style/Color.js index 4f913fb8..4232bfdc 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -606,9 +606,6 @@ var Color = Base.extend(new function() { } // Default fallbacks: rgb, black this._type = type || 'rgb'; - // Define this Color's unique id in its own private id pool. - // NOTE: This is only required by SVG Export code! - this._id = UID.get(Color); if (!components) { // Produce a components array now, and parse values. Even if no // values are defined, parsers are still called to produce diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 730c38d5..15808d73 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -324,7 +324,10 @@ new function() { function getDefinition(item, type) { if (!definitions) definitions = { ids: {}, svgs: {} }; - return item && definitions.svgs[type + '-' + item._id]; + // Use #__id for items that don't have internal #_id properties (Color), + // and give them ids from their own private id pool named 'svg'. + var id = item._id || item.__id || (item.__id = UID.get('svg')); + return item && definitions.svgs[type + '-' + id]; } function setDefinition(item, node, type) { @@ -333,10 +336,11 @@ new function() { if (!definitions) getDefinition(); // Have different id ranges per type - var id = definitions.ids[type] = (definitions.ids[type] || 0) + 1; + var typeId = definitions.ids[type] = (definitions.ids[type] || 0) + 1; // Give the svg node an id, and link to it from the item id. - node.id = type + '-' + id; - definitions.svgs[type + '-' + item._id] = node; + node.id = type + '-' + typeId; + // See getDefinition() for an explanation of #__id: + definitions.svgs[type + '-' + (item._id || item.__id)] = node; } function exportDefinitions(node, options) { diff --git a/src/util/UID.js b/src/util/UID.js index 628baf02..9aac04c0 100644 --- a/src/util/UID.js +++ b/src/util/UID.js @@ -25,11 +25,10 @@ var UID = { * @return {Number} the next unique id * @static **/ - get: function(ctor) { - if (ctor) { + get: function(name) { + if (name) { // Use one UID pool per given constructor - var name = ctor._class, - pool = this._pools[name]; + var pool = this._pools[name]; if (!pool) pool = this._pools[name] = { _id: 1 }; return pool._id++;