You've already forked DataMate
refactor(annotation): 优化模板生成逻辑移除文本类型特殊处理
Some checks failed
Some checks failed
- 移除了 text_object_types 变量定义 - 删除了 is_text_template 判断逻辑 - 移除了长文本优化的双栏布局实现 - 添加了关于 Label Studio 默认侧栏控件行为的说明 - 简化了 XML 结构生成逻辑
This commit is contained in:
@@ -36,7 +36,6 @@ class AnnotationTemplateService:
|
||||
"""
|
||||
tag_config = LabelStudioTagConfig()
|
||||
control_types = tag_config.get_control_types()
|
||||
text_object_types = {"Text", "Paragraphs", "ParagraphLabels", "HyperText", "Markdown"}
|
||||
|
||||
def normalize_control_type(raw: Optional[str]) -> str:
|
||||
if not raw:
|
||||
@@ -49,8 +48,6 @@ class AnnotationTemplateService:
|
||||
return ct
|
||||
return raw
|
||||
|
||||
is_text_template = any((obj.type in text_object_types) for obj in config.objects)
|
||||
|
||||
# 生成对象定义
|
||||
object_parts: List[str] = []
|
||||
for obj in config.objects:
|
||||
@@ -93,20 +90,9 @@ class AnnotationTemplateService:
|
||||
# 处理简单标签类型(不需要子元素)
|
||||
control_parts.append(f' <{tag_type} {" ".join(label_attrs)}/>')
|
||||
|
||||
if is_text_template:
|
||||
# 长文本优化:将标签控件固定在右侧(sticky),避免需要滚动到页面底部才能看到控件
|
||||
xml_parts = [
|
||||
'<View style="display: flex; flex-direction: row; align-items: flex-start; gap: 12px;">',
|
||||
' <View style="flex: 1; min-width: 0;">',
|
||||
*object_parts,
|
||||
' </View>',
|
||||
' <View style="width: 320px; position: sticky; top: 0; align-self: flex-start; max-height: 90vh; overflow: auto; background: #fff; padding: 12px; border: 1px solid #f0f0f0; border-radius: 6px;">',
|
||||
*control_parts,
|
||||
' </View>',
|
||||
'</View>',
|
||||
]
|
||||
return '\n'.join(xml_parts)
|
||||
|
||||
# 说明:
|
||||
# - Label Studio Frontend 默认会将控件(control tags)渲染到右侧侧栏(side-column/controls)。
|
||||
# - 如果在 XML 中手工做“双栏布局”,会导致控件出现在主区域,从而与侧栏的结果面板重复,影响体验。
|
||||
xml_parts = ['<View>']
|
||||
xml_parts.extend(object_parts)
|
||||
xml_parts.extend(control_parts)
|
||||
|
||||
Reference in New Issue
Block a user