@linkurious/ogma-linkurious-parser 4.1.3 → 4.1.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"transformations.js","sourceRoot":"","sources":["../../../src/ogma/features/transformations.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAgBb,iDAAsD;AAEtD,MAAM,wBAAwB,GAS1B;IACF,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE;QACL,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,OAAO;KACd;IACD,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,MAAa,kBAAkB;IAO7B,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACU,kBAAkB;;YAC7B,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE;gBACrC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC;oBAC/D,wBAAwB,EAAE,IAAI;oBAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;wBACjB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;oBACjD,CAAC;oBACD,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;oBAC/C,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;wBACnB,OAAO;4BACL,IAAI,EAAE;gCACJ,UAAU,EAAE;oCACV,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iCACvC;6BACF;yBACF,CAAC;oBACJ,CAAC;iBACF,CAAC,CAAC;aACJ;iBAAM;gBACL,MAAM,IAAI,CAAC,cAAc,CAA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,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC;SACtC;IACH,CAAC;CACF;AA3ED,gDA2EC","sourcesContent":["'use strict';\n\nimport {GenericObject, IEdgeGroupStyle, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {\n Edge,\n EdgeAttributesValue,\n EdgeExtremity,\n EdgeStyle,\n EdgeType,\n PixelSize,\n StyleRule,\n Transformation\n} from '@linkurious/ogma';\n\nimport {LKOgma} from '../index';\n\nimport {LKE_NODE_GROUPING_EDGE} from './nodeGrouping';\n\nconst DEFAULT_EDGE_GROUP_STYLE: {\n color: string;\n shape: {\n body?: EdgeType;\n head?: EdgeExtremity;\n tail?: EdgeExtremity;\n style?: EdgeStyle;\n };\n width: PixelSize;\n} = {\n color: '#000000',\n shape: {\n style: 'dashed',\n head: 'arrow'\n },\n width: 1.5\n};\n\nexport class TransformationsViz {\n private _ogma: LKOgma;\n public groupedEdges: GenericObject<boolean>;\n public edgeGroupStyle!: IEdgeGroupStyle;\n public transformation!: Transformation<LkNodeData, LkEdgeData>;\n public edgeGroupingStyleRule!: StyleRule<LkNodeData, LkEdgeData>;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.groupedEdges = {};\n }\n\n /**\n * create an edge grouping transformation by edge type\n */\n public async initTransformation(): Promise<void> {\n if (this.transformation === undefined) {\n this.transformation = this._ogma.transformations.addEdgeGrouping({\n separateEdgesByDirection: true,\n selector: (edge) => {\n return this.groupedEdges[edge.getData('type')];\n },\n groupIdFunction: (edge) => edge.getData('type'),\n generator: (edges) => {\n return {\n data: {\n properties: {\n originalType: edges.getData('type')[0]\n }\n }\n };\n }\n });\n } else {\n await this.transformation.refresh();\n }\n }\n\n /**\n * init edge grouping style\n */\n public initEdgeGroupingStyle(): void {\n this.edgeGroupingStyleRule = this._ogma.styles.addRule({\n edgeAttributes: {\n ...DEFAULT_EDGE_GROUP_STYLE,\n ...(this.edgeGroupStyle as EdgeAttributesValue<LkEdgeData, LkNodeData>),\n text: {\n content: (edge: Edge<LkEdgeData> | undefined): string | undefined => {\n // check it the edge is virtual and was not created by node grouping\n if (\n edge !== undefined &&\n edge.getSubEdges() !== null &&\n edge.getData('type') !== LKE_NODE_GROUPING_EDGE\n ) {\n const size = edge.getSubEdges()!.filter((e) => !e.hasClass('filtered')).size;\n return `${edge.getData(['properties', 'originalType'])} (${size})`;\n }\n },\n style: 'bold'\n }\n },\n edgeSelector: (edge) =>\n edge.isVirtual() &&\n edge.getSubEdges() &&\n edge.getSubEdges()!.filter((e) => !e.hasClass('filtered')).size > 0 &&\n edge.getData('type') !== LKE_NODE_GROUPING_EDGE,\n edgeDependencies: {self: {data: true}}\n });\n }\n\n public refreshEdgeGroupingStyle(): void {\n if (this.edgeGroupingStyleRule !== undefined) {\n this.edgeGroupingStyleRule.refresh();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"transformations.js","sourceRoot":"","sources":["../../../src/ogma/features/transformations.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAgBb,iDAAsD;AAEtD,MAAM,wBAAwB,GAS1B;IACF,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE;QACL,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,OAAO;KACd;IACD,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,MAAa,kBAAkB;IAO7B,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACU,kBAAkB;;YAC7B,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;gBACtC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC;oBAC/D,wBAAwB,EAAE,IAAI;oBAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;wBACjB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC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AAE;gBAChB,IAAI,CAAC,WAAW,EAAE;gBAClB,IAAI,CAAC,WAAW,EAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;gBACnE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,qCAAsB;YACjD,gBAAgB,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,EAAC;SACvC,CAAC,CAAC;IACL,CAAC;IAEM,wBAAwB;QAC7B,IAAI,IAAI,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AA3ED,gDA2EC","sourcesContent":["'use strict';\n\nimport {GenericObject, IEdgeGroupStyle, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {\n Edge,\n EdgeAttributesValue,\n EdgeExtremity,\n EdgeStyle,\n EdgeType,\n PixelSize,\n StyleRule,\n Transformation\n} from '@linkurious/ogma';\n\nimport {LKOgma} from '../index';\n\nimport {LKE_NODE_GROUPING_EDGE} from './nodeGrouping';\n\nconst DEFAULT_EDGE_GROUP_STYLE: {\n color: string;\n shape: {\n body?: EdgeType;\n head?: EdgeExtremity;\n tail?: EdgeExtremity;\n style?: EdgeStyle;\n };\n width: PixelSize;\n} = {\n color: '#000000',\n shape: {\n style: 'dashed',\n head: 'arrow'\n },\n width: 1.5\n};\n\nexport class TransformationsViz {\n private _ogma: LKOgma;\n public groupedEdges: GenericObject<boolean>;\n public edgeGroupStyle!: IEdgeGroupStyle;\n public transformation!: Transformation<LkNodeData, LkEdgeData>;\n public edgeGroupingStyleRule!: StyleRule<LkNodeData, LkEdgeData>;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.groupedEdges = {};\n }\n\n /**\n * create an edge grouping transformation by edge type\n */\n public async initTransformation(): Promise<void> {\n if (this.transformation === undefined) {\n this.transformation = this._ogma.transformations.addEdgeGrouping({\n separateEdgesByDirection: true,\n selector: (edge) => {\n return this.groupedEdges[edge.getData('type')];\n },\n groupIdFunction: (edge) => edge.getData('type'),\n generator: (edges) => {\n return {\n data: {\n properties: {\n originalType: edges.getData('type')[0]\n }\n }\n };\n }\n });\n } else {\n await this.transformation.refresh();\n }\n }\n\n /**\n * init edge grouping style\n */\n public initEdgeGroupingStyle(): void {\n this.edgeGroupingStyleRule = this._ogma.styles.addRule({\n edgeAttributes: {\n ...DEFAULT_EDGE_GROUP_STYLE,\n ...(this.edgeGroupStyle as EdgeAttributesValue<LkEdgeData, LkNodeData>),\n text: {\n content: (edge: Edge<LkEdgeData> | undefined): string | undefined => {\n // check it the edge is virtual and was not created by node grouping\n if (\n edge !== undefined &&\n edge.getSubEdges() !== null &&\n edge.getData('type') !== LKE_NODE_GROUPING_EDGE\n ) {\n const size = edge.getSubEdges()!.filter((e) => !e.hasClass('filtered')).size;\n return `${edge.getData(['properties', 'originalType'])} (${size})`;\n }\n },\n style: 'bold'\n }\n },\n edgeSelector: (edge) =>\n edge.isVirtual() &&\n edge.getSubEdges() &&\n edge.getSubEdges()!.filter((e) => !e.hasClass('filtered')).size > 0 &&\n edge.getData('type') !== LKE_NODE_GROUPING_EDGE,\n edgeDependencies: {self: {data: true}}\n });\n }\n\n public refreshEdgeGroupingStyle(): void {\n if (this.edgeGroupingStyleRule !== undefined) {\n this.edgeGroupingStyleRule.refresh();\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ogma/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAUiC;AACjC,4DAW0B;AAE1B,0BAA8B;AAC9B,0CAAqC;AAErC,8CAA4C;AAC5C,gEAA8D;AAC9D,kDAAgD;AAChD,kDAA0C;AAE1C,0DAAmE;AAEnE,yCAAiD;AAAzC,6GAAA,OAAO,OAAQ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,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC5D,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACpB;IACH,CAAC;IAED;;OAEG;IACI,cAAc;QACnB,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,aAAa,CAAC,aAA2B,EAAE,IAAc,EAAE,OAAgB;QAChF,IAAI,aAAa,EAAE;YACjB,0GAA0G;YAC1G,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;SACrC;QACD,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,CAAC,UAAU,iCACV,IAAI,CAAC,cAAc,CAAC,OAAO,KAC9B,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,IACtC,CAAC;SACJ;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;CACF;AAxUD,wBAwUC","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 NodeId,\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';\nimport {NodeGroupingTransformation} from './features/nodeGrouping';\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 const FORCE_LAYOUT_CONFIG = {\n steps: 40,\n alignSiblings: true,\n charge: 5,\n theta: 0.34,\n duration: ANIMATION_DURATION\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 // Node Grouping transformation instance\n public LkNodeGroupingTransformation!: NodeGroupingTransformation;\n private _reactive!: RxViz;\n\n constructor(private _configuration: IOgmaConfig, _baseUrl?: string) {\n // set Ogma global configuration\n super(_configuration);\n Object.setPrototypeOf(this, new.target.prototype);\n this.initOgmaLinkuriousParser(true, _baseUrl);\n }\n\n /**\n * Initialize the Ogma instance with the configuration and the base url\n * @param init used to know if the instance is initialized for the first time (used in setConfigOgma)\n * @param baseUrl base url used for relative image urls\n * @private\n */\n private initOgmaLinkuriousParser(init?: boolean, baseUrl?: string): 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, init, baseUrl);\n this.LKTransformation = new TransformationsViz(this);\n this.LkNodeGroupingTransformation = new NodeGroupingTransformation(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, baseUrl?: string): void {\n this.LKStyles = new StylesViz(this, {\n node: configuration?.options?.styles?.node || {},\n edge: configuration?.options?.styles?.edge || {},\n baseUrl: baseUrl\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): Promise<void> {\n await 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 await this.LKCaptions.initVizCaptions({\n node: visualization.nodeFields.captions || {},\n edge: visualization.edgeFields.captions || {}\n });\n this.LKTransformation.groupedEdges = visualization.edgeGrouping;\n await 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 addEdges(edges: Array<RawEdge<LkEdgeData>>, options?: AddItemOptions): Promise<EdgeList> {\n return super.addEdges(edges, {...options, ignoreInvalid: true});\n }\n\n /**\n * Return the list of non filtered nodes\n */\n public getNonFilteredNodes(items?: Array<NodeId>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => !i.hasClass('filtered'))\n : // take only none virtual nodes\n this.getNodes('raw').filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered nodes\n * @param items items to check if they are filtered\n * @param filter type of nodes to check if they are filtered ( nodes that are visible, raw nodes (none virtual) or all nodes)\n */\n public getFilteredNodes(\n items?: Array<NodeId>,\n filter: 'visible' | 'raw' | 'all' = 'raw'\n ): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => i.hasClass('filtered'))\n : this.getNodes(filter).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(\n items?: Array<any>,\n filter: 'visible' | 'raw' | 'all' = 'raw'\n ): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => i.hasClass('filtered'))\n : this.getEdges(filter).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, baseUrl?: string): void {\n if (configuration) {\n // here we make sure that the internal config object is updated and we have the correct one when resetting\n this._configuration = configuration;\n }\n if (!init) {\n this.setOptions({\n ...this._configuration.options,\n renderer: this._configuration.renderer\n });\n }\n this.setStyles(this._configuration, baseUrl);\n this.setCaptions(this._configuration);\n }\n}\n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C;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,UAAU,iCACV,IAAI,CAAC,cAAc,CAAC,OAAO,KAC9B,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,IACtC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;CACF;AAxUD,wBAwUC","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 NodeId,\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';\nimport {NodeGroupingTransformation} from './features/nodeGrouping';\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 const FORCE_LAYOUT_CONFIG = {\n steps: 40,\n alignSiblings: true,\n charge: 5,\n theta: 0.34,\n duration: ANIMATION_DURATION\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 // Node Grouping transformation instance\n public LkNodeGroupingTransformation!: NodeGroupingTransformation;\n private _reactive!: RxViz;\n\n constructor(private _configuration: IOgmaConfig, _baseUrl?: string) {\n // set Ogma global configuration\n super(_configuration);\n Object.setPrototypeOf(this, new.target.prototype);\n this.initOgmaLinkuriousParser(true, _baseUrl);\n }\n\n /**\n * Initialize the Ogma instance with the configuration and the base url\n * @param init used to know if the instance is initialized for the first time (used in setConfigOgma)\n * @param baseUrl base url used for relative image urls\n * @private\n */\n private initOgmaLinkuriousParser(init?: boolean, baseUrl?: string): 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, init, baseUrl);\n this.LKTransformation = new TransformationsViz(this);\n this.LkNodeGroupingTransformation = new NodeGroupingTransformation(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, baseUrl?: string): void {\n this.LKStyles = new StylesViz(this, {\n node: configuration?.options?.styles?.node || {},\n edge: configuration?.options?.styles?.edge || {},\n baseUrl: baseUrl\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): Promise<void> {\n await 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 await this.LKCaptions.initVizCaptions({\n node: visualization.nodeFields.captions || {},\n edge: visualization.edgeFields.captions || {}\n });\n this.LKTransformation.groupedEdges = visualization.edgeGrouping;\n await 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 addEdges(edges: Array<RawEdge<LkEdgeData>>, options?: AddItemOptions): Promise<EdgeList> {\n return super.addEdges(edges, {...options, ignoreInvalid: true});\n }\n\n /**\n * Return the list of non filtered nodes\n */\n public getNonFilteredNodes(items?: Array<NodeId>): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => !i.hasClass('filtered'))\n : // take only none virtual nodes\n this.getNodes('raw').filter((i) => !i.hasClass('filtered'));\n }\n\n /**\n * Return the list of filtered nodes\n * @param items items to check if they are filtered\n * @param filter type of nodes to check if they are filtered ( nodes that are visible, raw nodes (none virtual) or all nodes)\n */\n public getFilteredNodes(\n items?: Array<NodeId>,\n filter: 'visible' | 'raw' | 'all' = 'raw'\n ): NodeList<LkNodeData, LkEdgeData> {\n return Tools.isDefined(items)\n ? this.getNodes(items).filter((i) => i.hasClass('filtered'))\n : this.getNodes(filter).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(\n items?: Array<any>,\n filter: 'visible' | 'raw' | 'all' = 'raw'\n ): EdgeList<LkEdgeData, LkNodeData> {\n return Tools.isDefined(items)\n ? this.getEdges(items).filter((i) => i.hasClass('filtered'))\n : this.getEdges(filter).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, baseUrl?: string): void {\n if (configuration) {\n // here we make sure that the internal config object is updated and we have the correct one when resetting\n this._configuration = configuration;\n }\n if (!init) {\n this.setOptions({\n ...this._configuration.options,\n renderer: this._configuration.renderer\n });\n }\n this.setStyles(this._configuration, baseUrl);\n this.setCaptions(this._configuration);\n }\n}\n"]}
@@ -8,7 +8,7 @@ var EdgeWidthExtrema;
8
8
  (function (EdgeWidthExtrema) {
9
9
  EdgeWidthExtrema[EdgeWidthExtrema["MIN"] = 50] = "MIN";
10
10
  EdgeWidthExtrema[EdgeWidthExtrema["MAX"] = 200] = "MAX";
11
- })(EdgeWidthExtrema = exports.EdgeWidthExtrema || (exports.EdgeWidthExtrema = {}));
11
+ })(EdgeWidthExtrema || (exports.EdgeWidthExtrema = EdgeWidthExtrema = {}));
12
12
  class EdgeAttributes extends itemAttributes_1.ItemAttributes {
13
13
  constructor(rulesMap) {
14
14
  super(rulesMap);
@@ -1 +1 @@
1
- {"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAMiC;AAEjC,0CAAqC;AAGrC,qDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED,MAAa,cAAe,SA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,cAAc,CAAC,sBAAsB,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;qBAC/E;iBACF;qBAAM;oBACL,OAAO,UAAU,CAAC;iBACnB;aACF;SACF;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,sBAAsB,CAClC,KAAa,EACb,IAA2B,EAC3B,KAAK,GAAG,KAAK;QAEb,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,IAAgB;QAMhB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO;gBACL,KAAK,EAAE,0BAAS;gBAChB,KAAK,EAAE,2BAAa,CAAC,KAAK;gBAC1B,KAAK,EAAE,MAAM;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;CACF;AArID,wCAqIC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IEdgeStyle,\n LkEdgeData,\n OgmaEdgeShape,\n IStyleAutoRange\n} 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<IEdgeStyle> {\n constructor(rulesMap: {\n color?: Array<StyleRule<IEdgeStyle>>;\n shape?: Array<StyleRule<IEdgeStyle>>;\n width?: Array<StyleRule<IEdgeStyle>>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(\n styleRules: Array<StyleRule<IEdgeStyle>>,\n data: LkEdgeData\n ): StyleRule<IEdgeStyle> | 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.color.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 EdgeAttributes.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 | number | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n if (styleRule !== undefined) {\n const widthStyle = styleRule?.style.width;\n if (widthStyle !== undefined && this.isAutoRange(widthStyle)) {\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 const isLog = widthStyle.scale && widthStyle.scale === AutoRangeScale.LOGARITHMIC;\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\n }\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeWidth(\n value: number,\n rule: StyleRule<IEdgeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width as IStyleAutoRange,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width as IStyleAutoRange,\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 | number;\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,yDAMiC;AAEjC,0CAAqC;AAGrC,qDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAC5D,YAAY,QAIX;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,UAAU,CACvB,UAAwC,EACxC,IAAgB;QAEhB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;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AK,CAAC,CAAC;oBAChF,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO,UAAU,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,sBAAsB,CAClC,KAAa,EACb,IAA2B,EAC3B,KAAK,GAAG,KAAK;QAEb,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,IAAgB;QAMhB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACL,KAAK,EAAE,0BAAS;gBAChB,KAAK,EAAE,2BAAa,CAAC,KAAK;gBAC1B,KAAK,EAAE,MAAM;aACd,CAAC;QACJ,CAAC;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;CACF;AArID,wCAqIC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IEdgeStyle,\n LkEdgeData,\n OgmaEdgeShape,\n IStyleAutoRange\n} 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<IEdgeStyle> {\n constructor(rulesMap: {\n color?: Array<StyleRule<IEdgeStyle>>;\n shape?: Array<StyleRule<IEdgeStyle>>;\n width?: Array<StyleRule<IEdgeStyle>>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(\n styleRules: Array<StyleRule<IEdgeStyle>>,\n data: LkEdgeData\n ): StyleRule<IEdgeStyle> | 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.color.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 EdgeAttributes.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 | number | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n if (styleRule !== undefined) {\n const widthStyle = styleRule?.style.width;\n if (widthStyle !== undefined && this.isAutoRange(widthStyle)) {\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 const isLog = widthStyle.scale && widthStyle.scale === AutoRangeScale.LOGARITHMIC;\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\n }\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeWidth(\n value: number,\n rule: StyleRule<IEdgeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width as IStyleAutoRange,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width as IStyleAutoRange,\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 | number;\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,gDAAwB;AAIxB,0CAAqC;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,MAAa,cAAc;IAWzB,YAAY,QAOX;QAjBS,gBAAW,GAAsC,IAAI,GAAG,EA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G,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAEjD,OAAO,GAAG,IAAI,GAAG,CAAC;SACnB;IACH,CAAC;IAEM,WAAW,CAAC,KAAwC;QACzD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,WAAW,CAAC;IAClE,CAAC;CACF;AAxJD,wCAwJC","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\nimport {IEdgeStyle, INodeStyle, IStyleAutoRange} from '@linkurious/rest-client';\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<T extends INodeStyle | IEdgeStyle> {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\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 | undefined, 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(\n rule: StyleRule<IEdgeStyle | INodeStyle>,\n type: string\n ): string | undefined | 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 with a linear function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLinear(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (max !== undefined && min !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\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\n /**\n * return the corresponding size to the value with a logarithmic function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLog(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (min !== undefined && max !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n // apply an offset for all the values (including min and max)\n if (min < 1) {\n value += Math.abs(min) + 1;\n max += Math.abs(min) + 1;\n min += Math.abs(min) + 1;\n }\n // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)\n const a = (higher - lower) / (Math.log(max) - Math.log(min));\n const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));\n const size = Math.floor(a * Math.log(value) + b);\n\n return `${size}%`;\n }\n }\n\n public isAutoRange(value: string | number | IStyleAutoRange): value is IStyleAutoRange {\n return typeof value === 'object' && value?.type === 'autoRange';\n }\n}\n"]}
1
+ {"version":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JC","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\nimport {IEdgeStyle, INodeStyle, IStyleAutoRange} from '@linkurious/rest-client';\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<T extends INodeStyle | IEdgeStyle> {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\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 | undefined, 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(\n rule: StyleRule<IEdgeStyle | INodeStyle>,\n type: string\n ): string | undefined | 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 with a linear function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLinear(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (max !== undefined && min !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\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\n /**\n * return the corresponding size to the value with a logarithmic function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLog(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (min !== undefined && max !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n // apply an offset for all the values (including min and max)\n if (min < 1) {\n value += Math.abs(min) + 1;\n max += Math.abs(min) + 1;\n min += Math.abs(min) + 1;\n }\n // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)\n const a = (higher - lower) / (Math.log(max) - Math.log(min));\n const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));\n const size = Math.floor(a * Math.log(value) + b);\n\n return `${size}%`;\n }\n }\n\n public isAutoRange(value: string | number | IStyleAutoRange): value is IStyleAutoRange {\n return typeof value === 'object' && value?.type === 'autoRange';\n }\n}\n"]}
@@ -13,7 +13,7 @@ var NodeSizeExtrema;
13
13
  (function (NodeSizeExtrema) {
14
14
  NodeSizeExtrema[NodeSizeExtrema["MIN"] = 50] = "MIN";
15
15
  NodeSizeExtrema[NodeSizeExtrema["MAX"] = 500] = "MAX";
16
- })(NodeSizeExtrema = exports.NodeSizeExtrema || (exports.NodeSizeExtrema = {}));
16
+ })(NodeSizeExtrema || (exports.NodeSizeExtrema = NodeSizeExtrema = {}));
17
17
  class NodeAttributes extends itemAttributes_1.ItemAttributes {
18
18
  constructor(rulesMap) {
19
19
  super(rulesMap);
@@ -1 +1 @@
1
- {"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,yDASiC;AACjC,gDAAwB;AAExB,0CAAqC;AACrC,0BAA6B;AAG7B,qDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,GAAf,uBA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AAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF;AA9QD,wCA8QC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IImageDataValue,\n INodeStyle,\n IStyleAutoRange,\n IStyleIcon,\n IStyleImage,\n LkNodeData,\n OgmaNodeShape\n} 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<INodeStyle> {\n // Base url, used for image urls\n private _baseUrl?: string;\n\n constructor(rulesMap: {\n color?: Array<StyleRule<INodeStyle>>;\n icon?: Array<StyleRule<INodeStyle>>;\n image?: Array<StyleRule<INodeStyle>>;\n shape?: Array<StyleRule<INodeStyle>>;\n size?: Array<StyleRule<INodeStyle>>;\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 static matchStyle(\n styleRules: Array<StyleRule<INodeStyle>>,\n itemData: LkNodeData,\n callback: (style: StyleRule<INodeStyle>) => 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: Array<string | null> = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let color = 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 color = ItemAttributes.autoColor(itemData.categories[i], rule.style.color.ignoreCase);\n } else {\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);\n }\n } else {\n color = rule.style.color as string;\n }\n break;\n }\n }\n colors.push(color);\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 const style = rules[i].style;\n if ('icon' in style && typeof style.icon === 'object') {\n result = {\n icon: {\n content: style.icon?.content as string,\n font: style.icon?.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in style && typeof style.image === 'object') {\n const imageUrlValue = NodeAttributes.getImageUrlFromStyleRule(\n style.image.url,\n itemData,\n this._baseUrl\n );\n if (imageUrlValue !== undefined) {\n result = {\n image: {\n url: imageUrlValue,\n scale: style.image.scale,\n fit: style.image.fit,\n tile: style.image.tile,\n minVisibleSize: 0\n }\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 NodeAttributes.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 NodeAttributes.matchStyle(\n this._rulesMap.size,\n itemData,\n (styleRule: StyleRule<INodeStyle>) => {\n const sizeStyle = styleRule.style.size as string | number | IStyleAutoRange;\n if (this.isAutoRange(sizeStyle)) {\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 const isLog = sizeStyle.scale && sizeStyle.scale === AutoRangeScale.LOGARITHMIC;\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n }\n );\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(\n value: number,\n rule: StyleRule<INodeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size as IStyleAutoRange,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size as IStyleAutoRange,\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 /**\n * Return the value of the image url from a style rule or undefined\n * @param value\n * @param itemData\n * @param baseUrl\n */\n public static getImageUrlFromStyleRule(\n value: string | IImageDataValue | undefined,\n itemData: LkNodeData,\n baseUrl?: string\n ): string | undefined {\n let imageUrl: string | undefined;\n if (typeof value === 'string' && ['imageUrl', 'image'].includes(Tools.getType(value)!)) {\n imageUrl = value;\n } else if (typeof value === 'object') {\n imageUrl = Tools.getIn(itemData, value.path);\n }\n\n // if base url is defined, we need to create a new URL to get the absolute path\n if (imageUrl !== undefined && baseUrl !== undefined) {\n return new URL(imageUrl, baseUrl).href;\n }\n return imageUrl;\n }\n\n /**\n * Set the base url (it will be used for image url while styling nodes)\n * @param baseUrl bse url\n */\n public setBaseUrl(baseUrl?: string): void {\n this._baseUrl = baseUrl;\n }\n}\n"]}
1
+ {"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,yDASiC;AACjC,gDAAwB;AAExB,0CAAqC;AACrC,0BAA6B;AAG7B,qDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAI5D,YAAY,QAMX;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,UAAU,CACvB,UAAwC,EACxC,QAAoB,EACpB,QAAmD;QAEnD,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QACD,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAA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;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF;AA9QD,wCA8QC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IImageDataValue,\n INodeStyle,\n IStyleAutoRange,\n IStyleIcon,\n IStyleImage,\n LkNodeData,\n OgmaNodeShape\n} 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<INodeStyle> {\n // Base url, used for image urls\n private _baseUrl?: string;\n\n constructor(rulesMap: {\n color?: Array<StyleRule<INodeStyle>>;\n icon?: Array<StyleRule<INodeStyle>>;\n image?: Array<StyleRule<INodeStyle>>;\n shape?: Array<StyleRule<INodeStyle>>;\n size?: Array<StyleRule<INodeStyle>>;\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 static matchStyle(\n styleRules: Array<StyleRule<INodeStyle>>,\n itemData: LkNodeData,\n callback: (style: StyleRule<INodeStyle>) => 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: Array<string | null> = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let color = 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 color = ItemAttributes.autoColor(itemData.categories[i], rule.style.color.ignoreCase);\n } else {\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);\n }\n } else {\n color = rule.style.color as string;\n }\n break;\n }\n }\n colors.push(color);\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 const style = rules[i].style;\n if ('icon' in style && typeof style.icon === 'object') {\n result = {\n icon: {\n content: style.icon?.content as string,\n font: style.icon?.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in style && typeof style.image === 'object') {\n const imageUrlValue = NodeAttributes.getImageUrlFromStyleRule(\n style.image.url,\n itemData,\n this._baseUrl\n );\n if (imageUrlValue !== undefined) {\n result = {\n image: {\n url: imageUrlValue,\n scale: style.image.scale,\n fit: style.image.fit,\n tile: style.image.tile,\n minVisibleSize: 0\n }\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 NodeAttributes.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 NodeAttributes.matchStyle(\n this._rulesMap.size,\n itemData,\n (styleRule: StyleRule<INodeStyle>) => {\n const sizeStyle = styleRule.style.size as string | number | IStyleAutoRange;\n if (this.isAutoRange(sizeStyle)) {\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 const isLog = sizeStyle.scale && sizeStyle.scale === AutoRangeScale.LOGARITHMIC;\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n }\n );\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(\n value: number,\n rule: StyleRule<INodeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size as IStyleAutoRange,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size as IStyleAutoRange,\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 /**\n * Return the value of the image url from a style rule or undefined\n * @param value\n * @param itemData\n * @param baseUrl\n */\n public static getImageUrlFromStyleRule(\n value: string | IImageDataValue | undefined,\n itemData: LkNodeData,\n baseUrl?: string\n ): string | undefined {\n let imageUrl: string | undefined;\n if (typeof value === 'string' && ['imageUrl', 'image'].includes(Tools.getType(value)!)) {\n imageUrl = value;\n } else if (typeof value === 'object') {\n imageUrl = Tools.getIn(itemData, value.path);\n }\n\n // if base url is defined, we need to create a new URL to get the absolute path\n if (imageUrl !== undefined && baseUrl !== undefined) {\n return new URL(imageUrl, baseUrl).href;\n }\n return imageUrl;\n }\n\n /**\n * Set the base url (it will be used for image url while styling nodes)\n * @param baseUrl bse url\n */\n public setBaseUrl(baseUrl?: string): void {\n this._baseUrl = baseUrl;\n }\n}\n"]}
@@ -7,7 +7,7 @@ const tools_1 = require("../tools/tools");
7
7
  var StyleRuleType;
8
8
  (function (StyleRuleType) {
9
9
  StyleRuleType["AUTO_RANGE"] = "autoRange";
10
- })(StyleRuleType = exports.StyleRuleType || (exports.StyleRuleType = {}));
10
+ })(StyleRuleType || (exports.StyleRuleType = StyleRuleType = {}));
11
11
  class StyleRule {
12
12
  constructor(model) {
13
13
  this.type = model.type;
@@ -1 +1 @@
1
- {"version":3,"file":"styleRule.js","sourceRoot":"","sources":["../../src/styles/styleRule.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDASiC;AAEjC,0BAAkC;AAClC,0CAAqC;AAErC,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,yCAAwB,CAAA;AAC1B,CAAC,EAFW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAExB;AAED,MAAa,SAAS;IASpB,YAAY,KAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;Q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;IAED;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAmC;QACxD,OAAO,QAAQ,KAAK,SAAS,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,IAAY;QAC9B,IAAI,KAAK,CAAC;QACV,IACE,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;YAC9C,IAAI,CAAC,IAAI,KAAK,0BAAY,CAAC,GAAG;YAC9B,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAC5B;YACA,KAAK,GAAG,kBAAc,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACjD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AArPD,8BAqPC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n IRangeValues,\n SelectorType,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {ItemAttributes} from '..';\nimport {Tools} from '../tools/tools';\n\nexport enum StyleRuleType {\n AUTO_RANGE = 'autoRange'\n}\n\nexport class StyleRule<T extends INodeStyle | IEdgeStyle = INodeStyle | IEdgeStyle>\n implements IStyleRule<T> {\n public type: SelectorType;\n public input: string[] | undefined;\n public index: number;\n public style: T;\n public itemType?: string;\n public value: IRangeValues | number | string | boolean;\n\n constructor(model: IStyleRule<T>) {\n this.type = model.type;\n this.input = model.input;\n this.index = model.index;\n this.itemType = model.itemType;\n this.style = model.style;\n // cast to remove undefined from type\n this.value = model.value as IRangeValues | number | string | boolean;\n }\n\n public static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean {\n return (\n rule.style !== undefined &&\n (((rule.style as IEdgeStyle).width !== undefined &&\n ((rule.style as IEdgeStyle).width as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE) ||\n ((rule.style as INodeStyle).size !== undefined &&\n ((rule.style as INodeStyle).size as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE))\n );\n }\n\n /**\n * Return an int describing specificity of the style. 4 = very specific / 1 = not specific\n *\n * @return {number}\n */\n get specificity(): 1 | 2 | 3 | 4 {\n if (this.itemType !== undefined && this.input !== undefined) {\n return 4;\n }\n if (this.itemType === undefined && this.input !== undefined) {\n return 3;\n }\n if (this.itemType !== undefined && this.input === undefined) {\n return 2;\n }\n return 1;\n }\n\n /**\n * Return true if this style match values\n */\n public matchValues(\n itemType: string | undefined,\n input: Array<string> | undefined,\n value: string | undefined\n ): boolean {\n if (Tools.isDefined(input)) {\n return (\n ((itemType === this.itemType || !Tools.isDefined(this.itemType)) &&\n Tools.isEqual(['properties', ...input], this.input) &&\n Tools.isEqual(value, this.value)) ||\n (this.type === 'any' &&\n !Tools.isDefined(this.input) &&\n typeof this.style.color === 'object' &&\n this.style.color.input[1] === input[0])\n );\n }\n\n if (Tools.isDefined(this.itemType)) {\n return itemType === this.itemType && !Tools.isDefined(this.input);\n }\n\n return !Tools.isDefined(this.input);\n }\n\n public static inputExists(\n type: SelectorType,\n input: Array<string> | undefined\n ): input is Array<string> {\n return type !== SelectorType.ANY;\n }\n\n /**\n * Return true if a style can apply to a node\n */\n public canApplyTo(data: LkNodeData | LkEdgeData): boolean {\n const types = 'categories' in data ? data.categories : [data.type];\n let typePredicate = false;\n switch (this.type) {\n case SelectorType.ANY:\n typePredicate = StyleRule.checkAny(data, this.style);\n break;\n\n case SelectorType.NO_VALUE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNoValue(data, this.input);\n }\n break;\n\n case SelectorType.NAN:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNan(data, this.input);\n }\n break;\n\n case SelectorType.RANGE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkRange(\n Tools.getIn(data, this.input),\n this.value as IRangeValues\n );\n }\n break;\n\n case SelectorType.IS:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkIs(data, this.input, this.value);\n }\n break;\n }\n return typePredicate && StyleRule.checkItemType(types, this.itemType);\n }\n\n /**\n * Return true or false on rule type 'any' if the current node match the rule\n */\n public static checkAny(data: LkNodeData | LkEdgeData, style: INodeStyle | IEdgeStyle): boolean {\n // return true if autoColor by a property and this property exists in node\n if (typeof style.color === 'object') {\n return Tools.isDefined(Tools.getIn(data, style.color.input));\n }\n return true;\n }\n\n /**\n * Return true or false on rule type 'noValue' if the current node match the rule\n */\n public static checkNoValue(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.valueExists(Tools.getIn(data, input));\n }\n\n /**\n * Return true or false on rule type 'NaN' if the current node match the rule\n */\n public static checkNan(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.isNumber(Tools.getIn(data, input));\n }\n\n /**\n * Return true if predicate is true for the node value\n *\n * @param value\n * @param comparator\n * @return {boolean}\n */\n public static checkRange(\n value: number,\n comparator: {[key in '<=' | '<' | '>' | '>=']?: number}\n ): boolean {\n return (\n (comparator['<='] === undefined || value <= comparator['<=']) &&\n (comparator['<'] === undefined || value < comparator['<']) &&\n (comparator['>'] === undefined || value > comparator['>']) &&\n (comparator['>='] === undefined || value >= comparator['>='])\n );\n }\n\n /**\n * Return true or false on rule type 'is' if the current node match the rule\n */\n public static checkIs(\n data: LkNodeData | LkEdgeData,\n input: Array<string>,\n value: IRangeValues | number | string | boolean\n ): boolean {\n if (!Tools.isDefined(input)) {\n return false;\n }\n const itemValue = Tools.getIn(data, input);\n let formattedValue = itemValue;\n if (\n Tools.isDefined(itemValue) &&\n typeof itemValue === 'object' &&\n (itemValue.type === 'date' || itemValue.type === 'datetime')\n ) {\n let timezone = itemValue.timezone;\n if (itemValue.timezone === 'Z') {\n timezone = '+00:00';\n }\n formattedValue = Tools.formatDate(\n itemValue.value,\n itemValue.type === 'datetime',\n Tools.timezoneToMilliseconds(timezone) / 1000\n );\n }\n return Tools.isEqual(formattedValue, value);\n }\n\n /**\n * Check that value of itemType match for the node\n */\n public static checkItemType(types: Array<string>, itemType: string | undefined): boolean {\n return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);\n }\n\n /**\n * Return true if itemType is defined and category exists in an array of categories\n *\n * @param {Array<string> | string} types\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchCategory(\n types: Array<string> | string,\n itemType: string | undefined\n ): boolean {\n return (\n Tools.isDefined(itemType) &&\n (Array.isArray(types) ? types.includes(itemType) : Tools.isEqual(types, itemType))\n );\n }\n\n /**\n * Return true if itemType is undefined\n *\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchAny(itemType: string | null | undefined): boolean {\n return itemType === undefined;\n }\n\n /**\n * Return the color for a type\n */\n public getTypeColor(type: string): string | undefined | null {\n let color;\n if (\n StyleRule.checkItemType([type], this.itemType) &&\n this.type === SelectorType.ANY &&\n !Tools.isDefined(this.input)\n ) {\n color = ItemAttributes.getTypeColor(this, type);\n }\n return color;\n }\n}\n"]}
1
+ {"version":3,"file":"styleRule.js","sourceRoot":"","sources":["../../src/styles/styleRule.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDASiC;AAEjC,0BAAkC;AAClC,0CAAqC;AAErC,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,yCAAwB,CAAA;AAC1B,CAAC,EAFW,aAAa,6BAAb,aAAa,QAExB;AAED,MAAa,SAAS;IASpB,YAAY,KAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,qCAAqC;QACrC,IAAI,CAAC,KAAK,GAAG,KA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ChC,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,IAAY;QAC9B,IAAI,KAAK,CAAC;QACV,IACE,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;YAC9C,IAAI,CAAC,IAAI,KAAK,0BAAY,CAAC,GAAG;YAC9B,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAC5B,CAAC;YACD,KAAK,GAAG,kBAAc,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AArPD,8BAqPC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n IRangeValues,\n SelectorType,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {ItemAttributes} from '..';\nimport {Tools} from '../tools/tools';\n\nexport enum StyleRuleType {\n AUTO_RANGE = 'autoRange'\n}\n\nexport class StyleRule<T extends INodeStyle | IEdgeStyle = INodeStyle | IEdgeStyle>\n implements IStyleRule<T> {\n public type: SelectorType;\n public input: string[] | undefined;\n public index: number;\n public style: T;\n public itemType?: string;\n public value: IRangeValues | number | string | boolean;\n\n constructor(model: IStyleRule<T>) {\n this.type = model.type;\n this.input = model.input;\n this.index = model.index;\n this.itemType = model.itemType;\n this.style = model.style;\n // cast to remove undefined from type\n this.value = model.value as IRangeValues | number | string | boolean;\n }\n\n public static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean {\n return (\n rule.style !== undefined &&\n (((rule.style as IEdgeStyle).width !== undefined &&\n ((rule.style as IEdgeStyle).width as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE) ||\n ((rule.style as INodeStyle).size !== undefined &&\n ((rule.style as INodeStyle).size as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE))\n );\n }\n\n /**\n * Return an int describing specificity of the style. 4 = very specific / 1 = not specific\n *\n * @return {number}\n */\n get specificity(): 1 | 2 | 3 | 4 {\n if (this.itemType !== undefined && this.input !== undefined) {\n return 4;\n }\n if (this.itemType === undefined && this.input !== undefined) {\n return 3;\n }\n if (this.itemType !== undefined && this.input === undefined) {\n return 2;\n }\n return 1;\n }\n\n /**\n * Return true if this style match values\n */\n public matchValues(\n itemType: string | undefined,\n input: Array<string> | undefined,\n value: string | undefined\n ): boolean {\n if (Tools.isDefined(input)) {\n return (\n ((itemType === this.itemType || !Tools.isDefined(this.itemType)) &&\n Tools.isEqual(['properties', ...input], this.input) &&\n Tools.isEqual(value, this.value)) ||\n (this.type === 'any' &&\n !Tools.isDefined(this.input) &&\n typeof this.style.color === 'object' &&\n this.style.color.input[1] === input[0])\n );\n }\n\n if (Tools.isDefined(this.itemType)) {\n return itemType === this.itemType && !Tools.isDefined(this.input);\n }\n\n return !Tools.isDefined(this.input);\n }\n\n public static inputExists(\n type: SelectorType,\n input: Array<string> | undefined\n ): input is Array<string> {\n return type !== SelectorType.ANY;\n }\n\n /**\n * Return true if a style can apply to a node\n */\n public canApplyTo(data: LkNodeData | LkEdgeData): boolean {\n const types = 'categories' in data ? data.categories : [data.type];\n let typePredicate = false;\n switch (this.type) {\n case SelectorType.ANY:\n typePredicate = StyleRule.checkAny(data, this.style);\n break;\n\n case SelectorType.NO_VALUE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNoValue(data, this.input);\n }\n break;\n\n case SelectorType.NAN:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNan(data, this.input);\n }\n break;\n\n case SelectorType.RANGE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkRange(\n Tools.getIn(data, this.input),\n this.value as IRangeValues\n );\n }\n break;\n\n case SelectorType.IS:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkIs(data, this.input, this.value);\n }\n break;\n }\n return typePredicate && StyleRule.checkItemType(types, this.itemType);\n }\n\n /**\n * Return true or false on rule type 'any' if the current node match the rule\n */\n public static checkAny(data: LkNodeData | LkEdgeData, style: INodeStyle | IEdgeStyle): boolean {\n // return true if autoColor by a property and this property exists in node\n if (typeof style.color === 'object') {\n return Tools.isDefined(Tools.getIn(data, style.color.input));\n }\n return true;\n }\n\n /**\n * Return true or false on rule type 'noValue' if the current node match the rule\n */\n public static checkNoValue(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.valueExists(Tools.getIn(data, input));\n }\n\n /**\n * Return true or false on rule type 'NaN' if the current node match the rule\n */\n public static checkNan(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.isNumber(Tools.getIn(data, input));\n }\n\n /**\n * Return true if predicate is true for the node value\n *\n * @param value\n * @param comparator\n * @return {boolean}\n */\n public static checkRange(\n value: number,\n comparator: {[key in '<=' | '<' | '>' | '>=']?: number}\n ): boolean {\n return (\n (comparator['<='] === undefined || value <= comparator['<=']) &&\n (comparator['<'] === undefined || value < comparator['<']) &&\n (comparator['>'] === undefined || value > comparator['>']) &&\n (comparator['>='] === undefined || value >= comparator['>='])\n );\n }\n\n /**\n * Return true or false on rule type 'is' if the current node match the rule\n */\n public static checkIs(\n data: LkNodeData | LkEdgeData,\n input: Array<string>,\n value: IRangeValues | number | string | boolean\n ): boolean {\n if (!Tools.isDefined(input)) {\n return false;\n }\n const itemValue = Tools.getIn(data, input);\n let formattedValue = itemValue;\n if (\n Tools.isDefined(itemValue) &&\n typeof itemValue === 'object' &&\n (itemValue.type === 'date' || itemValue.type === 'datetime')\n ) {\n let timezone = itemValue.timezone;\n if (itemValue.timezone === 'Z') {\n timezone = '+00:00';\n }\n formattedValue = Tools.formatDate(\n itemValue.value,\n itemValue.type === 'datetime',\n Tools.timezoneToMilliseconds(timezone) / 1000\n );\n }\n return Tools.isEqual(formattedValue, value);\n }\n\n /**\n * Check that value of itemType match for the node\n */\n public static checkItemType(types: Array<string>, itemType: string | undefined): boolean {\n return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);\n }\n\n /**\n * Return true if itemType is defined and category exists in an array of categories\n *\n * @param {Array<string> | string} types\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchCategory(\n types: Array<string> | string,\n itemType: string | undefined\n ): boolean {\n return (\n Tools.isDefined(itemType) &&\n (Array.isArray(types) ? types.includes(itemType) : Tools.isEqual(types, itemType))\n );\n }\n\n /**\n * Return true if itemType is undefined\n *\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchAny(itemType: string | null | undefined): boolean {\n return itemType === undefined;\n }\n\n /**\n * Return the color for a type\n */\n public getTypeColor(type: string): string | undefined | null {\n let color;\n if (\n StyleRule.checkItemType([type], this.itemType) &&\n this.type === SelectorType.ANY &&\n !Tools.isDefined(this.input)\n ) {\n color = ItemAttributes.getTypeColor(this, type);\n }\n return color;\n }\n}\n"]}
@@ -13,7 +13,7 @@ var StyleType;
13
13
  StyleType["IMAGE"] = "image";
14
14
  StyleType["SHAPE"] = "shape";
15
15
  StyleType["WIDTH"] = "width";
16
- })(StyleType = exports.StyleType || (exports.StyleType = {}));
16
+ })(StyleType || (exports.StyleType = StyleType = {}));
17
17
  exports.SORTING_RULE = ['specificity', 'itemType', 'index'];
18
18
  class StyleRules {
19
19
  constructor(rules) {
@@ -1 +1 @@
1
- {"version":3,"file":"styleRules.js","sourceRoot":"","sources":["../../src/styles/styleRules.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAYiC;AAEjC,0CAA6C;AAE7C,2CAAsC;AACtC,qDAAgD;AAEhD,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB;AAMY,QAAA,YAAY,GAAG,CAAC,aAAa,EAAE,UAAU,EAA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eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACxD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACnC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;aACZ;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC7B;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA5UD,gCA4UC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles,\n IStyleColor,\n IRangeValues\n} from '@linkurious/rest-client';\n\nimport {sortBy, Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {ItemAttributes} from './itemAttributes';\n\nexport enum StyleType {\n COLOR = 'color',\n ICON = 'icon',\n SIZE = 'size',\n IMAGE = 'image',\n SHAPE = 'shape',\n WIDTH = 'width'\n}\n\nexport interface Legend {\n [key: string]: Array<{label: string; value: string | IStyleIcon | IStyleImage | number}>;\n}\n\nexport const SORTING_RULE = ['specificity', 'itemType', 'index'];\n\nexport class StyleRules {\n private _rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>;\n\n constructor(rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>) {\n this._rules = rules;\n }\n\n /**\n * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get color(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.COLOR, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get icon(): Array<StyleRule> {\n return sortBy(\n [\n ...(StyleRules.getBy(StyleType.ICON, this._rules) || []),\n ...(StyleRules.getBy(StyleType.IMAGE, this._rules) || [])\n ],\n SORTING_RULE\n );\n }\n\n /**\n * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get image(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.IMAGE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get shape(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SHAPE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get size(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SIZE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get width(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.WIDTH, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an object containing for each node style a sorted array of StyleRule\n *\n * @return {{[key: string]: Array<StyleRule>} }\n */\n public get nodeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n icon: this.icon,\n image: this.image,\n shape: this.shape,\n size: this.size\n };\n }\n\n /**\n * Return an object containing for each edge style a sorted array of StyleRule\n *\n * @return { {[key: string]: Array<StyleRule>}}\n */\n public get edgeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n shape: this.shape,\n width: this.width\n };\n }\n\n /**\n * Generate a legend with an array of style rules and existing items in visualization\n */\n public generateLegend(itemsData: Array<LkNodeData | LkEdgeData>): Legend {\n const result: Legend = {};\n if (itemsData.length === 0) {\n return result;\n }\n\n if ('categories' in itemsData[0]) {\n Object.keys(this.nodeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.nodeRules[style],\n itemsData\n );\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.edgeRules[style],\n itemsData\n );\n });\n }\n return result;\n }\n\n /**\n * Return the legend for a specific style type (color, icon, image...)\n */\n public static getLegendForStyle(\n styleType: StyleType,\n styles: Array<StyleRule>,\n itemsData: Array<LkNodeData | LkEdgeData>\n ): Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> {\n const result: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> = [];\n const data = itemsData.filter((i) => i);\n for (let i = 0; i < styles.length; i++) {\n const styleRule = new StyleRule(styles[i]);\n const ruleExistsInViz = data.some((itemData) => {\n return styleRule.canApplyTo(itemData);\n });\n if (ruleExistsInViz) {\n if (styleType === StyleType.COLOR && typeof styleRule.style.color === 'object') {\n StyleRules.addLegendAutoColors(data, styleRule, result);\n } else if (styleType === StyleType.ICON && 'image' in styleRule.style) {\n // style is a custom icon\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const imageStyle = styleRule.style.image as IStyleImage;\n if (\n imageStyle.url &&\n typeof imageStyle.url === 'object' &&\n imageStyle.url.type === 'data'\n ) {\n // If the custom icon is read from a node property-value dynamically, then we\n // skip it from the legend, because it could be a different image for each node,\n // thus bloating the legend.\n } else {\n const value = styleRule.style.image;\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n } else {\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const value =\n styleType === StyleType.WIDTH\n ? (styleRule.style as IEdgeStyle)[styleType]\n : (styleRule.style as INodeStyle)[styleType];\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(\n styleType: SelectorType,\n value: IRangeValues | number | string | boolean\n ): string {\n let template = '';\n switch (styleType) {\n case SelectorType.NO_VALUE:\n return 'is undefined';\n\n case SelectorType.NAN:\n return 'is not an number';\n\n case SelectorType.RANGE:\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${(value as IRangeValues)[k as keyof IRangeValues]}`;\n });\n return template;\n }\n\n return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;\n }\n\n /**\n * Add items in legend for automatic coloring\n */\n public static addLegendAutoColors(\n itemsData: Array<LkNodeData | LkEdgeData>,\n styleRule: StyleRule,\n currentLegend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>\n ): void {\n const colorStyle = styleRule.style.color as IStyleColor;\n const propertyKey: string = colorStyle.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, colorStyle.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: value});\n }\n });\n }\n\n /**\n * Return the label of item type for a legend item\n */\n public static getTypeLabel(type: string | undefined | null): string {\n return type === undefined ? 'All' : type === null ? 'Others' : type;\n }\n\n /**\n * Check if a legend item already exists and overwrite it / push it\n */\n public static updateLegend(\n legend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>,\n {label, value}: {[key: string]: string}\n ): void {\n const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);\n if (indexOfLegendItem < 0) {\n legend.push({label: label, value: value});\n } else {\n legend[indexOfLegendItem] = {label: label, value: value};\n }\n }\n\n /**\n * return an array of StyleRule, containing only the desired style\n */\n public static getBy(\n styleType: StyleType,\n rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>\n ): Array<StyleRule> {\n return rules\n .filter((style: IStyleRule<INodeStyle | IEdgeStyle>) => {\n switch (styleType) {\n case StyleType.COLOR:\n return style.style.color !== undefined;\n\n case StyleType.ICON:\n return 'icon' in style.style && style.style.icon !== undefined;\n\n case StyleType.IMAGE:\n return 'image' in style.style && style.style.image !== undefined;\n\n case StyleType.SHAPE:\n return style.style.shape !== undefined;\n\n case StyleType.SIZE:\n return 'size' in style.style && style.style.size !== undefined;\n\n case StyleType.WIDTH:\n return 'width' in style.style && style.style.width !== undefined;\n }\n })\n .map((style: IStyleRule<INodeStyle | IEdgeStyle>) => StyleRules.getRule(style, styleType));\n }\n\n /**\n * From a RawStyle, generate a StyleRule of a specific style\n */\n public static getRule(\n rawRule: IStyleRule<INodeStyle | IEdgeStyle>,\n styleType: StyleType\n ): StyleRule {\n const rule = Tools.clone(rawRule);\n rule.style = {[styleType]: rule.style[styleType]};\n return new StyleRule(rule);\n }\n\n /**\n * Check for non unique index in styles rules and update them if exists\n */\n public static sanitizeStylesIndex(styles: IStyles): IStyles {\n const seenIndex: Array<number> = [];\n const sanitizedStyles: IStyles = Tools.clone(styles);\n let maxIndex =\n Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;\n sanitizedStyles.node = sanitizedStyles.node.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n return sanitizedStyles;\n }\n}\n"]}
1
+ {"version":3,"file":"styleRules.js","sourceRoot":"","sources":["../../src/styles/styleRules.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAYiC;AAEjC,0CAA6C;AAE7C,2CAAsC;AACtC,qDAAgD;AAEhD,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB;AAMY,QAAA,YAAY,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAEjE,MAAa,UAAU;IAGrB,YAAY,KAAiD;QAC3D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAW,KAAK;QACd,OAAO,IAAA,cAAM,EAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,oBAAY,CAAC,CAAC;IAC9E,CAAC;IAED;;;;OAIG;IACH,IAAW,IAAI;QACb,OAAO,IAAA,cAAM,EACX;YACE,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACxD,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SAC1D,EACD,oBAAY,CACb,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAW,KAAK;QACd,OAAO,IAAA,cAAM,EAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CA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Icon,\n IStyleImage,\n IStyles,\n IStyleColor,\n IRangeValues\n} from '@linkurious/rest-client';\n\nimport {sortBy, Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {ItemAttributes} from './itemAttributes';\n\nexport enum StyleType {\n COLOR = 'color',\n ICON = 'icon',\n SIZE = 'size',\n IMAGE = 'image',\n SHAPE = 'shape',\n WIDTH = 'width'\n}\n\nexport interface Legend {\n [key: string]: Array<{label: string; value: string | IStyleIcon | IStyleImage | number}>;\n}\n\nexport const SORTING_RULE = ['specificity', 'itemType', 'index'];\n\nexport class StyleRules {\n private _rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>;\n\n constructor(rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>) {\n this._rules = rules;\n }\n\n /**\n * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get color(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.COLOR, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get icon(): Array<StyleRule> {\n return sortBy(\n [\n ...(StyleRules.getBy(StyleType.ICON, this._rules) || []),\n ...(StyleRules.getBy(StyleType.IMAGE, this._rules) || [])\n ],\n SORTING_RULE\n );\n }\n\n /**\n * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get image(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.IMAGE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get shape(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SHAPE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get size(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SIZE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get width(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.WIDTH, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an object containing for each node style a sorted array of StyleRule\n *\n * @return {{[key: string]: Array<StyleRule>} }\n */\n public get nodeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n icon: this.icon,\n image: this.image,\n shape: this.shape,\n size: this.size\n };\n }\n\n /**\n * Return an object containing for each edge style a sorted array of StyleRule\n *\n * @return { {[key: string]: Array<StyleRule>}}\n */\n public get edgeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n shape: this.shape,\n width: this.width\n };\n }\n\n /**\n * Generate a legend with an array of style rules and existing items in visualization\n */\n public generateLegend(itemsData: Array<LkNodeData | LkEdgeData>): Legend {\n const result: Legend = {};\n if (itemsData.length === 0) {\n return result;\n }\n\n if ('categories' in itemsData[0]) {\n Object.keys(this.nodeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.nodeRules[style],\n itemsData\n );\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.edgeRules[style],\n itemsData\n );\n });\n }\n return result;\n }\n\n /**\n * Return the legend for a specific style type (color, icon, image...)\n */\n public static getLegendForStyle(\n styleType: StyleType,\n styles: Array<StyleRule>,\n itemsData: Array<LkNodeData | LkEdgeData>\n ): Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> {\n const result: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> = [];\n const data = itemsData.filter((i) => i);\n for (let i = 0; i < styles.length; i++) {\n const styleRule = new StyleRule(styles[i]);\n const ruleExistsInViz = data.some((itemData) => {\n return styleRule.canApplyTo(itemData);\n });\n if (ruleExistsInViz) {\n if (styleType === StyleType.COLOR && typeof styleRule.style.color === 'object') {\n StyleRules.addLegendAutoColors(data, styleRule, result);\n } else if (styleType === StyleType.ICON && 'image' in styleRule.style) {\n // style is a custom icon\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const imageStyle = styleRule.style.image as IStyleImage;\n if (\n imageStyle.url &&\n typeof imageStyle.url === 'object' &&\n imageStyle.url.type === 'data'\n ) {\n // If the custom icon is read from a node property-value dynamically, then we\n // skip it from the legend, because it could be a different image for each node,\n // thus bloating the legend.\n } else {\n const value = styleRule.style.image;\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n } else {\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const value =\n styleType === StyleType.WIDTH\n ? (styleRule.style as IEdgeStyle)[styleType]\n : (styleRule.style as INodeStyle)[styleType];\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(\n styleType: SelectorType,\n value: IRangeValues | number | string | boolean\n ): string {\n let template = '';\n switch (styleType) {\n case SelectorType.NO_VALUE:\n return 'is undefined';\n\n case SelectorType.NAN:\n return 'is not an number';\n\n case SelectorType.RANGE:\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${(value as IRangeValues)[k as keyof IRangeValues]}`;\n });\n return template;\n }\n\n return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;\n }\n\n /**\n * Add items in legend for automatic coloring\n */\n public static addLegendAutoColors(\n itemsData: Array<LkNodeData | LkEdgeData>,\n styleRule: StyleRule,\n currentLegend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>\n ): void {\n const colorStyle = styleRule.style.color as IStyleColor;\n const propertyKey: string = colorStyle.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, colorStyle.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: value});\n }\n });\n }\n\n /**\n * Return the label of item type for a legend item\n */\n public static getTypeLabel(type: string | undefined | null): string {\n return type === undefined ? 'All' : type === null ? 'Others' : type;\n }\n\n /**\n * Check if a legend item already exists and overwrite it / push it\n */\n public static updateLegend(\n legend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>,\n {label, value}: {[key: string]: string}\n ): void {\n const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);\n if (indexOfLegendItem < 0) {\n legend.push({label: label, value: value});\n } else {\n legend[indexOfLegendItem] = {label: label, value: value};\n }\n }\n\n /**\n * return an array of StyleRule, containing only the desired style\n */\n public static getBy(\n styleType: StyleType,\n rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>\n ): Array<StyleRule> {\n return rules\n .filter((style: IStyleRule<INodeStyle | IEdgeStyle>) => {\n switch (styleType) {\n case StyleType.COLOR:\n return style.style.color !== undefined;\n\n case StyleType.ICON:\n return 'icon' in style.style && style.style.icon !== undefined;\n\n case StyleType.IMAGE:\n return 'image' in style.style && style.style.image !== undefined;\n\n case StyleType.SHAPE:\n return style.style.shape !== undefined;\n\n case StyleType.SIZE:\n return 'size' in style.style && style.style.size !== undefined;\n\n case StyleType.WIDTH:\n return 'width' in style.style && style.style.width !== undefined;\n }\n })\n .map((style: IStyleRule<INodeStyle | IEdgeStyle>) => StyleRules.getRule(style, styleType));\n }\n\n /**\n * From a RawStyle, generate a StyleRule of a specific style\n */\n public static getRule(\n rawRule: IStyleRule<INodeStyle | IEdgeStyle>,\n styleType: StyleType\n ): StyleRule {\n const rule = Tools.clone(rawRule);\n rule.style = {[styleType]: rule.style[styleType]};\n return new StyleRule(rule);\n }\n\n /**\n * Check for non unique index in styles rules and update them if exists\n */\n public static sanitizeStylesIndex(styles: IStyles): IStyles {\n const seenIndex: Array<number> = [];\n const sanitizedStyles: IStyles = Tools.clone(styles);\n let maxIndex =\n Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;\n sanitizedStyles.node = sanitizedStyles.node.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n return sanitizedStyles;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ogmaTool.js","sourceRoot":"","sources":["../../src/tools/ogmaTool.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAIb,mCAA8B;AAC9B,iDAA2C;AAE3C,MAAa,SAAS;IACpB;;;;OAIG;IACI,MAAM,CAAC,kBAAkB,CAAC,KAAuC;QACtE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,MAAc,EAAE,IAAkC,EAAE,EAAE;YACzE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,UAAU,K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oDAAoD,CAAC,CAAC;YACnE,OAAO,IAAI,CAAC;SACb;QACD,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,MAAM,CAClB,IAAiE;QAEjE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,UAAU,CACtB,KAA0E;QAE1E,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AA1FD,8BA0FC","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] = /rgba?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})(,\\d{1,3})?\\)/\n .exec(rgb.replace(/\\s/g, ''))!\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<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AAE,CAAC,CAAC,KAAK,CAAC;gBACzC,CAAC,CAAC,KAAK,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,mDAAmD;aAClE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAE;aAC7B,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEf,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,MAAM,CAClB,IAAiE;QAEjE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,UAAU,CACtB,KAA0E;QAE1E,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AA1FD,8BA0FC","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] = /rgba?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})(,\\d{1,3})?\\)/\n .exec(rgb.replace(/\\s/g, ''))!\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"]}