@linkurious/ogma-linkurious-parser 3.0.8 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ogma/features/captions.d.ts +1 -1
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/reactive.d.ts +5 -5
- package/dist/ogma/features/reactive.js +34 -34
- package/dist/ogma/features/reactive.js.map +1 -1
- package/dist/ogma/features/selectors.d.ts +1 -1
- package/dist/ogma/features/selectors.js.map +1 -1
- package/dist/ogma/features/styles.js +3 -4
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.d.ts +1 -1
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.d.ts +17 -7
- package/dist/ogma/index.js +63 -22
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/edgeAttributes.d.ts +1 -1
- package/dist/styles/edgeAttributes.js.map +1 -1
- package/dist/styles/itemAttributes.d.ts +1 -1
- package/dist/styles/itemAttributes.js.map +1 -1
- package/dist/styles/nodeAttributes.d.ts +1 -1
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/dist/tools/ogmaTool.d.ts +1 -1
- package/dist/tools/ogmaTool.js.map +1 -1
- package/dist/tools/tools.d.ts +1 -1
- package/dist/tools/tools.js.map +1 -1
- package/package.json +5 -5
package/dist/ogma/index.d.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { ForceLayoutMode, HierarchicalLayoutMode, IOgmaConfig, LkEdgeData, LkNodeData, PopulatedVisualization, VizEdge, VizNode } from '@linkurious/rest-client';
|
|
2
|
-
import Ogma, { EdgeList, ForceLayoutOptions, HierarchicalLayoutOptions, NodeList, NonObjectPropertyWatcher, RadialLayoutOptions, RawEdge, RawGraph } from 'ogma';
|
|
2
|
+
import Ogma, { EdgeList, ForceLayoutOptions, HierarchicalLayoutOptions, NodeList, NonObjectPropertyWatcher, RadialLayoutOptions, RawEdge, RawGraph } from '@linkurious/ogma';
|
|
3
3
|
import { StylesViz } from './features/styles';
|
|
4
4
|
import { TransformationsViz } from './features/transformations';
|
|
5
5
|
import { CaptionsViz } from './features/captions';
|
|
6
6
|
import { OgmaStore } from './features/OgmaStore';
|
|
7
|
-
export { default as Ogma } from 'ogma';
|
|
7
|
+
export { default as Ogma } from '@linkurious/ogma';
|
|
8
8
|
export declare const ANIMATION_DURATION = 750;
|
|
9
9
|
interface AddItemOptions {
|
|
10
10
|
batchSize?: number;
|
|
11
11
|
virtual?: boolean;
|
|
12
12
|
}
|
|
13
13
|
export declare class LKOgma extends Ogma<LkNodeData, LkEdgeData> {
|
|
14
|
-
private
|
|
14
|
+
private _configuration;
|
|
15
15
|
LKStyles: StylesViz;
|
|
16
16
|
LKCaptions: CaptionsViz;
|
|
17
17
|
LKTransformation: TransformationsViz;
|
|
18
18
|
nodeCategoriesWatcher: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;
|
|
19
19
|
edgeTypeWatcher: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;
|
|
20
20
|
store: OgmaStore;
|
|
21
|
-
|
|
21
|
+
private _reactive;
|
|
22
|
+
constructor(_configuration: IOgmaConfig);
|
|
23
|
+
private initOgmaLinkuriousParser;
|
|
22
24
|
/**
|
|
23
25
|
* Initialize selection behavior
|
|
24
26
|
*/
|
|
25
27
|
initSelection(): void;
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
+
private setStyles;
|
|
29
|
+
private setCaptions;
|
|
28
30
|
/**
|
|
29
31
|
* Returns Ogma Layout parameters according to visualization layout settings
|
|
30
32
|
* */
|
|
31
33
|
getForceLayoutParams(mode: ForceLayoutMode, duration?: number): ForceLayoutOptions;
|
|
32
|
-
getRadialLayoutParams(rootNode: string, duration?: number): RadialLayoutOptions
|
|
34
|
+
getRadialLayoutParams(rootNode: string, duration?: number): RadialLayoutOptions<unknown, unknown>;
|
|
33
35
|
getHierarchicalLayoutParams(mode: HierarchicalLayoutMode, rootNode: string, duration?: number): HierarchicalLayoutOptions;
|
|
34
36
|
/**
|
|
35
37
|
* Initialize graph.
|
|
@@ -71,4 +73,12 @@ export declare class LKOgma extends Ogma<LkNodeData, LkEdgeData> {
|
|
|
71
73
|
* Do a full reset on ogma and streams of ogma
|
|
72
74
|
*/
|
|
73
75
|
shutDown(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Reset the Ogma instance so that it can be used fresh in the next visulization
|
|
78
|
+
*/
|
|
79
|
+
clearOgmaState(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Updates the Ogma config when config changes in LKE. If init, options were already set by the Ogma.reset()
|
|
82
|
+
*/
|
|
83
|
+
setConfigOgma(configuration: IOgmaConfig, init?: boolean): void;
|
|
74
84
|
}
|
package/dist/ogma/index.js
CHANGED
|
@@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
|
+
var __assign = (this && this.__assign) || function () {
|
|
16
|
+
__assign = Object.assign || function(t) {
|
|
17
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
+
s = arguments[i];
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
15
26
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
27
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
28
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,35 +64,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
64
|
};
|
|
54
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
66
|
var rest_client_1 = require("@linkurious/rest-client");
|
|
56
|
-
var ogma_1 = __importDefault(require("ogma"));
|
|
67
|
+
var ogma_1 = __importDefault(require("@linkurious/ogma"));
|
|
57
68
|
var __1 = require("..");
|
|
58
69
|
var tools_1 = require("../tools/tools");
|
|
59
70
|
var styles_1 = require("./features/styles");
|
|
60
71
|
var transformations_1 = require("./features/transformations");
|
|
61
72
|
var captions_1 = require("./features/captions");
|
|
62
73
|
var reactive_1 = require("./features/reactive");
|
|
63
|
-
var ogma_2 = require("ogma");
|
|
74
|
+
var ogma_2 = require("@linkurious/ogma");
|
|
64
75
|
exports.Ogma = ogma_2.default;
|
|
65
76
|
exports.ANIMATION_DURATION = 750;
|
|
66
77
|
var LKOgma = /** @class */ (function (_super) {
|
|
67
78
|
__extends(LKOgma, _super);
|
|
68
|
-
function LKOgma(
|
|
79
|
+
function LKOgma(_configuration) {
|
|
69
80
|
var _newTarget = this.constructor;
|
|
70
81
|
var _this =
|
|
71
82
|
// set Ogma global configuration
|
|
72
|
-
_super.call(this,
|
|
73
|
-
_this.
|
|
83
|
+
_super.call(this, _configuration) || this;
|
|
84
|
+
_this._configuration = _configuration;
|
|
85
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
86
|
+
_this.initOgmaLinkuriousParser();
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
LKOgma.prototype.initOgmaLinkuriousParser = function () {
|
|
90
|
+
this.nodeCategoriesWatcher = this.schema.watchNodeNonObjectProperty({
|
|
74
91
|
path: 'categories',
|
|
75
92
|
unwindArrays: true,
|
|
76
93
|
filter: 'all'
|
|
77
94
|
});
|
|
78
|
-
|
|
95
|
+
this.edgeTypeWatcher = this.schema.watchEdgeNonObjectProperty({
|
|
79
96
|
path: 'type',
|
|
80
97
|
filter: 'all'
|
|
81
98
|
});
|
|
82
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
83
99
|
// set ogma max zoom value and selection with mouse option (false?)
|
|
84
|
-
|
|
100
|
+
this.setOptions({
|
|
85
101
|
interactions: {
|
|
86
102
|
zoom: {
|
|
87
103
|
maxValue: function (params) {
|
|
@@ -93,18 +109,23 @@ var LKOgma = /** @class */ (function (_super) {
|
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
// only instantiate the store once when app is starting
|
|
113
|
+
if (this._reactive === undefined) {
|
|
114
|
+
this._reactive = new reactive_1.RxViz(this);
|
|
115
|
+
this.store = this._reactive.store;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// if store already exist, but ogma was reset, create new ogma event listener
|
|
119
|
+
this._reactive.listenToSelectionEvents();
|
|
120
|
+
}
|
|
121
|
+
this.initSelection();
|
|
122
|
+
this.setConfigOgma(this._configuration, true);
|
|
123
|
+
this.LKTransformation = new transformations_1.TransformationsViz(this);
|
|
124
|
+
this.LKStyles.setNodesDefaultHalo();
|
|
125
|
+
this.LKStyles.setEdgesDefaultHalo();
|
|
126
|
+
this.LKStyles.setBadgeRule();
|
|
127
|
+
this.LKStyles.setFilterClass();
|
|
128
|
+
};
|
|
108
129
|
/**
|
|
109
130
|
* Initialize selection behavior
|
|
110
131
|
*/
|
|
@@ -141,7 +162,7 @@ var LKOgma = /** @class */ (function (_super) {
|
|
|
141
162
|
}
|
|
142
163
|
});
|
|
143
164
|
};
|
|
144
|
-
LKOgma.prototype.
|
|
165
|
+
LKOgma.prototype.setStyles = function (configuration) {
|
|
145
166
|
var _a, _b, _c, _d, _e, _f;
|
|
146
167
|
this.LKStyles = new styles_1.StylesViz(this, {
|
|
147
168
|
node: ((_c = (_b = (_a = configuration) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.styles) === null || _c === void 0 ? void 0 : _c.node) || {},
|
|
@@ -150,7 +171,7 @@ var LKOgma = /** @class */ (function (_super) {
|
|
|
150
171
|
this.LKStyles.setNodesDefaultStyles();
|
|
151
172
|
this.LKStyles.setEdgesDefaultStyles();
|
|
152
173
|
};
|
|
153
|
-
LKOgma.prototype.
|
|
174
|
+
LKOgma.prototype.setCaptions = function (configuration) {
|
|
154
175
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
155
176
|
var nodeMaxTextLength = (_e = (_d = (_c = (_b = (_a = configuration) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.styles) === null || _c === void 0 ? void 0 : _c.node) === null || _d === void 0 ? void 0 : _d.text) === null || _e === void 0 ? void 0 : _e.maxTextLength;
|
|
156
177
|
var edgeMaxTextLength = (_k = (_j = (_h = (_g = (_f = configuration) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.styles) === null || _h === void 0 ? void 0 : _h.edge) === null || _j === void 0 ? void 0 : _j.text) === null || _k === void 0 ? void 0 : _k.maxTextLength;
|
|
@@ -345,6 +366,26 @@ var LKOgma = /** @class */ (function (_super) {
|
|
|
345
366
|
this.store.clear();
|
|
346
367
|
}
|
|
347
368
|
};
|
|
369
|
+
/**
|
|
370
|
+
* Reset the Ogma instance so that it can be used fresh in the next visulization
|
|
371
|
+
*/
|
|
372
|
+
LKOgma.prototype.clearOgmaState = function () {
|
|
373
|
+
this.reset();
|
|
374
|
+
if (this.store) {
|
|
375
|
+
this.store.clear();
|
|
376
|
+
}
|
|
377
|
+
this.initOgmaLinkuriousParser();
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Updates the Ogma config when config changes in LKE. If init, options were already set by the Ogma.reset()
|
|
381
|
+
*/
|
|
382
|
+
LKOgma.prototype.setConfigOgma = function (configuration, init) {
|
|
383
|
+
if (!init) {
|
|
384
|
+
this.setOptions(__assign(__assign({}, configuration.options), { renderer: configuration.renderer }));
|
|
385
|
+
}
|
|
386
|
+
this.setStyles(configuration);
|
|
387
|
+
this.setCaptions(configuration);
|
|
388
|
+
};
|
|
348
389
|
return LKOgma;
|
|
349
390
|
}(ogma_1.default));
|
|
350
391
|
exports.LKOgma = LKOgma;
|
package/dist/ogma/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ogma/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAUiC;AACjC,8CAUc;AAEd,wBAA8B;AAC9B,wCAAqC;AAErC,4CAA4C;AAC5C,8DAA8D;AAC9D,gDAAgD;AAChD,gDAA0C;AAG1C,6BAAqC;AAA7B,sBAAA,OAAO,CAAQ;AACV,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAOtC;IAA4B,0BAA4B;IAWtD,gBAAY,aAA0B;;QAAtC;QACE,gCAAgC;QAChC,kBAAM,aAAa,CAAC,SAoCrB;QAnCC,KAAI,CAAC,qBAAqB,GAAG,KAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC;YAClE,IAAI,EAAE,YAAY;YAClB,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;QACH,KAAI,CAAC,eAAe,GAAG,KAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC;YAC5D,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,WAAW,SAAS,CAAC,CAAC;QAClD,oEAAoE;QACpE,KAAI,CAAC,UAAU,CAAC;YACd,YAAY,EAAE;gBACZ,IAAI,EAAE;oBACJ,QAAQ,EAAE,UAAC,MAAW;wBACpB,OAAO,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC;oBACvC,CAAC;iBACF;gBACD,SAAS,EAAE;oBACT,OAAO,EAAE,KAAK;iBACf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AC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAtB,CAAsB,CAAC;YAC5D,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAtB,CAAsB,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACI,yBAAQ,GAAf;QACE,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACpB;IACH,CAAC;IACH,aAAC;AAAD,CAAC,AAjRD,CAA4B,cAAI,GAiR/B;AAjRY,wBAAM","sourcesContent":["import {\n EntityType,\n ForceLayoutMode,\n HierarchicalLayoutMode,\n IOgmaConfig,\n LkEdgeData,\n LkNodeData,\n PopulatedVisualization,\n VizEdge,\n VizNode\n} from '@linkurious/rest-client';\nimport Ogma, {\n EdgeList,\n ForceLayoutOptions,\n HierarchicalLayoutOptions,\n NodeList,\n NonObjectPropertyWatcher,\n RadialLayoutOptions,\n RawEdge,\n RawGraph,\n RawNode\n} from 'ogma';\n\nimport {StyleRules} from '..';\nimport {Tools} from '../tools/tools';\n\nimport {StylesViz} from './features/styles';\nimport {TransformationsViz} from './features/transformations';\nimport {CaptionsViz} from './features/captions';\nimport {RxViz} from './features/reactive';\nimport {OgmaStore} from './features/OgmaStore';\n\nexport {default as Ogma} from 'ogma';\nexport const ANIMATION_DURATION = 750;\n\ninterface AddItemOptions {\n batchSize?: number;\n virtual?: boolean;\n}\n\nexport class LKOgma extends Ogma<LkNodeData, LkEdgeData> {\n private _reactive: RxViz;\n public LKStyles!: StylesViz;\n public LKCaptions!: CaptionsViz;\n public LKTransformation: TransformationsViz;\n // Trigger an event with node category changes\n public nodeCategoriesWatcher: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;\n // Trigger an event with edge type changes\n public edgeTypeWatcher: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;\n public store: OgmaStore;\n\n constructor(configuration: IOgmaConfig) {\n // set Ogma global configuration\n super(configuration);\n this.nodeCategoriesWatcher = this.schema.watchNodeNonObjectProperty({\n path: 'categories',\n unwindArrays: true,\n filter: 'all'\n });\n this.edgeTypeWatcher = this.schema.watchEdgeNonObjectProperty({\n path: 'type',\n filter: 'all'\n });\n Object.setPrototypeOf(this, new.target.prototype);\n // set ogma max zoom value and selection with mouse option (false?)\n this.setOptions({\n interactions: {\n zoom: {\n maxValue: (params: any) => {\n return 128 / params.smallestNodeSize;\n }\n },\n selection: {\n enabled: false\n }\n }\n });\n\n this._reactive = new RxViz(this);\n this.store = this._reactive.store;\n this.initSelection();\n this.initStyles(configuration);\n this.initCaptions(configuration);\n this.LKTransformation = new TransformationsViz(this);\n\n this.LKStyles.setNodesDefaultHalo();\n this.LKStyles.setEdgesDefaultHalo();\n this.LKStyles.setBadgeRule();\n this.LKStyles.setFilterClass();\n }\n\n /**\n * Initialize selection behavior\n */\n public initSelection(): void {\n this.events.onClick((e) => {\n if (e !== undefined && e.button === 'left') {\n if (e.target !== null) {\n const multiSelectionKey = navigator.platform === 'MacIntel' ? 'cmd' : 'ctrl';\n if (this.keyboard.isKeyPressed(multiSelectionKey)) {\n if (e.target.isNode && this.getSelectedEdges().size > 0) {\n this.getSelectedEdges().setSelected(false);\n }\n if (!e.target.isNode && this.getSelectedNodes().size > 0) {\n this.getSelectedNodes().setSelected(false);\n }\n if (e.target.isSelected()) {\n e.target.setSelected(false);\n } else {\n e.target.setSelected(true);\n }\n } else {\n this.getSelectedNodes().setSelected(false);\n this.getSelectedEdges().setSelected(false);\n e.target.setSelected(true);\n }\n } else {\n this.getSelectedNodes().setSelected(false);\n this.getSelectedEdges().setSelected(false);\n }\n }\n });\n }\n\n private initStyles(configuration: IOgmaConfig): void {\n this.LKStyles = new StylesViz(this, {\n node: configuration?.options?.styles?.node || {},\n edge: configuration?.options?.styles?.edge || {}\n });\n this.LKStyles.setNodesDefaultStyles();\n this.LKStyles.setEdgesDefaultStyles();\n }\n\n private initCaptions(configuration: IOgmaConfig): void {\n const nodeMaxTextLength = configuration?.options?.styles?.node?.text?.maxTextLength;\n const edgeMaxTextLength = configuration?.options?.styles?.edge?.text?.maxTextLength;\n this.LKCaptions = new CaptionsViz(this, nodeMaxTextLength, edgeMaxTextLength);\n }\n\n /**\n * Returns Ogma Layout parameters according to visualization layout settings\n * */\n public getForceLayoutParams(mode: ForceLayoutMode, duration = 0): ForceLayoutOptions {\n let dynamicSteps = 300 - ((300 - 40) / 5000) * this.getNodes().size;\n if (dynamicSteps < 40) {\n dynamicSteps = 40;\n }\n return {\n steps: mode === ForceLayoutMode.FAST ? dynamicSteps : 300,\n alignSiblings: this.getNodes().size > 3,\n duration: duration,\n charge: 20,\n gravity: 0.08,\n theta: this.getNodes().size > 100 ? 0.8 : 0.34\n };\n }\n public getRadialLayoutParams(rootNode: string, duration = 0): RadialLayoutOptions {\n return {\n centralNode: rootNode,\n radiusDelta: 1,\n nodeGap: 10,\n repulsion: this.getNodes().size > 80 ? 1 : 6,\n duration: duration\n };\n }\n\n public getHierarchicalLayoutParams(\n mode: HierarchicalLayoutMode,\n rootNode: string,\n duration = 0\n ): HierarchicalLayoutOptions {\n return {\n direction: mode,\n roots: [rootNode],\n duration: duration\n };\n }\n\n /**\n * Initialize graph.\n * add nodes and edges to the viz and init the selection.\n */\n public async init(visualization: {nodes: Array<VizNode>; edges: Array<VizEdge>}): Promise<void> {\n this.clearGraph();\n let selectedEntityType: EntityType | undefined = undefined;\n let selectedElements: Array<string> = [];\n // need to remove selected in every items before adding them to Ogma\n const fixedNodes = visualization.nodes.map((node) => {\n if (node.attributes.selected) {\n selectedEntityType = EntityType.NODE;\n selectedElements.push(node.id);\n }\n delete node.attributes.selected;\n return node;\n });\n const fixedEdges = visualization.edges.map((edge) => {\n if (edge.attributes !== undefined) {\n if (edge.attributes.selected) {\n if (selectedEntityType === undefined || selectedEntityType === EntityType.NODE) {\n selectedEntityType = EntityType.EDGE;\n selectedElements = [];\n }\n selectedElements.push(edge.id);\n }\n delete edge.attributes.selected;\n }\n return edge;\n });\n await this.addGraphAfterValidation({\n nodes: fixedNodes as Array<RawNode<LkNodeData>>,\n edges: fixedEdges as Array<RawEdge<LkEdgeData>>\n });\n if (selectedEntityType === EntityType.NODE) {\n this.getNodes(selectedElements).setSelected(true);\n } else if (selectedEntityType === EntityType.EDGE) {\n this.getEdges(selectedElements).setSelected(true);\n }\n }\n\n public async initVisualization(visualization: PopulatedVisualization) {\n this.init(visualization);\n const styles = StyleRules.sanitizeStylesIndex(visualization.design.styles);\n this.LKStyles.initNodeColors(styles.node);\n this.LKStyles.initNodesIcons(styles.node);\n this.LKStyles.initNodesSizes(styles.node);\n this.LKStyles.initNodesShapes(styles.node);\n this.LKStyles.initEdgesWidth(styles.edge);\n this.LKStyles.initEdgesShape(styles.edge);\n this.LKStyles.initEdgesColor(styles.edge);\n this.LKCaptions.initVizCaptions({\n node: visualization.nodeFields.captions || {},\n edge: visualization.edgeFields.captions || {}\n });\n this.LKTransformation.groupedEdges = visualization.edgeGrouping;\n this.LKTransformation.initTransformation();\n this.LKTransformation.initEdgeGroupingStyle();\n }\n\n /**\n * Adding nodes then adding edges to the graph\n */\n public async addGraphAfterValidation(\n graph: RawGraph<LkNodeData, LkEdgeData>\n ): Promise<{\n nodes: NodeList<LkNodeData>;\n edges: EdgeList<LkEdgeData>;\n }> {\n const addedNodes = await this.addNodes(graph.nodes);\n const addedEdges = await this.addEdges(graph.edges);\n return {\n nodes: addedNodes,\n edges: addedEdges\n };\n }\n\n /**\n * Adding edges to the graph after filtering disconnected ones\n */\n public async addEdges(\n edges: Array<RawEdge<LkEdgeData>>,\n options?: AddItemOptions\n ): Promise<EdgeList> {\n const filteredEdges = edges.filter((edge) => {\n return this.getNode(edge.source) !== undefined && this.getNode(edge.target) !== undefined;\n });\n return super.addEdges(filteredEdges, options);\n }\n\n /**\n * Return the list of non filtered nodes\n */\n public getNonFilteredNodes(items?: Array<any>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => !i.hasClass('filtered'))\n : this.getNodes().filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered nodes\n */\n public getFilteredNodes(items?: Array<any>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => i.hasClass('filtered'))\n : this.getNodes().filter((i) => i.hasClass('filtered'));\n }\n\n /**\n * Return the list of non filtered edges\n */\n public getNonFilteredEdges(items?: Array<any>): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => !i.hasClass('filtered'))\n : this.getEdges('raw').filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered edges\n */\n public getFilteredEdges(items?: Array<any>): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => i.hasClass('filtered'))\n : this.getEdges('raw').filter((i) => i.hasClass('filtered'));\n }\n\n /**\n * Do a full reset on ogma and streams of ogma\n */\n public shutDown() {\n this.destroy();\n if (this.store) {\n this.store.clear();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ogma/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAUiC;AACjC,0DAU0B;AAE1B,wBAA8B;AAC9B,wCAAqC;AAErC,4CAA4C;AAC5C,8DAA8D;AAC9D,gDAAgD;AAChD,gDAA0C;AAG1C,yCAAiD;AAAzC,sBAAA,OAAO,CAAQ;AACV,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAOtC;IAA4B,0BAA4B;IAWtD,gBAAoB,cAA2B;;QAA/C;QACE,gCAAgC;QAChC,kBAA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,EAAE,CAAC;SACpB;IACH,CAAC;IAED;;OAEG;IACI,+BAAc,GAArB;QACE,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,8BAAa,GAApB,UAAqB,aAA0B,EAAE,IAAc;QAC7D,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,CAAC,UAAU,uBACV,aAAa,CAAC,OAAO,KACxB,QAAQ,EAAE,aAAa,CAAC,QAAQ,IAChC,CAAC;SACJ;QACD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QAC9B,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAClC,CAAC;IACH,aAAC;AAAD,CAAC,AAvTD,CAA4B,cAAI,GAuT/B;AAvTY,wBAAM","sourcesContent":["import {\n EntityType,\n ForceLayoutMode,\n HierarchicalLayoutMode,\n IOgmaConfig,\n LkEdgeData,\n LkNodeData,\n PopulatedVisualization,\n VizEdge,\n VizNode\n} from '@linkurious/rest-client';\nimport Ogma, {\n EdgeList,\n ForceLayoutOptions,\n HierarchicalLayoutOptions,\n NodeList,\n NonObjectPropertyWatcher,\n RadialLayoutOptions,\n RawEdge,\n RawGraph,\n RawNode\n} from '@linkurious/ogma';\n\nimport {StyleRules} from '..';\nimport {Tools} from '../tools/tools';\n\nimport {StylesViz} from './features/styles';\nimport {TransformationsViz} from './features/transformations';\nimport {CaptionsViz} from './features/captions';\nimport {RxViz} from './features/reactive';\nimport {OgmaStore} from './features/OgmaStore';\n\nexport {default as Ogma} from '@linkurious/ogma';\nexport const ANIMATION_DURATION = 750;\n\ninterface AddItemOptions {\n batchSize?: number;\n virtual?: boolean;\n}\n\nexport class LKOgma extends Ogma<LkNodeData, LkEdgeData> {\n public LKStyles!: StylesViz;\n public LKCaptions!: CaptionsViz;\n public LKTransformation!: TransformationsViz;\n // Trigger an event with node category changes\n public nodeCategoriesWatcher!: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;\n // Trigger an event with edge type changes\n public edgeTypeWatcher!: NonObjectPropertyWatcher<LkNodeData, LkEdgeData>;\n public store!: OgmaStore;\n private _reactive!: RxViz;\n\n constructor(private _configuration: IOgmaConfig) {\n // set Ogma global configuration\n super(_configuration);\n Object.setPrototypeOf(this, new.target.prototype);\n this.initOgmaLinkuriousParser();\n }\n\n private initOgmaLinkuriousParser(): void {\n this.nodeCategoriesWatcher = this.schema.watchNodeNonObjectProperty({\n path: 'categories',\n unwindArrays: true,\n filter: 'all'\n });\n this.edgeTypeWatcher = this.schema.watchEdgeNonObjectProperty({\n path: 'type',\n filter: 'all'\n });\n // set ogma max zoom value and selection with mouse option (false?)\n this.setOptions({\n interactions: {\n zoom: {\n maxValue: (params: any) => {\n return 128 / params.smallestNodeSize;\n }\n },\n selection: {\n enabled: false\n }\n }\n });\n\n // only instantiate the store once when app is starting\n if (this._reactive === undefined) {\n this._reactive = new RxViz(this);\n this.store = this._reactive.store;\n } else {\n // if store already exist, but ogma was reset, create new ogma event listener\n this._reactive.listenToSelectionEvents();\n }\n this.initSelection();\n this.setConfigOgma(this._configuration, true);\n this.LKTransformation = new TransformationsViz(this);\n\n this.LKStyles.setNodesDefaultHalo();\n this.LKStyles.setEdgesDefaultHalo();\n this.LKStyles.setBadgeRule();\n this.LKStyles.setFilterClass();\n }\n\n /**\n * Initialize selection behavior\n */\n public initSelection(): void {\n this.events.onClick((e) => {\n if (e !== undefined && e.button === 'left') {\n if (e.target !== null) {\n const multiSelectionKey = navigator.platform === 'MacIntel' ? 'cmd' : 'ctrl';\n if (this.keyboard.isKeyPressed(multiSelectionKey)) {\n if (e.target.isNode && this.getSelectedEdges().size > 0) {\n this.getSelectedEdges().setSelected(false);\n }\n if (!e.target.isNode && this.getSelectedNodes().size > 0) {\n this.getSelectedNodes().setSelected(false);\n }\n if (e.target.isSelected()) {\n e.target.setSelected(false);\n } else {\n e.target.setSelected(true);\n }\n } else {\n this.getSelectedNodes().setSelected(false);\n this.getSelectedEdges().setSelected(false);\n e.target.setSelected(true);\n }\n } else {\n this.getSelectedNodes().setSelected(false);\n this.getSelectedEdges().setSelected(false);\n }\n }\n });\n }\n\n private setStyles(configuration: IOgmaConfig): void {\n this.LKStyles = new StylesViz(this, {\n node: configuration?.options?.styles?.node || {},\n edge: configuration?.options?.styles?.edge || {}\n });\n this.LKStyles.setNodesDefaultStyles();\n this.LKStyles.setEdgesDefaultStyles();\n }\n\n private setCaptions(configuration: IOgmaConfig): void {\n const nodeMaxTextLength = configuration?.options?.styles?.node?.text?.maxTextLength;\n const edgeMaxTextLength = configuration?.options?.styles?.edge?.text?.maxTextLength;\n this.LKCaptions = new CaptionsViz(this, nodeMaxTextLength, edgeMaxTextLength);\n }\n\n /**\n * Returns Ogma Layout parameters according to visualization layout settings\n * */\n public getForceLayoutParams(mode: ForceLayoutMode, duration = 0): ForceLayoutOptions {\n let dynamicSteps = 300 - ((300 - 40) / 5000) * this.getNodes().size;\n if (dynamicSteps < 40) {\n dynamicSteps = 40;\n }\n return {\n steps: mode === ForceLayoutMode.FAST ? dynamicSteps : 300,\n alignSiblings: this.getNodes().size > 3,\n duration: duration,\n charge: 20,\n gravity: 0.08,\n theta: this.getNodes().size > 100 ? 0.8 : 0.34\n };\n }\n\n public getRadialLayoutParams(\n rootNode: string,\n duration = 0\n ): RadialLayoutOptions<unknown, unknown> {\n return {\n centralNode: rootNode,\n radiusDelta: 1,\n nodeGap: 10,\n repulsion: this.getNodes().size > 80 ? 1 : 6,\n duration: duration\n };\n }\n\n public getHierarchicalLayoutParams(\n mode: HierarchicalLayoutMode,\n rootNode: string,\n duration = 0\n ): HierarchicalLayoutOptions {\n return {\n direction: mode,\n roots: [rootNode],\n duration: duration\n };\n }\n\n /**\n * Initialize graph.\n * add nodes and edges to the viz and init the selection.\n */\n public async init(visualization: {nodes: Array<VizNode>; edges: Array<VizEdge>}): Promise<void> {\n this.clearGraph();\n let selectedEntityType: EntityType | undefined = undefined;\n let selectedElements: Array<string> = [];\n // need to remove selected in every items before adding them to Ogma\n const fixedNodes = visualization.nodes.map((node) => {\n if (node.attributes.selected) {\n selectedEntityType = EntityType.NODE;\n selectedElements.push(node.id);\n }\n delete node.attributes.selected;\n return node;\n });\n const fixedEdges = visualization.edges.map((edge) => {\n if (edge.attributes !== undefined) {\n if (edge.attributes.selected) {\n if (selectedEntityType === undefined || selectedEntityType === EntityType.NODE) {\n selectedEntityType = EntityType.EDGE;\n selectedElements = [];\n }\n selectedElements.push(edge.id);\n }\n delete edge.attributes.selected;\n }\n return edge;\n });\n await this.addGraphAfterValidation({\n nodes: fixedNodes as Array<RawNode<LkNodeData>>,\n edges: fixedEdges as Array<RawEdge<LkEdgeData>>\n });\n if (selectedEntityType === EntityType.NODE) {\n this.getNodes(selectedElements).setSelected(true);\n } else if (selectedEntityType === EntityType.EDGE) {\n this.getEdges(selectedElements).setSelected(true);\n }\n }\n\n public async initVisualization(visualization: PopulatedVisualization) {\n this.init(visualization);\n const styles = StyleRules.sanitizeStylesIndex(visualization.design.styles);\n this.LKStyles.initNodeColors(styles.node);\n this.LKStyles.initNodesIcons(styles.node);\n this.LKStyles.initNodesSizes(styles.node);\n this.LKStyles.initNodesShapes(styles.node);\n this.LKStyles.initEdgesWidth(styles.edge);\n this.LKStyles.initEdgesShape(styles.edge);\n this.LKStyles.initEdgesColor(styles.edge);\n this.LKCaptions.initVizCaptions({\n node: visualization.nodeFields.captions || {},\n edge: visualization.edgeFields.captions || {}\n });\n this.LKTransformation.groupedEdges = visualization.edgeGrouping;\n this.LKTransformation.initTransformation();\n this.LKTransformation.initEdgeGroupingStyle();\n }\n\n /**\n * Adding nodes then adding edges to the graph\n */\n public async addGraphAfterValidation(\n graph: RawGraph<LkNodeData, LkEdgeData>\n ): Promise<{\n nodes: NodeList<LkNodeData>;\n edges: EdgeList<LkEdgeData>;\n }> {\n const addedNodes = await this.addNodes(graph.nodes);\n const addedEdges = await this.addEdges(graph.edges);\n return {\n nodes: addedNodes,\n edges: addedEdges\n };\n }\n\n /**\n * Adding edges to the graph after filtering disconnected ones\n */\n public async addEdges(\n edges: Array<RawEdge<LkEdgeData>>,\n options?: AddItemOptions\n ): Promise<EdgeList> {\n const filteredEdges = edges.filter((edge) => {\n return this.getNode(edge.source) !== undefined && this.getNode(edge.target) !== undefined;\n });\n return super.addEdges(filteredEdges, options);\n }\n\n /**\n * Return the list of non filtered nodes\n */\n public getNonFilteredNodes(items?: Array<any>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => !i.hasClass('filtered'))\n : this.getNodes().filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered nodes\n */\n public getFilteredNodes(items?: Array<any>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => i.hasClass('filtered'))\n : this.getNodes().filter((i) => i.hasClass('filtered'));\n }\n\n /**\n * Return the list of non filtered edges\n */\n public getNonFilteredEdges(items?: Array<any>): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => !i.hasClass('filtered'))\n : this.getEdges('raw').filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered edges\n */\n public getFilteredEdges(items?: Array<any>): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => i.hasClass('filtered'))\n : this.getEdges('raw').filter((i) => i.hasClass('filtered'));\n }\n\n /**\n * Do a full reset on ogma and streams of ogma\n */\n public shutDown(): void {\n this.destroy();\n if (this.store) {\n this.store.clear();\n }\n }\n\n /**\n * Reset the Ogma instance so that it can be used fresh in the next visulization\n */\n public clearOgmaState(): void {\n this.reset();\n if (this.store) {\n this.store.clear();\n }\n this.initOgmaLinkuriousParser();\n }\n\n /**\n * Updates the Ogma config when config changes in LKE. If init, options were already set by the Ogma.reset()\n */\n public setConfigOgma(configuration: IOgmaConfig, init?: boolean): void {\n if (!init) {\n this.setOptions({\n ...configuration.options,\n renderer: configuration.renderer\n });\n }\n this.setStyles(configuration);\n this.setCaptions(configuration);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,uDAAkE;AAElE,wCAAqC;AAGrC,mDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED;IAAoC,kCAAc;IAChD,wBAAY,QAIX;eACC,kBAAM,QAAQ,CAAC;IACjB,CAAC;IAED;;OAEG;IACK,mCAAU,GAAlB,UAAmB,UAA4B,EAAE,IAAgB;QAC/D,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC1C,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAClC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;aACtB;SACF;IACH,CAAC;IAED;;OAEG;IACI,8BAAK,GAAZ,UAAa,IAAgB;QAC3B,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO,0BAAS,CAAC;SAClB;QACD,IAAI,KAAK,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACrD,IAAM,IAAI,GAAG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eShape} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport enum EdgeWidthExtrema {\n MIN = 50,\n MAX = 200\n}\n\nexport class EdgeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private matchStyle(styleRules: Array<StyleRule>, data: LkEdgeData): StyleRule | undefined {\n if (data === undefined) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(data)) {\n return styleRules[i];\n }\n }\n }\n\n /**\n * Generate color for a given edge (call only if _rulesMap.color exists)\n */\n public color(data: LkEdgeData): Color {\n if (!Tools.isDefined(data)) {\n return BASE_GREY;\n }\n let color;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (rule.canApplyTo(data)) {\n if (typeof rule.style.color === 'string') {\n color = rule.style.color;\n } else if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(data, rule.style.color.input);\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n break;\n }\n }\n return Tools.isDefined(color) ? color : BASE_GREY;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(data: LkEdgeData): OgmaEdgeShape | undefined {\n if (this._rulesMap.shape !== undefined) {\n return this.matchStyle(this._rulesMap.shape, data)?.style.shape;\n }\n }\n\n /**\n * Generate size for a given node\n */\n public width(data: LkEdgeData): string | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = this.matchStyle(this._rulesMap.width, data);\n const widthStyle = styleRule?.style.width;\n if (Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {\n if (\n widthStyle.input !== undefined &&\n widthStyle.max !== undefined &&\n widthStyle.min !== undefined\n ) {\n const propertyName: string = widthStyle.input[1];\n const propertyValue = Tools.parseNumber(data.properties[propertyName]);\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule);\n }\n } else {\n return widthStyle;\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n */\n public static getAutomaticRangeWidth(value: number, rule: StyleRule): string {\n return this.getAutomaticRangeStyle(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n data: LkEdgeData\n ): {\n color: Color;\n shape: OgmaEdgeShape | undefined;\n width: string | undefined;\n } {\n if (!Tools.isDefined(data)) {\n return {\n color: BASE_GREY,\n shape: OgmaEdgeShape.ARROW,\n width: '100%'\n };\n }\n return {\n color: this.color(data),\n shape: this.shape(data),\n width: this.width(data)\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,uDAAkE;AAElE,wCAAqC;AAGrC,mDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED;IAAoC,kCAAc;IAChD,wBAAY,QAIX;eACC,kBAAM,QAAQ,CAAC;IACjB,CAAC;IAED;;OAEG;IACK,mCAAU,GAAlB,UAAmB,UAA4B,EAAE,IAAgB;QAC/D,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC1C,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAClC,OAAO,UAAU,CAAC,CAA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;aACd,CAAC;SACH;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;SACxB,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AAnHD,CAAoC,+BAAc,GAmHjD;AAnHY,wCAAc","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkEdgeData, OgmaEdgeShape} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport enum EdgeWidthExtrema {\n MIN = 50,\n MAX = 200\n}\n\nexport class EdgeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private matchStyle(styleRules: Array<StyleRule>, data: LkEdgeData): StyleRule | undefined {\n if (data === undefined) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(data)) {\n return styleRules[i];\n }\n }\n }\n\n /**\n * Generate color for a given edge (call only if _rulesMap.color exists)\n */\n public color(data: LkEdgeData): Color {\n if (!Tools.isDefined(data)) {\n return BASE_GREY;\n }\n let color;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (rule.canApplyTo(data)) {\n if (typeof rule.style.color === 'string') {\n color = rule.style.color;\n } else if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(data, rule.style.color.input);\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n break;\n }\n }\n return Tools.isDefined(color) ? color : BASE_GREY;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(data: LkEdgeData): OgmaEdgeShape | undefined {\n if (this._rulesMap.shape !== undefined) {\n return this.matchStyle(this._rulesMap.shape, data)?.style.shape;\n }\n }\n\n /**\n * Generate size for a given node\n */\n public width(data: LkEdgeData): string | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = this.matchStyle(this._rulesMap.width, data);\n const widthStyle = styleRule?.style.width;\n if (Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {\n if (\n widthStyle.input !== undefined &&\n widthStyle.max !== undefined &&\n widthStyle.min !== undefined\n ) {\n const propertyName: string = widthStyle.input[1];\n const propertyValue = Tools.parseNumber(data.properties[propertyName]);\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule);\n }\n } else {\n return widthStyle;\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n */\n public static getAutomaticRangeWidth(value: number, rule: StyleRule): string {\n return this.getAutomaticRangeStyle(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n data: LkEdgeData\n ): {\n color: Color;\n shape: OgmaEdgeShape | undefined;\n width: string | undefined;\n } {\n if (!Tools.isDefined(data)) {\n return {\n color: BASE_GREY,\n shape: OgmaEdgeShape.ARROW,\n width: '100%'\n };\n }\n return {\n color: this.color(data),\n shape: this.shape(data),\n width: this.width(data)\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,8CAAwB;AAGxB,wCAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IAC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AsC,EACtC,KAAyC,EACzC,MAA0C;YAFzC,YAAG,EAAE,YAAG;QAIT,yCAAyC;QACzC,IAAI,GAAG,KAAK,GAAG,EAAE;YACf,OAAO,MAAM,CAAC;SACf;QAED,8CAA8C;QAC9C,IAAM,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;QACzC,IAAM,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;QACrD,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAEvC,OAAU,IAAI,MAAG,CAAC;IACpB,CAAC;IACH,qBAAC;AAAD,CAAC,AA9GD,IA8GC;AA9GY,wCAAc","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from 'ogma';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {NodeSizeExtrema} from './nodeAttributes';\nimport {EdgeWidthExtrema} from './edgeAttributes';\n\nexport const BASE_GREY = '#7f7f7f';\nexport const PALETTE = [\n '#9467bd',\n '#e377c2',\n '#1f77b4',\n '#17becf',\n '#2ca02c',\n '#bcbd22',\n '#d62728',\n '#ff7f0e',\n '#8c564b',\n '#c5b0d5',\n '#f7b6d2',\n '#aec7e8',\n '#9edae5',\n '#98df8a',\n '#dbdb8d',\n '#ff9896',\n '#ffbb78',\n '#c49c94'\n];\n\nexport class ItemAttributes {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }): void {\n if (rulesMap.color !== undefined) {\n this.colorsCache = new Map();\n }\n this._rulesMap = {\n color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,\n icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,\n image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,\n shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,\n size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,\n width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width\n };\n }\n\n /**\n * Return the color for a node when style color is auto\n */\n public static autoColor(value: string, ignoreCase?: boolean): string {\n if (!Tools.isDefined(value)) {\n return BASE_GREY;\n }\n return PALETTE[\n ItemAttributes.getRandomUniqueColorPaletteIndex(value, PALETTE.length, ignoreCase)\n ];\n }\n\n /**\n * Return a number from 0 to number of occurrence in a palette based on a property\n */\n private static getRandomUniqueColorPaletteIndex(\n input: string,\n modulo: number,\n ignoreCase: boolean | undefined\n ): number {\n if (ignoreCase) {\n input = input.toLowerCase();\n }\n return +('0x' + sha1(input).substr(-4)) % modulo;\n }\n\n /**\n * Get color of a type\n */\n public static getTypeColor(rule: StyleRule, type: string): string | null {\n if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {\n return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);\n }\n if (!Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {\n return rule.style.color;\n }\n return null;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyle(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min) {\n return '100%';\n }\n\n // calculate the linear function f(x) = ax + b\n const a = (higher - lower) / (max - min);\n const b = (lower * max - higher * min) / (max - min);\n const size = Math.floor(value * a + b);\n\n return `${size}%`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,8CAAwB;AAGxB,wCAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF;IAWE,wBAAY,QAOX;QAjBS,gBAAW,GAAsC,IAAI,GAAG,EAAE,CAAC;QAC3D,cAAS,GAOf,EAAE,CAAC;QAUL,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,gCAAO,GAAd,UAAe,QAOd;QACC,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;SAC9B;QACD,IAAI,CAAC,SAAS,GAAG;YACf,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,eAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK;YAC5E,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,eAAI,Q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n\nimport {StyleRule} from './styleRule';\nimport {NodeSizeExtrema} from './nodeAttributes';\nimport {EdgeWidthExtrema} from './edgeAttributes';\n\nexport const BASE_GREY = '#7f7f7f';\nexport const PALETTE = [\n '#9467bd',\n '#e377c2',\n '#1f77b4',\n '#17becf',\n '#2ca02c',\n '#bcbd22',\n '#d62728',\n '#ff7f0e',\n '#8c564b',\n '#c5b0d5',\n '#f7b6d2',\n '#aec7e8',\n '#9edae5',\n '#98df8a',\n '#dbdb8d',\n '#ff9896',\n '#ffbb78',\n '#c49c94'\n];\n\nexport class ItemAttributes {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }): void {\n if (rulesMap.color !== undefined) {\n this.colorsCache = new Map();\n }\n this._rulesMap = {\n color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,\n icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,\n image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,\n shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,\n size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,\n width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width\n };\n }\n\n /**\n * Return the color for a node when style color is auto\n */\n public static autoColor(value: string, ignoreCase?: boolean): string {\n if (!Tools.isDefined(value)) {\n return BASE_GREY;\n }\n return PALETTE[\n ItemAttributes.getRandomUniqueColorPaletteIndex(value, PALETTE.length, ignoreCase)\n ];\n }\n\n /**\n * Return a number from 0 to number of occurrence in a palette based on a property\n */\n private static getRandomUniqueColorPaletteIndex(\n input: string,\n modulo: number,\n ignoreCase: boolean | undefined\n ): number {\n if (ignoreCase) {\n input = input.toLowerCase();\n }\n return +('0x' + sha1(input).substr(-4)) % modulo;\n }\n\n /**\n * Get color of a type\n */\n public static getTypeColor(rule: StyleRule, type: string): string | null {\n if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {\n return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);\n }\n if (!Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {\n return rule.style.color;\n }\n return null;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyle(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min) {\n return '100%';\n }\n\n // calculate the linear function f(x) = ax + b\n const a = (higher - lower) / (max - min);\n const b = (lower * max - higher * min) / (max - min);\n const size = Math.floor(value * a + b);\n\n return `${size}%`;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAGb,8CAAwB;AAExB,wCAAqC;AACrC,wBAA6B;AAG7B,mDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B;AAED;IAAoC,kCAAc;I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aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,IAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AArND,CAAoC,+BAAc,GAqNjD;AArNY,wCAAc","sourcesContent":["'use strict';\nimport {Color} from 'ogma';\nimport {LkNodeData, OgmaNodeShape, IStyleImage, IStyleIcon} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private matchStyle(\n styleRules: Array<StyleRule>,\n itemData: LkNodeData,\n callback: (style: StyleRule) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let c = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n c = ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);\n } else {\n c = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n } else {\n c = rule.style.color;\n }\n break;\n }\n }\n colors.push(c);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n if ('icon' in rules[i].style) {\n result = {\n icon: {\n content: rules[i].style.icon.content,\n font: rules[i].style.icon.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in rules[i].style) {\n result = {\n image: {\n url:\n Tools.getType(rules[i].style.image.url) === 'imageUrl' ||\n Tools.getType(rules[i].style.image.url) === 'image'\n ? rules[i].style.image.url\n : Tools.getIn(itemData, rules[i].style.image.url.path),\n scale: rules[i].style.image.scale,\n fit: rules[i].style.image.fit,\n tile: rules[i].style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n this.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n this.matchStyle(this._rulesMap.size, itemData, (styleRule) => {\n const sizeStyle = styleRule.style.size;\n if (sizeStyle.type === 'autoRange') {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule);\n }\n } else {\n result = sizeStyle;\n }\n });\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n */\n public static getAutomaticRangeSize(value: number, rule: StyleRule): string {\n return this.getAutomaticRangeStyle(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAGb,8CAAwB;AAExB,wCAAqC;AACrC,wBAA6B;AAG7B,mDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B;AAED;IAAoC,kCAAc;IAChD,wBAAY,QAMX;eACC,kBAAM,QAAQ,CAAC;IACjB,CAAC;IAED;;OAEG;IACK,mCAAU,GAAlB,UACE,UAA4B,EAC5B,QAAoB,EACpB,QAAuC;QAEvC,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;SACR;QACD,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAChC,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC1C,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;gBACtC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxB,MAAM;aACP;SACF;IACH,CAAC;IAED;;OAEG;IACI,8BAAK,GAAZ,UAAa,QAAoB;QAC/B,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO,CAAC,0BAAS,CAAC,CAAC;SACpB;QACD,IAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5C,IAAM,WAAW,GAAG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CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;qBACzE;iBACF;qBAAM;oBACL,MAAM,GAAG,SAAS,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACW,oCAAqB,GAAnC,UAAoC,KAAa,EAAE,IAAe;QAChE,OAAO,IAAI,CAAC,sBAAsB,CAChC,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,4BAAG,GAAV,UACE,QAAoB;QAQpB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,IAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AArND,CAAoC,+BAAc,GAqNjD;AArNY,wCAAc","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkNodeData, OgmaNodeShape, IStyleImage, IStyleIcon} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private matchStyle(\n styleRules: Array<StyleRule>,\n itemData: LkNodeData,\n callback: (style: StyleRule) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let c = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n c = ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);\n } else {\n c = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n } else {\n c = rule.style.color;\n }\n break;\n }\n }\n colors.push(c);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n if ('icon' in rules[i].style) {\n result = {\n icon: {\n content: rules[i].style.icon.content,\n font: rules[i].style.icon.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in rules[i].style) {\n result = {\n image: {\n url:\n Tools.getType(rules[i].style.image.url) === 'imageUrl' ||\n Tools.getType(rules[i].style.image.url) === 'image'\n ? rules[i].style.image.url\n : Tools.getIn(itemData, rules[i].style.image.url.path),\n scale: rules[i].style.image.scale,\n fit: rules[i].style.image.fit,\n tile: rules[i].style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n this.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n this.matchStyle(this._rulesMap.size, itemData, (styleRule) => {\n const sizeStyle = styleRule.style.size;\n if (sizeStyle.type === 'autoRange') {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule);\n }\n } else {\n result = sizeStyle;\n }\n });\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n */\n public static getAutomaticRangeSize(value: number, rule: StyleRule): string {\n return this.getAutomaticRangeStyle(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
package/dist/tools/ogmaTool.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ogmaTool.js","sourceRoot":"","sources":["../../src/tools/ogmaTool.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,iCAA8B;AAC9B,+CAA2C;AAE3C;IAAA;IA2FA,CAAC;IA1FC;;;;OAIG;IACW,4BAAkB,GAAhC,UAAiC,KAAuC;QACtE,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,MAAc,EAAE,IAAkC;YACrE,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC5B,IAAM,eAAe,GACnB,UAAU,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,SAAS;oBACtD,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,aAAK,CAAC,8BAA8B,CAAC,IAAI,CAAC;oBAChE,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;gBACjC,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,GAAG,CAAC,EAAE;oBACxD,OA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cesContent":["'use strict';\nimport {Color, NodeList, Node, EdgeList, Edge} from 'ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {Tools} from './tools';\nimport {HTML_COLORS} from './colorPalette';\n\nexport class OgmaTools {\n /**\n * Get the amount of hidden neighbors from a list of nodes\n *\n * @param nodes\n */\n public static getHiddenNeighbors(nodes: NodeList<LkNodeData, LkEdgeData>): number {\n return nodes.reduce((result: number, node: Node<LkNodeData, LkEdgeData>) => {\n const statistics = node.getData('statistics');\n if (statistics !== undefined) {\n const hiddenNeighbors =\n statistics.degree !== undefined && !statistics.supernode\n ? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)\n : statistics.supernodeDegree;\n if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {\n return (result += hiddenNeighbors);\n }\n }\n return result;\n }, 0);\n }\n\n /**\n * Return the visible degree of a node without self connection (self edge)\n *\n * @param {Node} node\n * @return {number}\n */\n public static getDegreeWithoutSelfConnection(node: Node<LkNodeData, LkEdgeData>): number {\n return node.getAdjacentNodes({policy: 'exclude-sources', filter: 'all'}).size;\n }\n\n /**\n * Return true if the color tone is \"bright\"\n *\n * @param {string} color\n * @returns {boolean}\n */\n public static isBright(color: Color): boolean {\n if (color === null || !Tools.isStringFilled(color)) {\n return true;\n }\n const hexRegExp = /#[A-Fa-f0-9]{3,6}/;\n const rgbRegExp = /^rgb\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$/i;\n const rgbaRegExp = /^rgba\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|1|0?\\.\\d+)\\s*\\)$/i;\n let rgb: string;\n\n if (hexRegExp.test(color)) {\n if (color.length < 5) {\n color += color.slice(1);\n }\n color = color.replace('#', '');\n const r = parseInt(color[0].toString() + color[1].toString(), 16);\n const g = parseInt(color[2].toString() + color[3].toString(), 16);\n const b = parseInt(color[4].toString() + color[5].toString(), 16);\n rgb = `rgb(${r}, ${g}, ${b})`;\n } else if (\n rgbRegExp.test(color) ||\n rgbaRegExp.test(color) ||\n HTML_COLORS[color.toLowerCase()] !== undefined\n ) {\n rgb = Tools.isDefined(HTML_COLORS[color.toLowerCase()])\n ? HTML_COLORS[color.toLowerCase()]['rgb']\n : color;\n } else {\n return true;\n }\n\n const [r, g, b] = rgb\n .replace(/\\s/g, '')\n .match(/rgba?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})(,\\d{1,3})?\\)/)!\n .slice(1, 4);\n\n if (!Tools.isDefined(r) || !Tools.isDefined(g) || !Tools.isDefined(b)) {\n console.warn('The given color is not a valid rgb formatted color');\n return true;\n }\n return (+r * 299 + +g * 587 + +b * 114) / 1000 > 255 * 0.7;\n }\n\n public static isNode(\n item: Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData>\n ): item is Node<LkNodeData, LkEdgeData> {\n return item.isNode;\n }\n\n public static isNodeList(\n items: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>\n ): items is NodeList<LkNodeData, LkEdgeData> {\n return items.isNode;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ogmaTool.js","sourceRoot":"","sources":["../../src/tools/ogmaTool.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,iCAA8B;AAC9B,+CAA2C;AAE3C;IAAA;IA2FA,CAAC;IA1FC;;;;OAIG;IACW,4BAAkB,GAAhC,UAAiC,KAAuC;QACtE,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,MAAc,EAAE,IAAkC;YACrE,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,UAAU,KAAK,SA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,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;IAC7D,CAAC;IAEa,gBAAM,GAApB,UACE,IAAiE;QAEjE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEa,oBAAU,GAAxB,UACE,KAA0E;QAE1E,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IACH,gBAAC;AAAD,CAAC,AA3FD,IA2FC;AA3FY,8BAAS","sourcesContent":["'use strict';\nimport {Color, NodeList, Node, EdgeList, Edge} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {Tools} from './tools';\nimport {HTML_COLORS} from './colorPalette';\n\nexport class OgmaTools {\n /**\n * Get the amount of hidden neighbors from a list of nodes\n *\n * @param nodes\n */\n public static getHiddenNeighbors(nodes: NodeList<LkNodeData, LkEdgeData>): number {\n return nodes.reduce((result: number, node: Node<LkNodeData, LkEdgeData>) => {\n const statistics = node.getData('statistics');\n if (statistics !== undefined) {\n const hiddenNeighbors =\n statistics.degree !== undefined && !statistics.supernode\n ? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)\n : statistics.supernodeDegree;\n if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {\n return (result += hiddenNeighbors);\n }\n }\n return result;\n }, 0);\n }\n\n /**\n * Return the visible degree of a node without self connection (self edge)\n *\n * @param {Node} node\n * @return {number}\n */\n public static getDegreeWithoutSelfConnection(node: Node<LkNodeData, LkEdgeData>): number {\n return node.getAdjacentNodes({policy: 'exclude-sources', filter: 'all'}).size;\n }\n\n /**\n * Return true if the color tone is \"bright\"\n *\n * @param {string} color\n * @returns {boolean}\n */\n public static isBright(color: Color): boolean {\n if (color === null || !Tools.isStringFilled(color)) {\n return true;\n }\n const hexRegExp = /#[A-Fa-f0-9]{3,6}/;\n const rgbRegExp = /^rgb\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$/i;\n const rgbaRegExp = /^rgba\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|1|0?\\.\\d+)\\s*\\)$/i;\n let rgb: string;\n\n if (hexRegExp.test(color)) {\n if (color.length < 5) {\n color += color.slice(1);\n }\n color = color.replace('#', '');\n const r = parseInt(color[0].toString() + color[1].toString(), 16);\n const g = parseInt(color[2].toString() + color[3].toString(), 16);\n const b = parseInt(color[4].toString() + color[5].toString(), 16);\n rgb = `rgb(${r}, ${g}, ${b})`;\n } else if (\n rgbRegExp.test(color) ||\n rgbaRegExp.test(color) ||\n HTML_COLORS[color.toLowerCase()] !== undefined\n ) {\n rgb = Tools.isDefined(HTML_COLORS[color.toLowerCase()])\n ? HTML_COLORS[color.toLowerCase()]['rgb']\n : color;\n } else {\n return true;\n }\n\n const [r, g, b] = rgb\n .replace(/\\s/g, '')\n .match(/rgba?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})(,\\d{1,3})?\\)/)!\n .slice(1, 4);\n\n if (!Tools.isDefined(r) || !Tools.isDefined(g) || !Tools.isDefined(b)) {\n console.warn('The given color is not a valid rgb formatted color');\n return true;\n }\n return (+r * 299 + +g * 587 + +b * 114) / 1000 > 255 * 0.7;\n }\n\n public static isNode(\n item: Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData>\n ): item is Node<LkNodeData, LkEdgeData> {\n return item.isNode;\n }\n\n public static isNodeList(\n items: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>\n ): items is NodeList<LkNodeData, LkEdgeData> {\n return items.isNode;\n }\n}\n"]}
|
package/dist/tools/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sortBy from 'lodash/sortBy';
|
|
2
|
-
import { Node, NodeList } from 'ogma';
|
|
2
|
+
import { Node, NodeList } from '@linkurious/ogma';
|
|
3
3
|
import { LkNodeData, LkProperty } from '@linkurious/rest-client';
|
|
4
4
|
export { sortBy };
|
|
5
5
|
export declare const CAPTION_HEURISTIC: string[];
|
package/dist/tools/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/tools/tools.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AAEb,2DAAqC;AACrC,yDAAmC;AAI3B,iBAJD,gBAAM,CAIC;AACd,IAAM,WAAW,GAAG,0CAA0C,CAAC;AAC/D,IAAM,aAAa,GAAG,qCAAqC,CAAC;AAC/C,QAAA,iBAAiB,GAAa;IACzC,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,YAAY;CACb,CAAC;AAEF;IAAA;IA8WA,CAAC;IA7We,aAAO,GAArB,UAAsB,EAAW,EAAE,EAAW;QAC5C,OAAO,iBAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACW,eAAS,GAAvB,UAA2B,KAAQ;QACjC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;IAC/C,CAAC;IAED;;OAEG;IACW,cAAQ,GAAtB,UAAuB,KAAc,EAAE,QAA0B,EAAE,KAAS;QAAT,sBAAA,EAAA,SAAS;QAC1E,IAAM,MAAM,GAAG,QAAQ,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,EAAE,CAAC;SACX;QACD,IAAM,eAAe,GAAG,KAAG,KAAO,CAAC;QACnC,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE;YACvC,OAAO,eAAe,CAAC;SACxB;QACD,IAAM,UAAU,GAAG,KAA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,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACW,sBAAgB,GAA9B,UACE,QAAoB,EACpB,eAAyB,EACzB,cAAwB;QAExB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC5D,IAAI,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE;gBAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,cAAc,EAAE;oBAChF,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;iBACvE;qBAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;oBACnE,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC3C;aACF;iBAAM,IAAI,eAAe,EAAE;gBAC1B,OAAO,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;aAC/D;iBAAM;gBACL,OAAO,SAAS,CAAC;aAClB;SACF;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACW,gBAAU,GAAxB,UAAyB,CAAU;QACjC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IACH,YAAC;AAAD,CAAC,AA9WD,IA8WC;AA9WY,sBAAK","sourcesContent":["'use strict';\n\nimport isEqual from 'lodash/isEqual';\nimport sortBy from 'lodash/sortBy';\nimport {Node, NodeList} from 'ogma';\nimport {LkNodeData, LkProperty} from '@linkurious/rest-client';\n\nexport {sortBy};\nconst URL_PATTERN = /([a-zA-Z][a-zA-Z0-9\\+\\-\\.]*:\\/\\/[^\\s]+)/i;\nconst IMAGE_PATTERN = /\\S+\\.(gif|jpe?g|tiff|png|bmp|svg)$/i;\nexport const CAPTION_HEURISTIC: string[] = [\n 'label',\n 'Label',\n 'name',\n 'Name',\n 'title',\n 'Title',\n 'rdfs:label'\n];\n\nexport class Tools {\n public static isEqual(v1: unknown, v2: unknown): boolean {\n return isEqual(v1, v2);\n }\n\n /**\n * Check that a value is defined : not null and not undefined\n *\n * @param {any} value\n * @return {boolean}\n */\n public static isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n }\n\n /**\n * Truncate a text\n */\n public static truncate(value: unknown, position: 'middle' | 'end', limit = 0): string {\n const suffix = '\\u2026';\n if (!Tools.isDefined(value)) {\n return ``;\n }\n const valueToTruncate = `${value}`;\n if (valueToTruncate.length <= limit + 1) {\n return valueToTruncate;\n }\n const fixedLimit = limit - 1;\n switch (position) {\n case 'middle':\n return (\n valueToTruncate.substring(0, Math.ceil(fixedLimit / 2)) +\n suffix +\n valueToTruncate.substring(valueToTruncate.length - Math.floor(fixedLimit / 2))\n );\n\n case 'end':\n return valueToTruncate.substring(0, fixedLimit) + suffix;\n }\n }\n\n /**\n * Return a value from a nested object depending on a keyPath\n */\n public static getIn(ref: any, path: Array<string | number>): any {\n return path.reduce((p, c) => (p && p[c] !== undefined ? p[c] : undefined), ref);\n }\n\n /**\n * Return a clone of an object\n */\n public static clone(o: any) {\n return typeof o === 'object'\n ? JSON.parse(\n JSON.stringify(o, (k, v) => {\n return v instanceof Set ? {} : v;\n })\n )\n : o;\n }\n\n /**\n * Get the amount of hidden neighbors from a list of nodes\n *\n * @param nodes\n */\n public static getHiddenNeighbors(nodes: NodeList<LkNodeData>): number {\n return nodes.reduce((result: number, node: Node<LkNodeData>) => {\n const statistics = node.getData('statistics');\n if (statistics !== undefined) {\n const hiddenNeighbors =\n statistics.degree !== undefined && !statistics.supernode\n ? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)\n : statistics.supernodeDegree;\n if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {\n return (result += hiddenNeighbors);\n }\n }\n return result;\n }, 0);\n }\n\n /**\n * Return the visible degree of a node without self connection (self edge)\n *\n * @param {Node} node\n * @return {number}\n */\n public static getDegreeWithoutSelfConnection(node: Node<LkNodeData>): number {\n return node.getAdjacentNodes({policy: 'exclude-sources', filter: 'raw'}).size;\n }\n\n /**\n * Return a formatted version of a number\n */\n public static formatNumber(number: number): string {\n let div = 1;\n let suffix = '';\n const sign = number < 0 ? '-' : '';\n number = Math.abs(number);\n\n if (number >= 1000000) {\n div = 1000000;\n suffix = 'M';\n } else if (number >= 1000) {\n div = 1000;\n suffix = 'k';\n }\n const nn = number / div;\n // if there is a decimal value and nn < 10\n if (nn < 10 && nn % 1 !== 0) {\n return sign + nn.toFixed(1) + suffix;\n } else {\n return sign + Math.floor(nn) + suffix;\n }\n }\n\n /**\n * Return true if a string is not composed only by invisible char\n *\n * @param {string} value\n * @return {boolean}\n */\n public static isStringFilled(value: string): boolean {\n return value.trim() !== '';\n }\n\n public static getValueFromLkProperty(property: LkProperty): null | string | number | boolean {\n if (typeof property === 'object' && 'type' in property) {\n if (!('original' in property) && !('value' in property)) {\n return null;\n }\n if ('original' in property) {\n return `${property.original}`;\n }\n if ('value' in property) {\n return Tools.formatDate(\n new Date(\n new Date(property.value).getTime() + Tools.timezoneToMilliseconds(property.timezone)\n ).toISOString()\n );\n }\n }\n return property;\n }\n\n /**\n * Return a formatted date as a string\n */\n public static formatDate(\n isoString: string,\n isDatetime?: boolean,\n timezone?: number\n ): string | null {\n // The date received from the server will be always in seconds\n let offsetDate: string | number = isoString;\n if (timezone !== undefined) {\n offsetDate = new Date(isoString).getTime() + timezone * 1000;\n }\n const dateObject = new Date(offsetDate);\n\n if (isNaN(dateObject.getUTCFullYear())) {\n return null;\n }\n let formattedDate =\n dateObject.getFullYear() +\n '-' +\n ((dateObject.getUTCMonth() + 1).toString().length === 1\n ? '0' + (dateObject.getUTCMonth() + 1)\n : dateObject.getUTCMonth() + 1) +\n '-' +\n (dateObject.getUTCDate().toString().length === 1\n ? '0' + dateObject.getUTCDate()\n : dateObject.getUTCDate());\n\n if (isDatetime) {\n formattedDate +=\n ' ' +\n (dateObject.getUTCHours().toString().length === 1\n ? '0' + dateObject.getUTCHours()\n : dateObject.getUTCHours()) +\n ':' +\n (dateObject.getUTCMinutes().toString().length === 1\n ? '0' + dateObject.getUTCMinutes()\n : dateObject.getUTCMinutes()) +\n ':' +\n (dateObject.getUTCSeconds().toString().length === 1\n ? '0' + dateObject.getUTCSeconds()\n : dateObject.getUTCSeconds());\n }\n return formattedDate;\n }\n\n /**\n * From \"+03:00\" return the offset in milliseconds\n * @param timezone\n */\n public static timezoneToMilliseconds(timezone: string | undefined): number {\n if (timezone === undefined) {\n return 0;\n }\n if (timezone === 'Z') {\n return 0;\n }\n const sign = timezone[0];\n const [hours, minutes] = timezone.slice(1).split(':');\n return sign === '+'\n ? this.sanitizeFormattedNumber(hours) * 3.6e6 + this.sanitizeFormattedNumber(minutes) * 60000\n : (this.sanitizeFormattedNumber(hours) * 3.6e6 +\n this.sanitizeFormattedNumber(minutes) * 60000) *\n -1;\n }\n\n public static sanitizeFormattedNumber(str: string): number {\n if (str.length === 2 && str.startsWith('0')) {\n return Tools.parseNumber(str[1]);\n }\n return Tools.parseNumber(str);\n }\n\n /**\n * Return true if `n` is (or can be parsed as) a float, but is NOT an integer\n *\n * @param {any} n\n * @return {number} a number (NaN is `n` cannot be parsed as a number)\n */\n public static parseNumber(n: unknown): number {\n // string: try to parse as number (allow ',' as decimal separator)\n if (typeof n === 'string') {\n // prevent the empty string to be parsed as 0\n if (n.trim() === '') {\n return Number.NaN;\n }\n\n n = +n.replace(',', '.').replace(' ', '');\n }\n\n // (the string could not be parsed) OR (it was neither string nor number)\n if (typeof n !== 'number') {\n return Number.NaN;\n }\n\n // false for NaN, +Infinity, -Infinity\n if (!isFinite(n)) {\n return Number.NaN;\n }\n\n return n;\n }\n\n /**\n * Return an Array without duplicated keys\n *\n * @param {Array<any>} arr\n * @param {string} key\n * @return {Array<any>}\n */\n public static uniqBy(arr: Array<any>, key?: string): Array<any> {\n const seen = new Set();\n if (key) {\n const result = [];\n for (let i = 0; i < arr.length; ++i) {\n if (arr[i] && arr[i][key] && !seen.has(arr[i][key])) {\n seen.add(arr[i][key]);\n result.push(arr[i]);\n } else if (!arr[i][key]) {\n result.push(arr[i]);\n }\n }\n return result;\n }\n return typeof arr[0] === 'object'\n ? Array.from(new Set(arr.map((v) => JSON.stringify(v)))).map((v) => JSON.parse(v))\n : Array.from(new Set(arr));\n }\n\n /**\n * Return 'image' or 'url' depending on the given string\n *\n * @param {string} value\n * @return {\"image\" | \"url\"}\n */\n public static getType(value: string): 'image' | 'url' | 'imageUrl' | undefined {\n if (Tools.isImage(value) && Tools.isUrl(value)) {\n return 'imageUrl';\n }\n\n if (Tools.isImage(value)) {\n return 'image';\n }\n\n if (Tools.isUrl(value)) {\n return 'url';\n }\n\n return undefined;\n }\n\n /**\n * Return true if the given string is an url that match the schema handled by LKE\n *\n * @param {string} value\n * @return {boolean}\n */\n private static isUrl(value: string): boolean {\n return URL_PATTERN.test(value);\n }\n\n /**\n * Return true if the given string is an url with an image extension\n *\n * @param {string} value\n * @return {boolean}\n */\n private static isImage(value: string): boolean {\n return IMAGE_PATTERN.test(value);\n }\n\n /**\n * Return true if a value is not undefined, not null and not an empty string\n */\n public static valueExists(value: LkProperty): boolean {\n return Tools.isDefined(value) && (typeof value !== 'string' || Tools.isStringFilled(value));\n }\n\n /**\n * Return true if `n` is (or can be parsed as) a number\n */\n public static isNumber(n: unknown): boolean {\n n = Tools.parseNumber(n);\n return Tools.isDefined(n) && n === n;\n }\n\n /**\n * return the correct property value\n */\n public static getPropertyValue(\n property: LkProperty,\n invalidAsString?: boolean,\n formattedDates?: boolean\n ): undefined | null | string | number | boolean | Array<string> {\n if (typeof property === 'object' && !Array.isArray(property)) {\n if (!('status' in property)) {\n if ((property.type === 'date' || property.type === 'datetime') && formattedDates) {\n return Tools.formatDate(property.value, property.type === 'datetime');\n } else if (property.type === 'date' || property.type === 'datetime') {\n return new Date(property.value).getTime();\n }\n } else if (invalidAsString) {\n return 'original' in property ? property.original : undefined;\n } else {\n return undefined;\n }\n }\n return property;\n }\n\n /**\n * Parse the given value and return a float number or NaN\n *\n * @param {any} n\n * @return {number}\n */\n public static parseFloat(n: unknown): number {\n return Tools.parseNumber(n);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/tools/tools.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AAEb,2DAAqC;AACrC,yDAAmC;AAI3B,iBAJD,gBAAM,CAIC;AACd,IAAM,WAAW,GAAG,0CAA0C,CAAC;AAC/D,IAAM,aAAa,GAAG,qCAAqC,CAAC;AAC/C,QAAA,iBAAiB,GAAa;IACzC,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,YAAY;CACb,CAAC;AAEF;IAAA;IA8WA,CAAC;IA7We,aAAO,GAArB,UAAsB,EAAW,EAAE,EAAW;QAC5C,OAAO,iBAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACW,eAAS,GAAvB,UAA2B,KAAQ;QACjC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;IAC/C,CAAC;IAED;;OAEG;IACW,cAAQ,GAAtB,UAAuB,KAAc,EAAE,QAA0B,EAAE,KAAS;QAAT,sBAAA,EAAA,SAAS;QAC1E,IAAM,MAAM,GAAG,QAAQ,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,EAAE,CAAC;SACX;QACD,IAAM,eAAe,GAAG,KAAG,KAAO,CAAC;QACnC,IAAI,eAAe,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE;YACvC,OAAO,eA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,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACW,sBAAgB,GAA9B,UACE,QAAoB,EACpB,eAAyB,EACzB,cAAwB;QAExB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC5D,IAAI,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE;gBAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,cAAc,EAAE;oBAChF,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;iBACvE;qBAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;oBACnE,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC3C;aACF;iBAAM,IAAI,eAAe,EAAE;gBAC1B,OAAO,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;aAC/D;iBAAM;gBACL,OAAO,SAAS,CAAC;aAClB;SACF;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACW,gBAAU,GAAxB,UAAyB,CAAU;QACjC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IACH,YAAC;AAAD,CAAC,AA9WD,IA8WC;AA9WY,sBAAK","sourcesContent":["'use strict';\n\nimport isEqual from 'lodash/isEqual';\nimport sortBy from 'lodash/sortBy';\nimport {Node, NodeList} from '@linkurious/ogma';\nimport {LkNodeData, LkProperty} from '@linkurious/rest-client';\n\nexport {sortBy};\nconst URL_PATTERN = /([a-zA-Z][a-zA-Z0-9\\+\\-\\.]*:\\/\\/[^\\s]+)/i;\nconst IMAGE_PATTERN = /\\S+\\.(gif|jpe?g|tiff|png|bmp|svg)$/i;\nexport const CAPTION_HEURISTIC: string[] = [\n 'label',\n 'Label',\n 'name',\n 'Name',\n 'title',\n 'Title',\n 'rdfs:label'\n];\n\nexport class Tools {\n public static isEqual(v1: unknown, v2: unknown): boolean {\n return isEqual(v1, v2);\n }\n\n /**\n * Check that a value is defined : not null and not undefined\n *\n * @param {any} value\n * @return {boolean}\n */\n public static isDefined<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n }\n\n /**\n * Truncate a text\n */\n public static truncate(value: unknown, position: 'middle' | 'end', limit = 0): string {\n const suffix = '\\u2026';\n if (!Tools.isDefined(value)) {\n return ``;\n }\n const valueToTruncate = `${value}`;\n if (valueToTruncate.length <= limit + 1) {\n return valueToTruncate;\n }\n const fixedLimit = limit - 1;\n switch (position) {\n case 'middle':\n return (\n valueToTruncate.substring(0, Math.ceil(fixedLimit / 2)) +\n suffix +\n valueToTruncate.substring(valueToTruncate.length - Math.floor(fixedLimit / 2))\n );\n\n case 'end':\n return valueToTruncate.substring(0, fixedLimit) + suffix;\n }\n }\n\n /**\n * Return a value from a nested object depending on a keyPath\n */\n public static getIn(ref: any, path: Array<string | number>): any {\n return path.reduce((p, c) => (p && p[c] !== undefined ? p[c] : undefined), ref);\n }\n\n /**\n * Return a clone of an object\n */\n public static clone(o: any) {\n return typeof o === 'object'\n ? JSON.parse(\n JSON.stringify(o, (k, v) => {\n return v instanceof Set ? {} : v;\n })\n )\n : o;\n }\n\n /**\n * Get the amount of hidden neighbors from a list of nodes\n *\n * @param nodes\n */\n public static getHiddenNeighbors(nodes: NodeList<LkNodeData>): number {\n return nodes.reduce((result: number, node: Node<LkNodeData>) => {\n const statistics = node.getData('statistics');\n if (statistics !== undefined) {\n const hiddenNeighbors =\n statistics.degree !== undefined && !statistics.supernode\n ? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)\n : statistics.supernodeDegree;\n if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {\n return (result += hiddenNeighbors);\n }\n }\n return result;\n }, 0);\n }\n\n /**\n * Return the visible degree of a node without self connection (self edge)\n *\n * @param {Node} node\n * @return {number}\n */\n public static getDegreeWithoutSelfConnection(node: Node<LkNodeData>): number {\n return node.getAdjacentNodes({policy: 'exclude-sources', filter: 'raw'}).size;\n }\n\n /**\n * Return a formatted version of a number\n */\n public static formatNumber(number: number): string {\n let div = 1;\n let suffix = '';\n const sign = number < 0 ? '-' : '';\n number = Math.abs(number);\n\n if (number >= 1000000) {\n div = 1000000;\n suffix = 'M';\n } else if (number >= 1000) {\n div = 1000;\n suffix = 'k';\n }\n const nn = number / div;\n // if there is a decimal value and nn < 10\n if (nn < 10 && nn % 1 !== 0) {\n return sign + nn.toFixed(1) + suffix;\n } else {\n return sign + Math.floor(nn) + suffix;\n }\n }\n\n /**\n * Return true if a string is not composed only by invisible char\n *\n * @param {string} value\n * @return {boolean}\n */\n public static isStringFilled(value: string): boolean {\n return value.trim() !== '';\n }\n\n public static getValueFromLkProperty(property: LkProperty): null | string | number | boolean {\n if (typeof property === 'object' && 'type' in property) {\n if (!('original' in property) && !('value' in property)) {\n return null;\n }\n if ('original' in property) {\n return `${property.original}`;\n }\n if ('value' in property) {\n return Tools.formatDate(\n new Date(\n new Date(property.value).getTime() + Tools.timezoneToMilliseconds(property.timezone)\n ).toISOString()\n );\n }\n }\n return property;\n }\n\n /**\n * Return a formatted date as a string\n */\n public static formatDate(\n isoString: string,\n isDatetime?: boolean,\n timezone?: number\n ): string | null {\n // The date received from the server will be always in seconds\n let offsetDate: string | number = isoString;\n if (timezone !== undefined) {\n offsetDate = new Date(isoString).getTime() + timezone * 1000;\n }\n const dateObject = new Date(offsetDate);\n\n if (isNaN(dateObject.getUTCFullYear())) {\n return null;\n }\n let formattedDate =\n dateObject.getFullYear() +\n '-' +\n ((dateObject.getUTCMonth() + 1).toString().length === 1\n ? '0' + (dateObject.getUTCMonth() + 1)\n : dateObject.getUTCMonth() + 1) +\n '-' +\n (dateObject.getUTCDate().toString().length === 1\n ? '0' + dateObject.getUTCDate()\n : dateObject.getUTCDate());\n\n if (isDatetime) {\n formattedDate +=\n ' ' +\n (dateObject.getUTCHours().toString().length === 1\n ? '0' + dateObject.getUTCHours()\n : dateObject.getUTCHours()) +\n ':' +\n (dateObject.getUTCMinutes().toString().length === 1\n ? '0' + dateObject.getUTCMinutes()\n : dateObject.getUTCMinutes()) +\n ':' +\n (dateObject.getUTCSeconds().toString().length === 1\n ? '0' + dateObject.getUTCSeconds()\n : dateObject.getUTCSeconds());\n }\n return formattedDate;\n }\n\n /**\n * From \"+03:00\" return the offset in milliseconds\n * @param timezone\n */\n public static timezoneToMilliseconds(timezone: string | undefined): number {\n if (timezone === undefined) {\n return 0;\n }\n if (timezone === 'Z') {\n return 0;\n }\n const sign = timezone[0];\n const [hours, minutes] = timezone.slice(1).split(':');\n return sign === '+'\n ? this.sanitizeFormattedNumber(hours) * 3.6e6 + this.sanitizeFormattedNumber(minutes) * 60000\n : (this.sanitizeFormattedNumber(hours) * 3.6e6 +\n this.sanitizeFormattedNumber(minutes) * 60000) *\n -1;\n }\n\n public static sanitizeFormattedNumber(str: string): number {\n if (str.length === 2 && str.startsWith('0')) {\n return Tools.parseNumber(str[1]);\n }\n return Tools.parseNumber(str);\n }\n\n /**\n * Return true if `n` is (or can be parsed as) a float, but is NOT an integer\n *\n * @param {any} n\n * @return {number} a number (NaN is `n` cannot be parsed as a number)\n */\n public static parseNumber(n: unknown): number {\n // string: try to parse as number (allow ',' as decimal separator)\n if (typeof n === 'string') {\n // prevent the empty string to be parsed as 0\n if (n.trim() === '') {\n return Number.NaN;\n }\n\n n = +n.replace(',', '.').replace(' ', '');\n }\n\n // (the string could not be parsed) OR (it was neither string nor number)\n if (typeof n !== 'number') {\n return Number.NaN;\n }\n\n // false for NaN, +Infinity, -Infinity\n if (!isFinite(n)) {\n return Number.NaN;\n }\n\n return n;\n }\n\n /**\n * Return an Array without duplicated keys\n *\n * @param {Array<any>} arr\n * @param {string} key\n * @return {Array<any>}\n */\n public static uniqBy(arr: Array<any>, key?: string): Array<any> {\n const seen = new Set();\n if (key) {\n const result = [];\n for (let i = 0; i < arr.length; ++i) {\n if (arr[i] && arr[i][key] && !seen.has(arr[i][key])) {\n seen.add(arr[i][key]);\n result.push(arr[i]);\n } else if (!arr[i][key]) {\n result.push(arr[i]);\n }\n }\n return result;\n }\n return typeof arr[0] === 'object'\n ? Array.from(new Set(arr.map((v) => JSON.stringify(v)))).map((v) => JSON.parse(v))\n : Array.from(new Set(arr));\n }\n\n /**\n * Return 'image' or 'url' depending on the given string\n *\n * @param {string} value\n * @return {\"image\" | \"url\"}\n */\n public static getType(value: string): 'image' | 'url' | 'imageUrl' | undefined {\n if (Tools.isImage(value) && Tools.isUrl(value)) {\n return 'imageUrl';\n }\n\n if (Tools.isImage(value)) {\n return 'image';\n }\n\n if (Tools.isUrl(value)) {\n return 'url';\n }\n\n return undefined;\n }\n\n /**\n * Return true if the given string is an url that match the schema handled by LKE\n *\n * @param {string} value\n * @return {boolean}\n */\n private static isUrl(value: string): boolean {\n return URL_PATTERN.test(value);\n }\n\n /**\n * Return true if the given string is an url with an image extension\n *\n * @param {string} value\n * @return {boolean}\n */\n private static isImage(value: string): boolean {\n return IMAGE_PATTERN.test(value);\n }\n\n /**\n * Return true if a value is not undefined, not null and not an empty string\n */\n public static valueExists(value: LkProperty): boolean {\n return Tools.isDefined(value) && (typeof value !== 'string' || Tools.isStringFilled(value));\n }\n\n /**\n * Return true if `n` is (or can be parsed as) a number\n */\n public static isNumber(n: unknown): boolean {\n n = Tools.parseNumber(n);\n return Tools.isDefined(n) && n === n;\n }\n\n /**\n * return the correct property value\n */\n public static getPropertyValue(\n property: LkProperty,\n invalidAsString?: boolean,\n formattedDates?: boolean\n ): undefined | null | string | number | boolean | Array<string> {\n if (typeof property === 'object' && !Array.isArray(property)) {\n if (!('status' in property)) {\n if ((property.type === 'date' || property.type === 'datetime') && formattedDates) {\n return Tools.formatDate(property.value, property.type === 'datetime');\n } else if (property.type === 'date' || property.type === 'datetime') {\n return new Date(property.value).getTime();\n }\n } else if (invalidAsString) {\n return 'original' in property ? property.original : undefined;\n } else {\n return undefined;\n }\n }\n return property;\n }\n\n /**\n * Parse the given value and return a float number or NaN\n *\n * @param {any} n\n * @return {number}\n */\n public static parseFloat(n: unknown): number {\n return Tools.parseNumber(n);\n }\n}\n"]}
|