tycho-components 0.40.6 → 0.40.7
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,5 +1,6 @@
|
|
|
1
1
|
import { EdgeDefinition, NodeDefinition, Position } from 'cytoscape';
|
|
2
2
|
import { Conllu, ConlluToken, Struct } from '../../configs';
|
|
3
|
+
import { ConlluViewerDependency, ConlluViewerGraph, ConlluViewerItem } from './ConlluViewerGraph';
|
|
3
4
|
export type CytoscapeTree = {
|
|
4
5
|
nodes: NodeDefinition[];
|
|
5
6
|
edges: EdgeDefinition[];
|
|
@@ -16,5 +17,9 @@ declare const ConlluUtils: {
|
|
|
16
17
|
deleteToken: (conllu: Conllu, tokenIndex: number) => Conllu;
|
|
17
18
|
getConlluTranslationFromStruct: (struct: Struct | undefined, lang: string) => string;
|
|
18
19
|
generateImageFromSVG: (svgElement: SVGSVGElement) => void;
|
|
20
|
+
isActiveDependency: (dep: ConlluViewerDependency, activeItem: ConlluViewerItem | undefined) => boolean;
|
|
21
|
+
isActiveItem: (item: ConlluViewerItem, activeItem: ConlluViewerItem | undefined) => boolean;
|
|
22
|
+
calculateAnchor: (graph: ConlluViewerGraph, i1: number, i2: number, lvl: number) => number;
|
|
23
|
+
escapeHTML: (str: string) => string;
|
|
19
24
|
};
|
|
20
25
|
export default ConlluUtils;
|
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
import { saveAs } from 'file-saver';
|
|
2
|
+
const escapeHTML = (str) => {
|
|
3
|
+
return str || '';
|
|
4
|
+
// return str.replace(/[&<>"'`]/g, (match) => {
|
|
5
|
+
// const escapeMap: Record<string, string> = {
|
|
6
|
+
// '&': '&',
|
|
7
|
+
// '<': '<',
|
|
8
|
+
// '>': '>',
|
|
9
|
+
// '"': '"',
|
|
10
|
+
// "'": ''',
|
|
11
|
+
// '`': '`',
|
|
12
|
+
// };
|
|
13
|
+
// return escapeMap[match];
|
|
14
|
+
// });
|
|
15
|
+
};
|
|
16
|
+
const calculateAnchor = (graph, i1, i2, lvl) => {
|
|
17
|
+
const a = graph.anchors[i1];
|
|
18
|
+
if (a.length === 1) {
|
|
19
|
+
if (i1 < i2) {
|
|
20
|
+
return 0.75;
|
|
21
|
+
}
|
|
22
|
+
return 0.25;
|
|
23
|
+
}
|
|
24
|
+
let n = 0;
|
|
25
|
+
for (let i = 0; i < a.length; i++) {
|
|
26
|
+
const v = a[i];
|
|
27
|
+
if (v.dist === i2 - i1 && v.level === lvl) {
|
|
28
|
+
n = i;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return (n + 0.5) / a.length;
|
|
33
|
+
};
|
|
34
|
+
const isActiveDependency = (dep, activeItem) => {
|
|
35
|
+
if (!activeItem)
|
|
36
|
+
return false;
|
|
37
|
+
return (dep.headpos === Number(activeItem.here) ||
|
|
38
|
+
dep.end === Number(activeItem.here));
|
|
39
|
+
};
|
|
40
|
+
const isActiveItem = (item, activeItem) => {
|
|
41
|
+
if (!activeItem)
|
|
42
|
+
return false;
|
|
43
|
+
return (activeItem.here === item.there ||
|
|
44
|
+
activeItem.there === item.here ||
|
|
45
|
+
activeItem.lineno === item.lineno);
|
|
46
|
+
};
|
|
2
47
|
const convertStructToConllu = (struct) => {
|
|
3
48
|
return {
|
|
4
49
|
uid: struct.uid,
|
|
@@ -267,5 +312,9 @@ const ConlluUtils = {
|
|
|
267
312
|
deleteToken,
|
|
268
313
|
getConlluTranslationFromStruct,
|
|
269
314
|
generateImageFromSVG,
|
|
315
|
+
isActiveDependency,
|
|
316
|
+
isActiveItem,
|
|
317
|
+
calculateAnchor,
|
|
318
|
+
escapeHTML,
|
|
270
319
|
};
|
|
271
320
|
export default ConlluUtils;
|