@linkurious/ogma-linkurious-parser 3.1.5 → 3.1.8
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.
|
@@ -160,8 +160,8 @@ var StyleRules = /** @class */ (function () {
|
|
|
160
160
|
var data = itemsData.filter(function (i) { return i; });
|
|
161
161
|
var _loop_1 = function (i) {
|
|
162
162
|
var styleRule = new styleRule_1.StyleRule(styles[i]);
|
|
163
|
-
var ruleExistsInViz = data.some(function (
|
|
164
|
-
return styleRule.canApplyTo(
|
|
163
|
+
var ruleExistsInViz = data.some(function (itemData) {
|
|
164
|
+
return styleRule.canApplyTo(itemData);
|
|
165
165
|
});
|
|
166
166
|
if (ruleExistsInViz) {
|
|
167
167
|
if (styleType === StyleType.COLOR && typeof styleRule.style.color === 'object') {
|
|
@@ -172,8 +172,18 @@ var StyleRules = /** @class */ (function () {
|
|
|
172
172
|
var label = tools_1.Tools.isDefined(styleRule.input)
|
|
173
173
|
? StyleRules.getTypeLabel(styleRule.itemType) + "." + styleRule.input[1] + " " + StyleRules.sanitizeValue(styleRule.type, styleRule.value)
|
|
174
174
|
: "" + StyleRules.getTypeLabel(styleRule.itemType);
|
|
175
|
-
var
|
|
176
|
-
|
|
175
|
+
var imageStyle = styleRule.style.image;
|
|
176
|
+
if (imageStyle.url &&
|
|
177
|
+
typeof imageStyle.url === 'object' &&
|
|
178
|
+
imageStyle.url.type === 'data') {
|
|
179
|
+
// If the custom icon is read from a node property-value dynamically, then we
|
|
180
|
+
// skip it from the legend, because it could be a different image for each node,
|
|
181
|
+
// thus bloating the legend.
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
var value = styleRule.style.image;
|
|
185
|
+
StyleRules.updateLegend(result, { label: label, value: value });
|
|
186
|
+
}
|
|
177
187
|
}
|
|
178
188
|
else {
|
|
179
189
|
var label = tools_1.Tools.isDefined(styleRule.input)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleRules.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,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK;YACpD,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;IACH,iBAAC;AAAD,CAAC,AAlTD,IAkTC;AAlTY,gCAAU","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles\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 {any}\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 {any}\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(style, this.nodeRules[style], itemsData);\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);\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: string,\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((d) => {\n return styleRule.canApplyTo(d);\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 value = styleRule.style.image;\n StyleRules.updateLegend(result, {label: label, value: value});\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 = styleRule.style[styleType];\n StyleRules.updateLegend(result, {label: label, value: value});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(styleType: SelectorType, value: any): string {\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 let template = '';\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${value[k]}`;\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 propertyKey: string = styleRule.style.color.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, styleRule.style.color.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, styleRule.style.color.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,uDAUiC;AAEjC,wCAA6C;AAE7C,yCAAsC;AACtC,mDAAgD;AAEhD,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BA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QACH,eAAe,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK;YACpD,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;IACH,iBAAC;AAAD,CAAC,AA7TD,IA6TC;AA7TY,gCAAU","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles\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 {any}\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 {any}\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(style, this.nodeRules[style], itemsData);\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);\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: string,\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});\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 = styleRule.style[styleType];\n StyleRules.updateLegend(result, {label: label, value: value});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(styleType: SelectorType, value: any): string {\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 let template = '';\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${value[k]}`;\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 propertyKey: string = styleRule.style.color.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, styleRule.style.color.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, styleRule.style.color.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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linkurious/ogma-linkurious-parser",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"author": "Linkurious SAS",
|
|
5
5
|
"description": "Parse and load a Linkurious visualization in Ogma with one line of code ",
|
|
6
6
|
"files": [
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@linkurious/ogma": "4.1.4",
|
|
56
|
-
"@linkurious/rest-client": "3.1.
|
|
56
|
+
"@linkurious/rest-client": "3.1.8",
|
|
57
57
|
"@rollup/plugin-buble": "0.21.3",
|
|
58
58
|
"@rollup/plugin-commonjs": "17.0.0",
|
|
59
59
|
"@rollup/plugin-json": "4.1.0",
|