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
改变 Spec 数组字段的 API 配置方式 #4599
Comments
两种形式:
{
// ...
transform: [
{ type: 'stackY', orderBy: 'value' },
{ type: 'normalizeY' }
]
}
interval
.transform('stackY', { orderBy: 'value' })
.transform('normalizeY') |
可能出现多个相同的 transform 吗,如果会的话,api这种方式就有问题。 |
会有相同的 transform,但是 api 并不会影响最后的 spec。 interval
.transform('sortX')
.transform('sortX')
// 等同于
const options = {
transform: [{ type: 'sortX' }, { type: 'sortX'}]
} |
那怎么删除和更新 transform。 |
这是一个好问题。不过这个问题应该一直都存在,按照之前的写法应该也会存在这个问题。解决办法需要对数组 api 进行扩展:
mark
.transform('sortX')
.transform('sortY')
mark.transform(); // [ { type: 'sortX' }, { type: 'sortY'} ]
mark
.transform('sortX')
.transform('stackY', { orderBy: 'value' })
mark.transform(); // [ { type: 'sortX' }, { type: 'stackY', orderBy: 'value' } ]
mark
.transform('sortX')
.transform('sortY', null, 0) // null 表示没有传递配置
.transform('stackY', { orderBy: 'value' }, 1)
mark.transform(); // [{type: 'sortY'}, {type: 'stackY', orderBy: 'value'}, {type: 'sortX'}]
mark
.transform('sortX')
.transform('stackY')
.transform(0, 'sortY')
.transform(1, null, { orderBy: 'value'}) // 只更新 options
mark.transform(); // [{type: 'sortY'}, {type:'stackY', orderBy: 'value'} ]
mark
.transform('sortX')
.transform(0);
mark.transform(); // []
mark
.transform('sortX')
.transform('sortY')
.transform(null);
mark.transform(); // [];
mark
.transform('sortX')
.transform('sortY')
mark.transform([{type: 'stackY'}, {type: 'normalizeY'}]);
mark.transform(); // [{type: 'stackY'}, {type: 'normalizeY'}] |
这个因为了给用户更好的心智模型,暂时先关闭。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
数组字段 API 修改
在 G2 5.0 的 Spec 中,有一些字段是数组,比如 transform。
目前 Chart API 的配置方式如下:
为了让 API 之间保持更加统一,也和 4.0 更加兼容,修改 API 的形式如下:
API 设计
# mark.[arrayField](type, [options])
arrayField 枚举值如下:
其中 type 是必须参数,指定该可视化组件的类型。options 是可选参数,指定改可视化组件的配置。
思路
修改
src/api/props.ts
里面的defineArrayProp
函数。TODO
The text was updated successfully, but these errors were encountered: