Skip to content

Commit

Permalink
feat: mapping 传入全部映射数据 (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
susiwen8 committed Aug 10, 2022
1 parent c7c4f7d commit d4a3a5b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/f2/src/attr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class Base {
}

// 等于 normalize + convert, 参数是原始数据,返回是定义域的值
mapping(value) {
const rst = isFunction(this.callback) ? this.callback(value) : null;
mapping(value, child = null) {
const rst = isFunction(this.callback) ? this.callback(value, child) : null;
if (!isNil(rst)) {
return rst;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class Geometry<
const attr = attrs[attrName];
// 分类属性的线性映射
if (attrController.isGroupAttr(attrName)) {
attrValues[attrName] = attr.mapping(child[attr.field]);
attrValues[attrName] = attr.mapping(child[attr.field], child);
} else {
normalized[attrName] = attr.normalize(child[attr.field]);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/f2/src/components/tooltip/withTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface TooltipProps extends ChartChildProps {
* 背景样式
*/
background?: RectAttrs;
/**
* 是否显示
*/
showItemMarker?: boolean;
}

export interface TooltipState {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions packages/f2/test/components/axis/axis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,82 +72,102 @@ describe('Axis 轴', () => {
{
Year: '1987',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '1989',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '1995',
NumberNewMicroBrewery: 2,
goal: 10,
},
{
Year: '1996',
NumberNewMicroBrewery: 2,
goal: 10,
},
{
Year: '1997',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '1998',
NumberNewMicroBrewery: 3,
goal: 10,
},
{
Year: '1999',
NumberNewMicroBrewery: 2,
goal: 10,
},
{
Year: '2006',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '2007',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '2008',
NumberNewMicroBrewery: 1,
goal: 10,
},
{
Year: '2009',
NumberNewMicroBrewery: 2,
goal: 10,
},
{
Year: '2010',
NumberNewMicroBrewery: 3,
goal: 10,
},
{
Year: '2011',
NumberNewMicroBrewery: 4,
goal: 3,
},
{
Year: '2012',
NumberNewMicroBrewery: 5,
goal: 10,
},
{
Year: '2013',
NumberNewMicroBrewery: 11,
goal: 10,
},
{
Year: '2014',
NumberNewMicroBrewery: 20,
goal: 21,
},
{
Year: '2015',
NumberNewMicroBrewery: 16,
goal: 15,
},
{
Year: '2016',
NumberNewMicroBrewery: 13,
goal: 10,
},
{
Year: '2017',
NumberNewMicroBrewery: 6,
goal: 10,
},
{
Year: '2018',
NumberNewMicroBrewery: 1,
goal: 10,
},
];
const { props } = (
Expand All @@ -169,8 +189,8 @@ describe('Axis 轴', () => {
y="NumberNewMicroBrewery"
color={{
field: 'NumberNewMicroBrewery',
callback: function(val) {
if (val === 20) {
callback: function(val, child) {
if (val > child.goal) {
return '#1890ff';
}
return '#66B5FF';
Expand Down

0 comments on commit d4a3a5b

Please sign in to comment.