UNPKG

3.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3require("source-map-support/register");
4// TODO should I get rid of the lib above for production browser build?
5/* pvjson: "id" is a required property.
6 * GPML2013a: GraphId is sometimes optional, e.g., for Groups or Anchors.
7 * GPML2017: supposed to make GraphId required.
8 *
9 * When converting GPML2013a, we fill in any missing GraphIds so that any
10 * element that MAY have a GraphId DOES have one.
11 * If the GraphId is already specified, we don't change it.
12 * If it is not specified, we want to generate one with these properties:
13 * 1) Stability/Purity: you can convert the same GPML file any number of times
14 * and always get the same pvjson output.
15 * 2) Uniqueness: don't clobber an existing GraphId in the pathway.
16 *
17 * The PathVisio algorithm for GraphId generation is basically:
18 *
19 * GraphId = RandomValue + IncrementingValue
20 *
21 * where IncrementingValue is generated by starting with a hex value of
22 * "0xa00" for the first GraphId and incrementing that value for each
23 * subsequent GraphId:
24 * https://github.com/PathVisio/pathvisio/blob/3cb194f120de550ef2e102877965bed3c54a6a75/modules/org.pathvisio.core/src/org/pathvisio/core/biopax/BiopaxElement.java#L245
25 *
26 * We want a stable output, so instead of using a random value, we use the
27 * namespace "pvjsgeneratedid", and since that's a string, we must append
28 * the IncrementingValue instead of adding it:
29 *
30 * GraphId = "pvjsgeneratedid" + IncrementingValue
31 */
32var GraphIdManager = /** @class */ (function () {
33 function GraphIdManager() {
34 this.namespace = "pvjsgeneratedid";
35 this.incrementingValueAsInt = parseInt("0xa00", 16);
36 }
37 GraphIdManager.prototype.generateAndRecord = function () {
38 this.incrementingValueAsInt += 1;
39 // NOTE: the namespace is not part of incrementingValueAsInt
40 return this.namespace + this.incrementingValueAsInt.toString(16);
41 };
42 GraphIdManager.prototype.recordExisting = function (graphIdAsHex) {
43 var incrementingValueAsInt = this.incrementingValueAsInt;
44 var graphIdAsInt = parseInt(graphIdAsHex, 16);
45 // NOTE: this graphIdAsInt does not refer to exactly the same thing as PathVisio's
46 // IncrementingValue, because it's the sum of RandomValue and IncrementingValue.
47 if (graphIdAsInt > incrementingValueAsInt) {
48 this.incrementingValueAsInt = graphIdAsInt;
49 }
50 };
51 return GraphIdManager;
52}());
53exports.GraphIdManager = GraphIdManager;
54//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJZE1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvR3JhcGhJZE1hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBcUM7QUFDckMsdUVBQXVFO0FBRXZFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQTBCRztBQUNIO0lBR0U7UUFEQSxjQUFTLEdBQVcsaUJBQWlCLENBQUM7UUFFcEMsSUFBSSxDQUFDLHNCQUFzQixHQUFHLFFBQVEsQ0FBQyxPQUFPLEVBQUUsRUFBRSxDQUFDLENBQUM7SUFDdEQsQ0FBQztJQUVELDBDQUFpQixHQUFqQjtRQUNFLElBQUksQ0FBQyxzQkFBc0IsSUFBSSxDQUFDLENBQUM7UUFDakMsNERBQTREO1FBQzVELE1BQU0sQ0FBQyxJQUFJLENBQUMsU0FBUyxHQUFHLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxRQUFRLENBQUMsRUFBRSxDQUFDLENBQUM7SUFDbkUsQ0FBQztJQUVELHVDQUFjLEdBQWQsVUFBZSxZQUFZO1FBQ2pCLElBQUEsb0RBQXNCLENBQVU7UUFDeEMsSUFBTSxZQUFZLEdBQUcsUUFBUSxDQUFDLFlBQVksRUFBRSxFQUFFLENBQUMsQ0FBQztRQUNoRCxrRkFBa0Y7UUFDbEYsZ0ZBQWdGO1FBQ2hGLEVBQUUsQ0FBQyxDQUFDLFlBQVksR0FBRyxzQkFBc0IsQ0FBQyxDQUFDLENBQUM7WUFDMUMsSUFBSSxDQUFDLHNCQUFzQixHQUFHLFlBQVksQ0FBQztRQUM3QyxDQUFDO0lBQ0gsQ0FBQztJQUNILHFCQUFDO0FBQUQsQ0FBQyxBQXRCRCxJQXNCQztBQXRCWSx3Q0FBYyJ9
\No newline at end of file