Skip to content

Commit

Permalink
Merge pull request #90 from VisActor/demo/81-add-demo-to-express-prod…
Browse files Browse the repository at this point in the history
…uct-raodmap

Demo/81 add demo to express product roadmap
  • Loading branch information
fangsmile committed Jul 3, 2023
2 parents 7361bb0 + 87d425f commit bdc5a05
Show file tree
Hide file tree
Showing 13 changed files with 977 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix problems width customRender expectedWidth and expectedHeight\n\n",
"type": "patch",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: add custom element line type\n\n",
"type": "patch",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
436 changes: 436 additions & 0 deletions packages/vtable/examples/business/roadmap.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/vtable/examples/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ export const menus = [
{
path: 'business',
name: 'three'
},
{
path: 'business',
name: 'roadmap'
}
]
},
Expand Down
450 changes: 450 additions & 0 deletions packages/vtable/site-demo/business/roadmap.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/vtable/site-demo/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export const menus = [
{
path: 'business',
name: 'temperature-trend'
},
{
path: 'business',
name: 'roadmap'
}
]
},
Expand Down
43 changes: 25 additions & 18 deletions packages/vtable/src/scenegraph/component/custom.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import type { Cursor } from '@visactor/vrender';
import { createArc, createCircle, createRect, TextAlignType, TextBaselineType } from '@visactor/vrender';
import { isFunction, isString } from '../../tools/util';
import type {
ICustomLayout,
ICustomRender,
ICustomRenderElement,
ICustomRenderElements,
ICustomRenderFuc,
ICustomRenderObj
} from '../../ts-types';
import { createArc, createCircle, createLine, createRect, TextAlignType, TextBaselineType } from '@visactor/vrender';
import { isFunction, isString, isValid } from '../../tools/util';
import type { ICustomLayout, ICustomRender, ICustomRenderElement, ICustomRenderElements } from '../../ts-types';
import { Group } from '../graphic/group';
import { Icon } from '../graphic/icon';
import { WrapText } from '../graphic/text';
import type { BaseTableAPI } from '../../ts-types/base-table';
import type { Rect } from '../../render/layout';

export function dealWithCustom(
customLayout: ICustomLayout,
Expand Down Expand Up @@ -227,6 +221,16 @@ function adjustElementToGroup(
image.role = 'image-custom';
customGroup.appendChild(image);
break;

case 'line':
const line = createLine({
points: element.points,
stroke: element.stroke as string,
pickable: !!element.clickable,
cursor: element.cursor as Cursor
});
customGroup.appendChild(line);
break;
}
});

Expand Down Expand Up @@ -258,12 +262,15 @@ function adjustElementsPos(
}

// 转换字符串值(百分比、px)
element.x = isString(element.x)
? transformString(element.x as string, width - borderLineWidths[1])
: Number(element.x);
element.y = isString(element.y)
? transformString(element.y as string, height - borderLineWidths[2])
: Number(element.y);
const rect = element as Rect;
if (isValid(rect.x)) {
rect.x = isString(rect.x)
? transformString((rect as any).x as string, width - borderLineWidths[1])
: Number(rect.x);
rect.y = isString(rect.y)
? transformString((rect as any).y as string, height - borderLineWidths[2])
: Number(rect.y);
}
if ('width' in element) {
element.width = isString(element.width)
? transformString(element.width as string, width - borderLineWidths[1])
Expand Down Expand Up @@ -298,8 +305,8 @@ function adjustElementsPos(
element.hover.y += top;
}
// 矫正位置
element.x = element.x + left;
element.y = element.y + top;
rect.x = rect.x + left;
rect.y = rect.y + top;

result.push(element as unknown as ICustomRenderElement);
}
Expand Down
13 changes: 4 additions & 9 deletions packages/vtable/src/scenegraph/group-creater/cell-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function createCell(
}
}

let elementsGroup;
let customElementsGroup;
let renderDefault = true;
let customRender;
let customLayout;
Expand All @@ -120,7 +120,7 @@ export function createCell(
autoRowHeight,
table
);
elementsGroup = customResult.elementsGroup;
customElementsGroup = customResult.elementsGroup;
renderDefault = customResult.renderDefault;
}
cellGroup = createCellGroup(
Expand All @@ -138,20 +138,14 @@ export function createCell(
textBaseline,
mayHaveIcon,
isfunctionalProps,
customElementsGroup,
renderDefault,
cellTheme
);
if (isMerge) {
cellGroup.mergeCol = range.end.col;
cellGroup.mergeRow = range.end.row;
}
if (elementsGroup) {
cellGroup.appendChild(elementsGroup);
cellGroup.setAttributes({
width: Math.max(cellGroup.attribute.width, elementsGroup.attribute.width),
height: Math.max(cellGroup.attribute.height, elementsGroup.attribute.height)
});
}
} else if (type === 'image') {
// 创建图片单元格
cellGroup = createImageCellGroup(
Expand Down Expand Up @@ -225,6 +219,7 @@ export function createCell(
textBaseline,
false,
true,
null,
true,
cellTheme
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function createCellGroup(
textBaseline: CanvasTextBaseline,
mayHaveIcon: boolean,
isfunctionalProps: boolean,
customElementsGroup: Group,
renderDefault: boolean,
cellTheme?: IThemeSpec
): Group {
Expand Down Expand Up @@ -86,7 +87,9 @@ export function createCellGroup(
cellGroup.col = col;
cellGroup.row = row;
columnGroup.addChild(cellGroup);

if (customElementsGroup) {
cellGroup.appendChild(customElementsGroup);
}
if (renderDefault) {
const textStr: string = table.getCellValue(col, row);
let icons;
Expand Down Expand Up @@ -128,6 +131,12 @@ export function createCellGroup(
cellGroup.appendChild(mark);
}
}
if (customElementsGroup) {
cellGroup.setAttributes({
width: Math.max(cellGroup.attribute.width, customElementsGroup.attribute.width),
height: Math.max(cellGroup.attribute.height, customElementsGroup.attribute.height)
});
}
return cellGroup;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/vtable/src/scenegraph/layout/update-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ export function updateCellHeight(
false,
scene.table
);
cell.appendChild(customResult.elementsGroup);
if (cell.childrenCount > 0) {
cell.insertBefore(customResult.elementsGroup, cell.firstChild);
} else {
cell.appendChild(customResult.elementsGroup);
}
}
}
}
1 change: 1 addition & 0 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export interface BaseTableAPI {

resize: () => void;

getMergeCellRect: (col: number, row: number) => Rect;
//#endregion tableAPI
}
export interface ListTableProtected extends IBaseTableProtected {
Expand Down
15 changes: 14 additions & 1 deletion packages/vtable/src/ts-types/customElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export interface TextElement extends baseElement {
cornerRadius?: number;
};
}
export interface LineElement extends Omit<baseElement, 'x' | 'y'> {
type: 'line';
stroke?: string | ((value: string) => string);
points: { x: number; y: number }[];
lineWidth?: number;
}

export interface RectElement extends baseElement {
type: 'rect';
Expand Down Expand Up @@ -104,7 +110,14 @@ export interface ImageElement extends baseElement {
};
shape?: 'circle' | 'square';
}
export type ICustomRenderElement = TextElement | RectElement | CircleElement | IconElement | ImageElement | ArcElement;
export type ICustomRenderElement =
| TextElement
| RectElement
| CircleElement
| IconElement
| ImageElement
| ArcElement
| LineElement;
export type ICustomRenderElements = Array<ICustomRenderElement>;

export type ICustomRenderFuc = (args: CustomRenderFunctionArg) => ICustomRenderObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ICustomLayout } from '../../customLayout';
import type { FieldDef, FieldFormat, FieldKeyDef } from '../../table-engine';
import type { ColumnIconOption } from '../../icon';
import type { MenuListItem } from '../../menu';
import type { BaseTableAPI } from '../../base-table';

// eslint-disable-next-line no-unused-vars
export interface IBasicHeaderDefine {
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface IBasicColumnBodyDefine {
| string
| ColumnIconOption
| (string | ColumnIconOption)[]
| ((args: CellInfo) => string | ColumnIconOption | (string | ColumnIconOption)[]);
| ((args: CellInfo & { table: BaseTableAPI }) => string | ColumnIconOption | (string | ColumnIconOption)[]);

// columnType?: ColumnTypeOption | BaseColumn<T, any> | null;

Expand Down

0 comments on commit bdc5a05

Please sign in to comment.