public createRootMatrixNode()

in src/dataViewBuilder/matrixBuilder.ts [189:226]


    public createRootMatrixNode(rows: string[][], rowNames: string[], columns?: [][], columnNames?: string[]): DataViewMatrixNode {
        let root = {
            children: []
        };
        const length = rows[0].length;
        if (rows.find(row => row.length !== length) || columns && columns.find(col => col.length !== length)) {
            throw "Invalid data input";
        }

        const depth: number = rows.length - 1;
        let identityIndexIterator = 0;
        let currentRoot: DataViewMatrixNode;
        for (let i = 0; i < length; i++) {
            currentRoot = root;
            for (let j = 0; j <= depth; j++) {
                const foundNode = currentRoot.children.filter(node => node.value === rows[i][j]);
                if (foundNode.length > 1) {
                    throw "Unexpected duplicate found";
                } else if (foundNode.length === 1) {
                    currentRoot = foundNode.pop();
                } else if (foundNode.length === 0) {
                    let newNode: DataViewMatrixNode = {
                        children: [],
                        identity: {
                            identityIndex: identityIndexIterator++
                        },
                        value: rows[i][j]
                    };
                    if (j === depth) {
                        // fill values
                    }
                    currentRoot.children.push(newNode);
                    currentRoot = newNode;
                }
            }
        }
        return root;
    }