Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/vchart/src/component/axis/base-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import type {
Datum,
StringOrNumber,
IGroup as ISeriesGroup,
CoordinateType,
IRect,
ILayoutRect
CoordinateType
} from '../../typings';
import { BaseComponent } from '../base/base-component';
import { CompilableData } from '../../compile/data';
Expand Down Expand Up @@ -57,6 +55,7 @@ import { getFormatFunction } from '../util';
import type { IComponentMark } from '../../mark/interface/mark';
import type { ICompilableMark } from '../../compile/mark';
import type { ICompilableData } from './../../compile/data/interface';
import { transformFunctionAttribute } from '../../util/spec/transform';

export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, any> = any> // FIXME: 补充公共类型,去掉 Record<string, any>
extends BaseComponent<T>
Expand Down Expand Up @@ -654,7 +653,7 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
protected _getGridAttributes() {
const spec = this._spec;
return {
alternateColor: spec.grid.alternateColor,
alternateColor: transformFunctionAttribute(spec.grid.alternateColor),
alignWithLabel: spec.grid.alignWithLabel,
style: isFunction(spec.grid.style)
? (datum: Datum, index: number) => {
Expand All @@ -668,7 +667,7 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
: {
type: 'line',
visible: spec.subGrid.visible,
alternateColor: spec.subGrid.alternateColor,
alternateColor: transformFunctionAttribute(spec.subGrid.alternateColor),
style: transformToGraphic(spec.subGrid.style)
}
};
Expand Down
9 changes: 8 additions & 1 deletion packages/vchart/src/util/spec/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, isPlainObject, isString } from '@visactor/vutils';
import { isArray, isFunction, isPlainObject, isString } from '@visactor/vutils';
import type { ISeriesSpec } from '../../typings';

// todo 以目前的场景来看,并没有递归的需要。
Expand Down Expand Up @@ -66,3 +66,10 @@ export function functionTransform(spec: ISeriesSpec, VChart: any): any {
}
return spec;
}

export function transformFunctionAttribute(att: unknown, ...args: unknown[]) {
if (isFunction(att)) {
return att(...args);
}
return att;
}
Loading