Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add merge cell custom graphic attribute sync #1718 #1809

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "feat: add merge cell custom graphic attribute sync #1718",
"type": "minor"
}
],
"packageName": "@visactor/vtable"
}
255 changes: 227 additions & 28 deletions packages/vtable/examples/custom/custom-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,33 @@ export function createTable() {
}
},
{
field: 'fansCount',
title: '粉丝数',
style: {
fontFamily: 'Arial',
fontSize: 12,
fontWeight: 'bold'
},
fieldFormat(rec) {
return rec.fansCount + 'w';
}
},
{
field: 'viewCount',
title: '播放量',
fieldFormat(rec) {
return rec.fansCount + 'w';
},
style: {
fontFamily: 'Arial',
fontSize: 12,
fontWeight: 'bold'
}
title: 'sum',
columns: [
{
field: 'fansCount',
title: '粉丝数',
style: {
fontFamily: 'Arial',
fontSize: 12,
fontWeight: 'bold'
},
fieldFormat(rec) {
return rec.fansCount + 'w';
}
},
{
field: 'viewCount',
title: '播放量',
fieldFormat(rec) {
return rec.fansCount + 'w';
},
style: {
fontFamily: 'Arial',
fontSize: 12,
fontWeight: 'bold'
}
}
]
},
{
field: 'viewCount',
Expand Down Expand Up @@ -347,7 +352,96 @@ export function createTable() {
field: '',
title: '操作',
width: 100,
icon: ['favorite', 'message']
icon: ['favorite', 'message'],
headerCustomLayout: args => {
const { table, row, col, rect } = args;
const { height, width } = rect || table.getCellRect(col, row);
const percentCalc = VTable.CustomLayout.percentCalc;
const container = new VTable.CustomLayout.Group({
height,
width,
display: 'flex',
flexDirection: 'row',
flexWrap: 'nowrap'
});
const containerLeft = new VTable.CustomLayout.Group({
height: percentCalc(100),
width: 160,
display: 'flex',
direction: 'column',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'space-around',
fill: 'blue',
// dx: 200
x: 200
});
container.add(containerLeft);

containerLeft.addEventListener('click', () => {
containerLeft.setAttributes({ fill: 'red' });
});

const containerRight = new VTable.CustomLayout.Group({
height: percentCalc(100),
width: percentCalc(100, -50),
display: 'flex',
direction: 'column'
// justifyContent: 'center'
});
container.add(containerRight);

const containerRightTop = new VTable.CustomLayout.Group({
id: 'containerRightTop',
height: percentCalc(50),
width: percentCalc(100),
display: 'flex',
alignItems: 'center',
flexWrap: 'nowrap'
});

const containerRightBottom = new VTable.CustomLayout.Group({
height: percentCalc(50),
width: percentCalc(100),
display: 'flex',
alignItems: 'center'
});

containerRight.add(containerRightTop);
containerRight.add(containerRightBottom);

const bloggerName = new VTable.CustomLayout.Text({
text: 'record.bloggerName',
fontSize: 13,
fontFamily: 'sans-serif',
fill: 'black',
marginLeft: 10
});
containerRightTop.add(bloggerName);

const location = new VTable.CustomLayout.Icon({
id: 'location',
iconName: 'location',
width: 15,
height: 15,
marginLeft: 10
});
containerRightTop.add(location);

const locationName = new VTable.CustomLayout.Text({
text: 'record.city',
fontSize: 11,
fontFamily: 'sans-serif',
fill: '#6f7070',
boundsPadding: [0, 10, 0, 0]
});
containerRightTop.add(locationName);

return {
rootContainer: container,
renderDefault: false
};
}
}
],
records: [
Expand Down Expand Up @@ -419,18 +513,123 @@ export function createTable() {
}
],
editor: 'input',
defaultRowHeight: 80
defaultRowHeight: 80,
customMergeCell: (col, row, table) => {
if (col >= 0 && col < table.colCount && row === table.rowCount - 2) {
return {
range: {
start: {
col: 0,
row: table.rowCount - 2
},
end: {
col: table.colCount - 1,
row: table.rowCount - 2
}
},
customLayout: args => {
const { table, row, col, rect } = args;
const { height, width } = rect || table.getCellRect(col, row);
const percentCalc = VTable.CustomLayout.percentCalc;
const container = new VTable.CustomLayout.Group({
height,
width,
display: 'flex',
flexDirection: 'row',
flexWrap: 'nowrap'
});
const containerLeft = new VTable.CustomLayout.Group({
height: percentCalc(100),
width: 160,
display: 'flex',
direction: 'column',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'space-around',
fill: 'blue',
// dx: 200
x: 200
});
container.add(containerLeft);

containerLeft.addEventListener('click', () => {
containerLeft.setAttributes({ fill: 'red' });
});

const containerRight = new VTable.CustomLayout.Group({
height: percentCalc(100),
width: percentCalc(100, -50),
display: 'flex',
direction: 'column'
// justifyContent: 'center'
});
container.add(containerRight);

const containerRightTop = new VTable.CustomLayout.Group({
id: 'containerRightTop',
height: percentCalc(50),
width: percentCalc(100),
display: 'flex',
alignItems: 'center',
flexWrap: 'nowrap'
});

const containerRightBottom = new VTable.CustomLayout.Group({
height: percentCalc(50),
width: percentCalc(100),
display: 'flex',
alignItems: 'center'
});

containerRight.add(containerRightTop);
containerRight.add(containerRightBottom);

const bloggerName = new VTable.CustomLayout.Text({
text: 'record.bloggerName',
fontSize: 13,
fontFamily: 'sans-serif',
fill: 'black',
marginLeft: 10
});
containerRightTop.add(bloggerName);

const location = new VTable.CustomLayout.Icon({
id: 'location',
iconName: 'location',
width: 15,
height: 15,
marginLeft: 10
});
containerRightTop.add(location);

const locationName = new VTable.CustomLayout.Text({
text: 'record.city',
fontSize: 11,
fontFamily: 'sans-serif',
fill: '#6f7070',
boundsPadding: [0, 10, 0, 0]
});
containerRightTop.add(locationName);

return {
rootContainer: container,
renderDefault: false
};
}
};
}
}
};

const instance = new ListTable(option);
bindDebugTool(instance.scenegraph.stage as any, {
customGrapicKeys: ['role']
});

const { MOUSEMOVE_CELL } = VTable.ListTable.EVENT_TYPE;
instance.addEventListener(MOUSEMOVE_CELL, (...args) => {
console.log('MOUSEMOVE_CELL', args[0]?.target);
});
// const { MOUSEMOVE_CELL } = VTable.ListTable.EVENT_TYPE;
// instance.addEventListener(MOUSEMOVE_CELL, (...args) => {
// console.log('MOUSEMOVE_CELL', args[0]?.target);
// });

// 只为了方便控制太调试用,不要拷贝
window.tableInstance = instance;
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/event/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getCellEventArgsSet(e: FederatedPointerEvent): SceneEvent {
return tableEvent;
}

function getTargetCell(target: any) {
export function getTargetCell(target: any) {
while (target && target.parent) {
if (target.role === 'cell') {
return target;
Expand Down
Loading
Loading