aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-10-29 04:02:29 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-10-29 04:02:29 -0400
commit691fc130de706c691a42f7e87688c14102016ccc (patch)
treeaf29b634c73be79ee18883ddb1b2d0ef1ab0b80c /src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
parent857797d1d47f22b641d1bddb4177028c26677f19 (diff)
starting to integrate refactor with docreatormenu functionality
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
index f05f61b61..486fe7f7e 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
@@ -1,11 +1,11 @@
import { Doc } from "../../../../../fields/Doc";
import { Docs } from "../../../../documents/Documents";
+import { Col } from "./DocCreatorMenu";
import { DynamicField } from "./FieldTypes/DynamicField";
import { Field, FieldSettings, ViewType } from "./FieldTypes/Field";
import { } from "./FieldTypes/FieldUtils";
import { } from "./FieldTypes/StaticField";
-import { TemplateDocInfos } from "./TemplateBackend";
export class Template {
@@ -17,9 +17,61 @@ export class Template {
get childFields(): Field[] { return this.mainField.getSubfields };
get allFields(): Field[] { return this.mainField.getAllSubfields };
+ get contentFields(): Field[] { return this.allFields.filter(field => field.getViewType === ViewType.STATIC) };
+
+ getFieldByID = (id: number): Field => {
+ return this.allFields.filter(field => field.getID === id)[0];
+ }
setupMainField = (templateInfo: FieldSettings) => {
return new DynamicField(templateInfo, ViewType.FREEFORM, 0);
}
+ isValidTemplate = (cols: Col[]) => {
+ return this.maxMatches(this.getMatches(cols)) === this.contentFields.length;
+ }
+
+ getMatches = (cols: Col[]) => {
+ const matches: number[][] = Array(this.contentFields.length)
+ .fill([])
+ .map(() => []);
+
+ this.contentFields.forEach((field, i) => {
+ matches[i].concat(field.matches(cols));
+ });
+
+ return matches;
+ }
+
+ maxMatches = (matches: number[][]) => {
+ const fieldsCt = this.contentFields.length;
+ const used: boolean[] = Array(fieldsCt).fill(false);
+ const mt: number[] = Array(fieldsCt).fill(-1);
+
+ 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;
+ return true;
+ }
+ }
+ return false;
+ };
+
+ for (let v = 0; v < fieldsCt; ++v) {
+ used.fill(false);
+ augmentingPath(v);
+ }
+
+ let count: number = 0;
+
+ for (let i = 0; i < fieldsCt; ++i) {
+ if (mt[i] !== -1) ++count;
+ }
+
+ return count;
+ };
+
} \ No newline at end of file