diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index ea83c170..320b5546 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -47,7 +47,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{ // NOTE: We do not use the same pool as the rest of the library here, // since this is only required to be unique at runtime among other // CurveLocation objects. - this._id = CurveLocation._id = (CurveLocation._id || 0) + 1; + this._id = UID.get(CurveLocation); this._curve = curve; // Also store references to segment1 and segment2, in case path // splitting / dividing is going to happen, in which case the segments diff --git a/src/style/Color.js b/src/style/Color.js index ceb3fdd2..056a865b 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -605,6 +605,9 @@ 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 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/util/UID.js b/src/util/UID.js index 22725bfe..2f649a0e 100644 --- a/src/util/UID.js +++ b/src/util/UID.js @@ -17,6 +17,7 @@ */ var UID = { _id: 1, + _pools: {}, /** * Returns the next unique id. @@ -24,7 +25,17 @@ var UID = { * @return {Number} The next unique id * @static **/ - get: function() { - return this._id++; + get: function(ctor) { + if (ctor) { + // Use one UID pool per given constructor + var name = ctor._class, + pool = this._pools[name]; + if (!pool) + pool = this._pools[name] = { _id: 1 }; + return pool._id++; + } else { + // Use the global UID pool: + return this._id++; + } } };