chore(data-vi): adjust api (#4116)

This commit is contained in:
YANG QIA 2024-04-21 21:14:26 +08:00 committed by GitHub
parent c43a6e98d5
commit b12fe0981f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 8 deletions

View File

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { FieldOption } from '../hooks'; import { FieldOption } from '../hooks';
import { QueryProps } from '../renderer'; import { DimensionProps, MeasureProps, QueryProps } from '../renderer';
import { parseField } from '../utils'; import { parseField } from '../utils';
import { ISchema } from '@formily/react'; import { ISchema } from '@formily/react';
import configs, { AnySchemaProperties, Config } from './configs'; import configs, { AnySchemaProperties, Config, FieldConfigProps } from './configs';
import { Transformer } from '../transformers'; import { Transformer } from '../transformers';
export type RenderProps = { export type RenderProps = {
@ -27,8 +27,8 @@ export interface ChartType {
init?: ( init?: (
fields: FieldOption[], fields: FieldOption[],
query: { query: {
measures?: QueryProps['measures']; measures?: MeasureProps[];
dimensions?: QueryProps['dimensions']; dimensions?: DimensionProps[];
}, },
) => { ) => {
general?: any; general?: any;
@ -102,7 +102,7 @@ export class Chart implements ChartType {
}; };
} }
addConfigs(configs: { [key: string]: Function }) { addConfigs(configs: { [key: string]: (props: FieldConfigProps) => AnySchemaProperties }) {
Object.entries(configs).forEach(([key, func]) => { Object.entries(configs).forEach(([key, func]) => {
this.configs.set(key, func); this.configs.set(key, func);
}); });
@ -114,8 +114,8 @@ export class Chart implements ChartType {
measures, measures,
dimensions, dimensions,
}: { }: {
measures?: QueryProps['measures']; measures?: MeasureProps[];
dimensions?: QueryProps['dimensions']; dimensions?: DimensionProps[];
}, },
) { ) {
let xField: FieldOption; let xField: FieldOption;

View File

@ -206,7 +206,16 @@ const transformers: {
}, },
}, },
Exponential: (val: number | string) => (+val)?.toExponential(), Exponential: (val: number | string) => (+val)?.toExponential(),
Abbreviation: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val), Abbreviation: {
schema: {
'x-component': 'Select',
enum: [
{ label: 'en-US', value: 'en-US' },
{ label: 'zh-CN', value: 'zh-CN' },
],
},
fn: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val),
},
}, },
string: { string: {
'Type conversion': { 'Type conversion': {