@linkurious/ogma-linkurious-parser 4.0.24 → 4.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -33
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ogma/features/captions.js +3 -1
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/nodeGrouping.d.ts +68 -0
- package/dist/ogma/features/nodeGrouping.js +247 -0
- package/dist/ogma/features/nodeGrouping.js.map +1 -0
- package/dist/ogma/features/styles.d.ts +1 -0
- package/dist/ogma/features/styles.js +24 -6
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.js +8 -3
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.d.ts +22 -5
- package/dist/ogma/index.js +31 -12
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/nodeAttributes.d.ts +8 -1
- package/dist/styles/nodeAttributes.js +18 -4
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/package.json +2 -2
|
@@ -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,uBAAe,KAAf,uBAAe,QAG1B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAC5D,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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IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,wBAAwB,CACpC,KAA2C,EAC3C,QAAoB;QAEpB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAK,CAAC,OAAO,CAAC,KAAK,CAAE,CAAC,EAAE;YACtF,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACpC,OAAO,aAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;SAC1C;IACH,CAAC;CACF;AAtPD,wCAsPC","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 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(style.image.url, itemData);\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 */\n public static getImageUrlFromStyleRule(\n value: string | IImageDataValue | undefined,\n itemData: LkNodeData\n ): string | undefined {\n if (typeof value === 'string' && ['imageUrl', 'image'].includes(Tools.getType(value)!)) {\n return value;\n } else if (typeof value === 'object') {\n return Tools.getIn(itemData, value.path);\n }\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,GAAf,uBAAe,KAAf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C,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linkurious/ogma-linkurious-parser",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.25",
|
|
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.5.5",
|
|
56
|
-
"@linkurious/rest-client": "4.0.
|
|
56
|
+
"@linkurious/rest-client": "4.0.25",
|
|
57
57
|
"@rollup/plugin-buble": "0.21.3",
|
|
58
58
|
"@rollup/plugin-commonjs": "17.0.0",
|
|
59
59
|
"@rollup/plugin-json": "4.1.0",
|