diff options
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx index 01d5bc83b..8afd1bbf1 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx @@ -604,7 +604,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { } }) - validTemplates = validTemplates.map(title => TemplateLayouts.fieldByTitle(title)); + validTemplates = validTemplates.map(title => TemplateLayouts.getTemplateByTitle(title)); return validTemplates; }; @@ -667,7 +667,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const field: Field = template.fields[Number(info.number)]; const col = this.getColByTitle(title); - const doc = FieldFuncs.TextField({ + const doc = FieldUtils.TextField({ tl: field.tl, br: field.br }, template.height, @@ -692,7 +692,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const createGeneratedImage = async(fieldNum: string, col: Col, prompt: string) => { const url = await this.generateGPTImage(prompt); const field: Field = template.fields[Number(fieldNum)]; - const doc = FieldFuncs.ImageField({ + const doc = FieldUtils.ImageField({ tl: field.tl, br: field.br }, template.height, @@ -755,7 +755,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const field: Field = template.fields[Number(f)]; const col = strCol[1]; - const doc = (col.type === TemplateFieldType.VISUAL ? FieldFuncs.ImageField : FieldFuncs.TextField)({ + const doc = (col.type === TemplateFieldType.VISUAL ? FieldUtils.ImageField : FieldUtils.TextField)({ tl: field.tl, br: field.br }, template.height, @@ -771,7 +771,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { }); template.decorations.forEach(dec => { - const doc = FieldFuncs.FreeformField({ + const doc = FieldUtils.FreeformField({ tl: dec.tl, br: dec.br }, template.height, @@ -856,7 +856,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const brokenDownAssignments: [TemplateDocInfos, {[field: number]: Col}][] = []; Object.entries(assignments).forEach(([tempTitle, assignment]) => { - const template = TemplateLayouts.fieldByTitle(tempTitle); + const template = TemplateLayouts.getTemplateByTitle(tempTitle); if (!template) return; const toObj = Object.entries(assignment).reduce((a, [fieldNum, colTitle]) => { a[Number(fieldNum)] = this.getColByTitle(colTitle); @@ -1468,14 +1468,45 @@ export type Col = { } type Field = { - tl: [number, number], - br: [number, number], - types?: TemplateFieldType[], - sizes?: TemplateFieldSize[], - description?: string; + tl: [number, number]; + br: [number, number]; opts: FieldOpts; - subfields?: ['freeform' | 'stacking' | 'carousel', Field[]]; -}; + subfields?: Field[]; + types?: TemplateFieldType[]; + sizes?: TemplateFieldSize[]; + isDecoration?: boolean; + description?: string; +} + +// class ContentField implements Field { +// tl: [number, number]; +// br: [number, number]; +// opts: FieldOpts; +// subfields?: Field[]; +// types?: TemplateFieldType[]; +// sizes?: TemplateFieldSize[]; +// description?: string; + +// constructor( tl: [number, number], br: [number, number], +// opts: FieldOpts, subfields?: Field[], +// types?: TemplateFieldType[], +// sizes?: TemplateFieldSize[], +// description?: string) { +// this.tl = tl; +// this.br = br; +// this.opts = opts; +// this.subfields = subfields; +// this.types = types; +// this.sizes = sizes; +// this.description = description; +// } + +// render = (content: any): Doc => { +// return new Doc; +// } +// } + +type DecorationField = Field; type InkDecoration = { @@ -1505,13 +1536,24 @@ export interface FieldOpts { //animation?: boolean; fontBold?: boolean; fontTransform?: 'uppercase' | 'lowercase'; + fieldViewType?: 'freeform' | 'stacked'; } interface TemplateOpts extends FieldOpts { } -export class FieldFuncs { +export class FieldUtils { + + public static contentFields = (fields: Field[]) => { + let toRet: Field[] = []; + fields.forEach(field => { + if (!field.isDecoration) { toRet.push(field) }; + toRet = toRet.concat(FieldUtils.contentFields(field.subfields ?? [])); + }); + + return toRet; + } public static calculateFontSize = (contWidth: number, contHeight: number, text: string, uppercase: boolean): number => { const words: string[] = text.split(/\s+/).filter(Boolean); @@ -1555,9 +1597,6 @@ export class FieldFuncs { return currFontSize - 1; }; - - - private static getDimensions = (coords: {tl: [number, number], br: [number, number]}, parentWidth: number, parentHeight: number): {width: number, height: number, coord: {x: number, y: number}} => { const l = coords.tl[0] * parentHeight / 2; const t = coords.tl[1] * parentWidth / 2; //prettier-ignore @@ -1570,7 +1609,7 @@ export class FieldFuncs { } public static FreeformField = (coords: {tl: [number, number], br: [number, number]}, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => { - const {width, height, coord} = FieldFuncs.getDimensions(coords, parentWidth, parentHeight); + const {width, height, coord} = FieldUtils.getDimensions(coords, parentWidth, parentHeight); const docWithBasicOpts = (Docs.Create.FreeformDocument)([], { isDefaultTemplateDoc: true, @@ -1592,7 +1631,7 @@ export class FieldFuncs { } public static TextField = (coords: {tl: [number, number], br: [number, number]}, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => { - const {width, height, coord} = FieldFuncs.getDimensions(coords, parentWidth, parentHeight); + const {width, height, coord} = FieldUtils.getDimensions(coords, parentWidth, parentHeight); const bool = true; @@ -1603,7 +1642,7 @@ export class FieldFuncs { title: title, x: coord.x, y: coord.y, - _text_fontSize: `${FieldFuncs.calculateFontSize(width, height, content, true)}` , + _text_fontSize: `${FieldUtils.calculateFontSize(width, height, content, true)}` , backgroundColor: opts.backgroundColor ?? '', text_fontColor: opts.color, contentBold: opts.fontBold, @@ -1623,7 +1662,7 @@ export class FieldFuncs { } public static ImageField = (coords: {tl: [number, number], br: [number, number]}, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => { - const {width, height, coord} = FieldFuncs.getDimensions(coords, parentWidth, parentHeight); + const {width, height, coord} = FieldUtils.getDimensions(coords, parentWidth, parentHeight); const doc = Docs.Create.ImageDocument(content, { isDefaultTemplateDoc: true, @@ -1647,7 +1686,7 @@ export class FieldFuncs { } public static CarouselField = (coords: {tl: [number, number], br: [number, number]}, parentWidth: number, parentHeight: number, title: string, fields: Doc[]) => { - const {width, height, coord} = FieldFuncs.getDimensions(coords, parentWidth, parentHeight); + const {width, height, coord} = FieldUtils.getDimensions(coords, parentWidth, parentHeight); const doc = Docs.Create.Carousel3DDocument(fields, { _height: height, _width: width, title: title, x: coord.x, y: coord.y, _text_fontSize: `${height/2}` }) @@ -1664,7 +1703,7 @@ export class TemplateLayouts { ) as TemplateDocInfos[]; } - public static fieldByTitle = (title: string): TemplateDocInfos | undefined => { + public static getTemplateByTitle = (title: string): TemplateDocInfos | undefined => { switch (title){ case 'fourfield1': return TemplateLayouts.FourField001; @@ -1984,18 +2023,6 @@ export class TemplateLayouts { borderWidth: '8', rotation: 45, }, - subfields: [ - 'freeform', - [{ - tl: [-2, -2], - br: [2, 2], - types: [TemplateFieldType.VISUAL], - sizes: [TemplateFieldSize.LARGE, TemplateFieldSize.HUGE], - opts: { - rotation: 315, - } - }] - ] }, { tl: [-.7, .2], br: [.7, .46], |