Skip to content

Commit

Permalink
feat: annotation supports default title and content from properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanyan-Wang committed Aug 15, 2023
1 parent eb767c7 commit 6bb30be
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import $i18n from '../../i18n';
export interface GraphAnnotationProps {
contextmenu: any;
annotationWay: string;
defaultTitleField?: string;
defaultContentFields?: string[];
}

const tagColors = [
Expand Down Expand Up @@ -51,7 +53,7 @@ const BADGE_CLASSNAME = 'gi-graph-annotation';
let unbindSizeSensor;

const GraphAnnotation: React.FunctionComponent<GraphAnnotationProps> = props => {
const { contextmenu, annotationWay } = props;
const { contextmenu, annotationWay, defaultTitleField, defaultContentFields } = props;
const { graph, GISDK_ID } = useContext();
const { item: menuTargetItem, x, y } = contextmenu; // target 为 null 可能是 canvas
if (menuTargetItem && menuTargetItem.destroyed) {
Expand Down Expand Up @@ -89,10 +91,20 @@ const GraphAnnotation: React.FunctionComponent<GraphAnnotationProps> = props =>
// onClickIcon: hideIconTooltip,
},
getTitle: item => {
if (defaultTitleField) return item.getModel()[defaultTitleField];
const type = item.getType?.() || 'canvas';
return menuItemName[type];
},
getContent: (item => undefined) as any,
getContent: (item => {
if (defaultContentFields) {
const model = item.getModel();
return defaultContentFields
.map(field => (model.hasOwnProperty(field) ? `${field}: ${model[field]}` : undefined))
.filter(Boolean)
.join('\n\r');
}
return undefined;
}) as any,
getContentPlaceholder: item =>
$i18n.get({
id: 'advance.components.GraphAnnotation.Component.DoubleClickHereToStart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const annotationWay = [
},
];

export default () => {
export default context => {
const { keys } = context;
return {
annotationWay: {
title: $i18n.get({ id: 'advance.components.GraphAnnotation.registerMeta.LabelingMethod', dm: '标注方式' }),
Expand All @@ -39,5 +40,33 @@ export default () => {
},
default: 'tag',
},

defaultTitleField: {
title: '默认标题填充属性',
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
mode: 'single',
options: keys.map(c => {
return { label: c, value: c };
}),
},
default: undefined,
},

defaultContentFields: {
title: '默认内容填充属性',
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
mode: 'multiple',
options: keys.map(c => {
return { label: c, value: c };
}),
},
default: undefined,
},
};
};

0 comments on commit 6bb30be

Please sign in to comment.