diff options
6 files changed, 38 insertions, 21 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx index 46266883f..a1de81fa3 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx @@ -469,7 +469,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { }; testTemplate = async () => { - this.updateIcons(this._suggestedTemplates.slice()); + + console.log(this.templateManager.templates); + this.forceUpdate(); // try { diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx index 220d938ff..f235d3218 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx @@ -7,7 +7,6 @@ import { FieldUtils } from "./FieldUtils"; import { StaticField } from "./StaticField"; export class DynamicField implements Field { - private type: ViewType; private subfields: Field[] = []; private id: number; @@ -17,8 +16,7 @@ export class DynamicField implements Field { private parent: Field; private dimensions: FieldDimensions; - constructor(settings: FieldSettings, type: ViewType, id: number, parent?: Field) { - this.type = type; + constructor(settings: FieldSettings, id: number, parent?: Field) { this.id = id; this.settings = settings; if (settings.title) { this.title = settings.title }; @@ -50,7 +48,7 @@ export class DynamicField implements Field { get getDimensions() { return this.dimensions }; get getID() { return this.id }; - get getViewType() { return this.type }; + get getViewType() { return this.settings.viewType }; get getDescription(): string { return this.settings.description ?? ''; @@ -61,16 +59,17 @@ export class DynamicField implements Field { } setupSubfields = (): Field[] => { + const fields: Field[] = []; this.settings.subfields?.forEach(fieldSettings => { let field: Field; const dynamicType = fieldSettings.viewType; - if (dynamicType) { field = new DynamicField(fieldSettings, dynamicType, 0, this); } + if (dynamicType) { field = new DynamicField(fieldSettings, 0, this); } field = new StaticField(fieldSettings, this, 0); - this.subfields?.push(field); + fields.push(field); }); - return []; + return fields; } getChildDimensions = (coords: { tl: [number, number]; br: [number, number] }): FieldDimensions => { @@ -85,7 +84,7 @@ export class DynamicField implements Field { }; renderedDoc = (): Doc => { - switch (this.type) { + switch (this.settings.viewType) { case ViewType.CAROUSEL3D: const carouselDoc = Docs.Create.Carousel3DDocument([], { title: this.title, diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx index 809b40520..0f3631858 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx @@ -44,7 +44,7 @@ export class StaticField { get getDimensions() { return this.dimensions }; get getID() { return this.id }; - get getViewType() { return ViewType.STATIC }; + get getViewType() { return this.settings.viewType }; get getDescription(): string { return this.settings.description ?? ''; @@ -63,10 +63,10 @@ export class StaticField { const fields: Field[] = []; this.settings.subfields?.forEach(fieldSettings => { let field: Field; - const dynamicType = fieldSettings.viewType; + const type = fieldSettings.viewType; - if (dynamicType) { - field = new DynamicField(fieldSettings, dynamicType, 0, this); + if (type === ViewType.FREEFORM || type === ViewType.CAROUSEL3D) { + field = new DynamicField(fieldSettings, 0, this); } else { field = new StaticField(fieldSettings, this, 0); }; @@ -78,8 +78,12 @@ export class StaticField { matches = (cols: Col[]): number[] => { const colMatchesField = (col: Col) => { - return this.settings.sizes?.some(size => col.sizes?.includes(size)) && this.settings.types?.includes(col.type); - }; + const isMatch: boolean = ( + this.settings.sizes?.some(size => col.sizes?.includes(size)) + && this.settings.types?.includes(col.type)) + ?? false; + return isMatch; + } const matches: Array<number> = []; 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; diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx index 00eb8fab4..a23c3ba3d 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx @@ -17,7 +17,7 @@ export enum TemplateFieldSize { export class TemplateLayouts { public static get allTemplates(): FieldSettings[] { - return Object.values(TemplateLayouts).filter(value => typeof value === 'object' && value !== null && 'title' in value) as FieldSettings[]; + return Object.values(TemplateLayouts); } public static FourField001: FieldSettings = { diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx index d47ae802c..535bd423f 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx @@ -30,6 +30,7 @@ export class TemplateManager { } getValidTemplates = (cols: Col[]): Template[] => { + console.log(this.templates.filter(template => template.isValidTemplate(cols))); return this.templates.filter(template => template.isValidTemplate(cols)); } }
\ No newline at end of file |