Skip to content

feat: vbi encoding fixes, measure builder improvements, and professional demo function extensions#333

Open
LoganLCX wants to merge 1 commit intoVisActor:feat/vbifrom
LoganLCX:feat/vbi
Open

feat: vbi encoding fixes, measure builder improvements, and professional demo function extensions#333
LoganLCX wants to merge 1 commit intoVisActor:feat/vbifrom
LoganLCX:feat/vbi

Conversation

@LoganLCX
Copy link

@LoganLCX LoganLCX commented Feb 6, 2026

vbi:add feat:基于离散字段新增指标&encoding逻辑&修改聚合方式&重命名&图表类型带encoding切换初步
professional:增加拖拽、重命名、修改聚合等,适配vbi新功能

@youngwinds youngwinds changed the base branch from main to feat/vbi February 6, 2026 13:18
}

this.dsl.get('dimensions').push([yMap])
const dimensionsArray = this.dsl.get('dimensions') as Y.Array<any>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要拆成行? 之前的写法有啥问题吗?

dimensionYMap.set('encoding', encoding)
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议实现一个 modifyDimension, 然后基于它, 实现modifyEncoding.

另外取名的话, update和modify需要选择一个统一的, 我建议modify, 因为我们的修改大多都是局部的.

}
}

renameMeasure(measureAlias: string, newAlias: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上, 先实现modifyMeasure, 然后再rename功能

}
}

updateAggregate(measureAlias: string, func: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上, 基于modifyMeasure, 来实现modifyAggregate

}
}

updateEncoding(measureAlias: string, encoding: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


static isMeasureNode(node: VBIMeasureTree[0]): node is VBIMeasure {
return 'field' in node
return 'expr' in node
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个似乎改错了? 我理解field没问题

}

// 辅助函数:将 VBIMeasureTree 展开为平面的 VBIMeasure 数组
private flattenMeasureTree(tree?: VBIMeasureTree): VBIMeasure[] {
Copy link
Collaborator

@youngwinds youngwinds Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

共建函数可以放在这里, packages/vbi/src/utils/tree/traverse.ts

这类函数和业务完全无关, 不应放在builder内, 可以单独抽出来作为工具函数, 用更通用的形式来实现.

}

// 辅助函数:将 VBIDimensionTree 展开为平面的 VBIDimension 数组
private flattenDimensionTree(tree?: VBIDimensionTree): VBIDimension[] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上, 应该从builder中剥离

const queryResult = await connector.query({ queryDSL, schema, connectorId })

// 转换 VBI measures 为 VSeed measures 格式
const flatMeasures = this.flattenMeasureTree(vbiDSL.measures)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildVSeed越来越大了, 我强烈建议抽出一个公共方法, builder内仅描述逻辑即可,

// Always create Y.Array for measures, converting plain arrays if needed
const measuresArray = new Y.Array<any>()
if (vbi.measures && Array.isArray(vbi.measures) && vbi.measures.length > 0) {
for (const m of vbi.measures) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我当时写的逻辑, 是业务yjs内部就会自动设置, 可以省去很多递归, 难道不是这样的?

export const zVBIDimensionSchema = z.object({
field: z.string(),
alias: z.string(),
encoding: z.string().optional(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vseed有具体的encoding值, 不应只写一个string

const measureSelects: Select<Record<string, unknown>> = measureNodes.map((measure) => {
return {
field: measure.field,
const field = exprField(measure.expr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太理解这个expr的具体作用, 具体有啥用? 是要支持用户自定义表达式?

* 当前版本:仅支持字段引用
* 未来版本:可扩展支持 if/case/cast 等表达式
*/
export const zMeasureExpr = z.discriminatedUnion('type', [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我懂了, 自定义表达式, 这个功能对目前而言, 太高级了, 我建议先暂时下掉, 这个功能需要在vquery内先实现.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants