diff options
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx index 486fe7f7e..708170359 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx @@ -24,33 +24,44 @@ export class Template { } setupMainField = (templateInfo: FieldSettings) => { - return new DynamicField(templateInfo, ViewType.FREEFORM, 0); + return new DynamicField(templateInfo, 0); } isValidTemplate = (cols: Col[]) => { - return this.maxMatches(this.getMatches(cols)) === this.contentFields.length; + const matches: number[][] = this.getMatches(cols); + const maxMatches: number = this.maxMatches(matches); + return maxMatches === this.contentFields.length; } - getMatches = (cols: Col[]) => { - const matches: number[][] = Array(this.contentFields.length) + getMatches = (cols: Col[]): number[][] => { + const numFields = this.contentFields.length; + + if (cols.length !== numFields) return []; + + const matches: number[][] = Array(numFields) .fill([]) .map(() => []); this.contentFields.forEach((field, i) => { - matches[i].concat(field.matches(cols)); + matches[i] = (field.matches(cols)); }); return matches; } maxMatches = (matches: number[][]) => { + if (matches.length === 0) return 0; + const fieldsCt = this.contentFields.length; const used: boolean[] = Array(fieldsCt).fill(false); const mt: number[] = Array(fieldsCt).fill(-1); + console.log(matches, fieldsCt); + const augmentingPath = (v: number): boolean => { if (used[v]) return false; used[v] = true; + for (const to of matches[v]) { if (mt[to] === -1 || augmentingPath(mt[to])) { mt[to] = v; |