Skip to content

Commit 77eba1e

Browse files
authored
Merge pull request #3588 from VisActor/style/optimize-axis
Style/optimize axis
2 parents 2beb4af + f0fc87c commit 77eba1e

File tree

30 files changed

+144
-128
lines changed

30 files changed

+144
-128
lines changed

docs/assets/examples/en/axis/style.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ group: axis
44
title: General Style Configuration
55
keywords: lineChart,comparison,trend,line,axis
66
order: 25-1
7-
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/vchart/preview/axis/style.png
7+
cover: /vchart/preview/axis-style_1.13.1.png
88
option: lineChart#axes
99
---
1010

@@ -23,26 +23,27 @@ For axis style configuration, configure through:
2323
- `tick` Coordinate axis scale line configuration
2424
- `grid` Coordinate axis grid line configuration
2525
- `title` Coordinate axis title configuration
26+
- `unit` Coordinate axis unit configuration
2627

2728
## Demo source
2829

2930
```javascript livedemo
3031
const spec = {
3132
type: 'line',
3233
theme: {
33-
fontFamily: 'serif' // configure global font
34+
fontFamily: 'serif' // Configure global fonts
3435
},
3536
data: [
3637
{
3738
id: 'line',
3839
values: [
39-
{ x: '周一', y: 12 },
40-
{ x: '周二', y: 13 },
41-
{ x: '周三', y: 11 },
42-
{ x: '周四', y: 10 },
43-
{ x: '周五', y: 12 },
44-
{ x: '周六', y: 14 },
45-
{ x: '周日', y: 17 }
40+
{ x: 'Monday', y: 12 },
41+
{ x: 'Tuesday', y: 13 },
42+
{ x: 'Wednesday', y: 11 },
43+
{ x: 'Thursday', y: 10 },
44+
{ x: 'Friday', y: 12 },
45+
{ x: 'Saturday', y: 14 },
46+
{ x: 'Sunday', y: 17 }
4647
]
4748
}
4849
],
@@ -54,14 +55,23 @@ const spec = {
5455
title: {
5556
visible: true,
5657
space: 12,
57-
text: '右轴标题'
58+
text: 'Right axis title'
5859
},
5960
label: {
6061
formatMethod: val => `${val}°C`,
6162
style: {
6263
fill: '#000'
6364
}
6465
},
66+
unit: {
67+
visible: true,
68+
text: 'Unit of right axis',
69+
style: {
70+
// dx: -18,
71+
dy: -8
72+
// textAlign: 'right'
73+
}
74+
},
6575
tick: {
6676
visible: true,
6777
tickStep: 2,
@@ -85,7 +95,16 @@ const spec = {
8595
title: {
8696
visible: true,
8797
space: 12,
88-
text: '左轴标题'
98+
text: 'Left axis title'
99+
},
100+
unit: {
101+
visible: true,
102+
text: 'Unit of left axis',
103+
style: {
104+
// dx: -18,
105+
dy: -8
106+
// textAlign: 'right'
107+
}
89108
},
90109
label: {
91110
formatMethod: val => `${val}°C`,
@@ -121,6 +140,7 @@ const spec = {
121140
fill: '#000'
122141
}
123142
},
143+
124144
tick: {
125145
inside: true,
126146
tickSize: 8,

docs/assets/examples/zh/axis/style.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ group: axis
44
title: 通用样式配置
55
keywords: lineChart,comparison,trend,line,axis
66
order: 25-1
7-
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/vchart/preview/axis/style.png
7+
cover: /vchart/preview/axis-style_1.13.1.png
88
option: lineChart#axes
99
---
1010

@@ -23,6 +23,7 @@ option: lineChart#axes
2323
- `tick` 坐标轴刻度线配置
2424
- `grid` 坐标轴网格线配置
2525
- `title` 坐标轴标题配置
26+
- `unit` 坐标轴单位配置
2627

2728
## 代码演示
2829

@@ -62,6 +63,15 @@ const spec = {
6263
fill: '#000'
6364
}
6465
},
66+
unit: {
67+
visible: true,
68+
text: 'Unit of right axis',
69+
style: {
70+
// dx: -18,
71+
dy: -8
72+
// textAlign: 'right'
73+
}
74+
},
6575
tick: {
6676
visible: true,
6777
tickStep: 2,
@@ -87,6 +97,15 @@ const spec = {
8797
space: 12,
8898
text: 'Left axis title'
8999
},
100+
unit: {
101+
visible: true,
102+
text: 'Unit of left axis',
103+
style: {
104+
// dx: -18,
105+
dy: -8
106+
// textAlign: 'right'
107+
}
108+
},
90109
label: {
91110
formatMethod: val => `${val}°C`,
92111
style: {
@@ -121,6 +140,7 @@ const spec = {
121140
fill: '#000'
122141
}
123142
},
143+
124144
tick: {
125145
inside: true,
126146
tickSize: 8,
39.2 KB
Loading

packages/vchart/bundler.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const crossEnvs = bundle_analyze_mode ? {} : {
6363
},
6464
};
6565

66-
const esEntries = ['index-harmony', 'index-harmony-simple'];
66+
const esEntries = bundle_analyze_mode ? [] : ['index-harmony', 'index-harmony-simple'];
6767
const umdEntries = Object.keys(crossEnvs)
6868
.map(env => crossEnvs[env].input)
6969
.filter((input, index, arr) => arr.indexOf(input, 0) === index);

packages/vchart/src/chart/base/base-chart.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import type { IRegion } from '../../region/interface';
3737
import { ComponentTypeEnum } from '../../component/interface';
3838
// eslint-disable-next-line no-duplicate-imports
3939
import type { IComponent, IComponentConstructor } from '../../component/interface';
40-
import type { IMark } from '../../mark/interface';
40+
import type { IMark, IRectMark } from '../../mark/interface';
4141
// eslint-disable-next-line no-duplicate-imports
4242
import { MarkTypeEnum } from '../../mark/interface';
4343
import type { IEvent } from '../../event/interface';
@@ -65,7 +65,6 @@ import { ChartEvent, VGRAMMAR_HOOK_EVENT } from '../../constant/event';
6565
import type { IGlobalScale } from '../../scale/interface';
6666
import { DimensionEventEnum } from '../../event/events/dimension';
6767
import type { ITooltip } from '../../component/tooltip/interface';
68-
import type { IRectMark } from '../../mark/rect';
6968
import { calculateChartSize, mergeUpdateResult } from '../util';
7069
import { isDiscrete } from '@visactor/vscale';
7170
import { updateDataViewInData } from '../../data/initialize';

packages/vchart/src/compile/compilable-base.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Compiler } from './compiler';
2-
import type { ICompilableInitOption, ICompilable } from './interface';
1+
import type { ICompilableInitOption, ICompilable, ICompiler } from './interface';
32

43
/** 可以编译的类的统一基类 */
54
export abstract class CompilableBase implements ICompilable {
@@ -8,7 +7,7 @@ export abstract class CompilableBase implements ICompilable {
87
return this._option;
98
}
109

11-
getCompiler: () => Compiler;
10+
getCompiler: () => ICompiler;
1211

1312
constructor(option: ICompilableInitOption) {
1413
this._option = option;

packages/vchart/src/compile/interface/compilable-item.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface IGrammarItemMap<T extends IGrammarItem> {
3333
export type ICompilerModel = Record<GrammarType, IProductMap<IGrammarItem>>;
3434

3535
export interface ICompiler {
36+
isInited?: boolean;
3637
getVGrammarView: () => IView;
3738
getModel: () => ICompilerModel;
3839
getRenderer: () => IRenderer;

packages/vchart/src/compile/mark/compilable-mark.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
IData,
23
IElement,
34
IGroupMark,
45
IMark,
@@ -265,7 +266,7 @@ export abstract class CompilableMark extends GrammarItem implements ICompilableM
265266
// 绑定数据
266267
const dataProduct = this._data.getProduct();
267268
if (isValid(this._product) && isValid(dataProduct)) {
268-
this._product.join(dataProduct, this.key, undefined, this.getGroupKey());
269+
this._product.join(dataProduct as IData, this.key, undefined, this.getGroupKey());
269270
}
270271
}
271272

packages/vchart/src/compile/mark/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface IMarkStateManager {
3030
isMultiMark?: boolean
3131
) => 'in' | 'out' | 'skip';
3232
checkState: (renderNode: IElement, datum: Datum | Datum[]) => StateValue[];
33+
updateLayoutState: (noRender?: boolean) => void;
3334
}
3435

3536
export interface IMarkData extends ICompilableData {

packages/vchart/src/component/axis/base-axis.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ITickDataOpt } from '@visactor/vrender-components';
33
import type { IBaseScale } from '@visactor/vscale';
44
// eslint-disable-next-line no-duplicate-imports
55
import { isContinuous } from '@visactor/vscale';
6-
import type { IGroup, IGraphic } from '@visactor/vrender-core';
6+
import type { IGraphic } from '@visactor/vrender-core';
77
// eslint-disable-next-line no-duplicate-imports
88
import type {
99
IOrientType,
@@ -24,7 +24,6 @@ import type { ISeries } from '../../series/interface';
2424
import { ChartEvent } from '../../constant/event';
2525
import { LayoutZIndex } from '../../constant/layout';
2626
import { animationConfig } from '../../animation/utils';
27-
import type { LooseFunction } from '@visactor/vutils';
2827
// eslint-disable-next-line no-duplicate-imports
2928
import {
3029
degreeToRadian,
@@ -33,7 +32,6 @@ import {
3332
array,
3433
get,
3534
isArray,
36-
isBoolean,
3735
isFunction,
3836
isNil,
3937
isValid,
@@ -45,7 +43,6 @@ import type { ITransformOptions } from '@visactor/vdataset';
4543
// eslint-disable-next-line no-duplicate-imports
4644
import { DataView } from '@visactor/vdataset';
4745
import { GridEnum } from '@visactor/vgrammar-core';
48-
import type { IComponentMark } from '../../mark/component';
4946
// eslint-disable-next-line no-duplicate-imports
5047
import { registerComponentMark } from '../../mark/component';
5148
import { Factory } from '../../core/factory';
@@ -56,6 +53,7 @@ import { GroupFadeOut, GroupFadeIn } from '@visactor/vrender-core';
5653
import { scaleParser } from '../../data/parser/scale';
5754
import { registerDataSetInstanceParser } from '../../data/register';
5855
import { getFormatFunction } from '../util';
56+
import type { IComponentMark } from '../../mark/interface/mark';
5957

6058
export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, any> = any> // FIXME: 补充公共类型,去掉 Record<string, any>
6159
extends BaseComponent<T>
@@ -561,7 +559,7 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
561559
// 处理纵轴的标题样式
562560
if (autoRotate && isNil(titleAngle)) {
563561
titleAngle = spec.orient === 'left' ? -90 : 90;
564-
titleTextStyle = DEFAULT_TITLE_STYLE[spec.orient];
562+
titleTextStyle = (DEFAULT_TITLE_STYLE as any)[spec.orient];
565563
}
566564
}
567565

0 commit comments

Comments
 (0)