Skip to content

Commit

Permalink
Fixed issues #15 and #16 + added tests + updated dependencies (v3.2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanichKotikov committed Jul 18, 2022
1 parent 20c27a2 commit 662eb51
Show file tree
Hide file tree
Showing 10 changed files with 1,110 additions and 1,305 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/lib
/.cache
/dist
.idea
28 changes: 28 additions & 0 deletions __tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import spouses from '../samples/several-spouses.json';
import spouses2 from '../samples/several-spouses-n2.json';
import testTree1 from '../samples/test-tree-n1.json';
import testTree2 from '../samples/test-tree-n2.json';
import testTree3 from '../samples/test-tree-n3.json';
import testTree4 from '../samples/test-tree-n4.json';
import average from '../samples/average-tree.json';

type ResultObj = { [id: string]: boolean | string };
Expand All @@ -26,6 +28,8 @@ const spousesTree = calcTree(spouses as any, { rootId: 'js2RsE5sr' });
const spousesTreeN2 = calcTree(spouses2 as any, { rootId: '957875050' });
const testTreeN1 = calcTree(testTree1 as any, { rootId: 'aeqW' });
const testTreeN2 = calcTree(testTree2 as any, { rootId: 'uJK9' });
const testTreeN3 = calcTree(testTree3 as any, { rootId: '1' });
const testTreeN4 = calcTree(testTree4 as any, { rootId: '1' });
const average1 = calcTree(average as any, { rootId: 'kuVISwh7w' });
const average2 = calcTree(average as any, { rootId: 'PXACjDxmR' });
const average3 = calcTree(average as any, { rootId: 'UIEjvLJMd' });
Expand Down Expand Up @@ -390,6 +394,30 @@ test('Node position', () => {
'yZwk': '6|6',
});
equal(convert(testTreeN2.nodes), { aCZW: '0|0', uJK9: '0|2', wIFr: '0|4', s9HE: '2|0' });
equal(
convert(testTreeN3.nodes),
{
'1': '6|7',
'2': '4|8',
'3': '4|6',
'4': '2|12',
'5': '2|10',
'6': '2|2',
'7': '2|4',
'8': '0|8',
'9': '0|10',
'10': '0|12',
'11': '0|14',
'12': '0|0',
'13': '0|2',
'14': '0|6',
'15': '0|4',
},
);
equal(
convert(testTreeN4.nodes),
{ '1': '6|2', '2': '4|1', '3': '4|3', '4': '2|0', '5': '2|4', '6': '0|0', '7': '0|2', '8': '0|4' },
);
equal(convert(average1.nodes), {
'011jVS4rb': '4|6',
'PXACjDxmR': '4|8',
Expand Down
42 changes: 23 additions & 19 deletions docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@ import spouses from '../../samples/several-spouses.json';
import spouses2 from '../../samples/several-spouses-n2.json';
import testTree1 from '../../samples/test-tree-n1.json';
import testTree2 from '../../samples/test-tree-n2.json';
import testTree3 from '../../samples/test-tree-n3.json';
import testTree4 from '../../samples/test-tree-n4.json';
import average from '../../samples/average-tree.json';
import { draw } from './render';

const content = document.getElementById('content');
if (!content) throw new Error('There is no content element');

const data: { [key: string]: any[] } = {
'gRstruEr4': empty,
'jsyRsE5sr': couple,
'dyTpfj6sr': simple,
'dyTpfj6st': diff,
'user4': divorced,
'js2RsE5sr': spouses,
'957875050': spouses2,
'aeqW': testTree1,
'uJK9': testTree2,
'kuVISwh7w': average,
'PXACjDxmR': average,
'UIEjvLJMd': average,
'RZbkr5vAi': average,
'Fbc9iwnJl': average,
'2DlrR0fK8': average,
};
const data: readonly { id: string, nodes: any[] }[] = [
{ id: 'gRstruEr4', nodes: empty },
{ id: 'jsyRsE5sr', nodes: couple },
{ id: 'dyTpfj6sr', nodes: simple },
{ id: 'dyTpfj6st', nodes: diff },
{ id: 'user4', nodes: divorced },
{ id: 'js2RsE5sr', nodes: spouses },
{ id: 'uJK9', nodes: testTree2 },
{ id: '957875050', nodes: spouses2 },
{ id: 'aeqW', nodes: testTree1 },
{ id: 'kuVISwh7w', nodes: average },
{ id: 'PXACjDxmR', nodes: average },
{ id: 'UIEjvLJMd', nodes: average },
{ id: 'RZbkr5vAi', nodes: average },
{ id: 'Fbc9iwnJl', nodes: average },
{ id: '2DlrR0fK8', nodes: average },
{ id: '1', nodes: testTree3 },
{ id: '1', nodes: testTree4 },
];

function drawTree(el: HTMLElement, nodes: Node[], rootId: string) {
const canvas = document.createElement('canvas');
Expand All @@ -41,6 +45,6 @@ function drawTree(el: HTMLElement, nodes: Node[], rootId: string) {
draw(canvas, tree, { root: rootId, debug: false });
}

Object.keys(data).forEach(id => {
drawTree(content, data[id]!, id);
data.forEach(({ id, nodes }) => {
drawTree(content, nodes, id);
});
4 changes: 3 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "../tsconfig",
"compilerOptions": {}
"compilerOptions": {
"resolveJsonModule": true
}
}
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit 662eb51

Please sign in to comment.