Skip to content

Commit 54887f2

Browse files
leondt1hustcc
andauthored
fix: dual-axes axisXTitle bug (#172)
* fix: fix dual-axes axisXTitle bug * chore: version * revert: version --------- Co-authored-by: hustcc <[email protected]>
1 parent 4ad8f63 commit 54887f2

File tree

8 files changed

+26
-9
lines changed

8 files changed

+26
-9
lines changed

bindings/gpt-vis-ssr/__tests__/dual-axes.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('SSR render', () => {
99
height: 400,
1010
type: 'dual-axes',
1111
title: 'This is a dual axes chart',
12+
axisXTitle: '时间',
1213
categories: [
1314
'2020-08-20',
1415
'2020-08-21',
@@ -102,6 +103,7 @@ describe('SSR render', () => {
102103
'2020-09-17',
103104
'2020-09-18',
104105
],
106+
axisXTitle: '时间',
105107
series: [
106108
{
107109
type: 'column',
@@ -133,6 +135,7 @@ describe('SSR render', () => {
133135
height: 400,
134136
type: 'dual-axes',
135137
title: 'This is a dual axes chart',
138+
axisXTitle: 'time',
136139
categories: [
137140
'2020-08-20',
138141
'2020-08-21',
@@ -198,6 +201,7 @@ describe('SSR render', () => {
198201
height: 400,
199202
type: 'dual-axes',
200203
title: 'This is a dual axes chart',
204+
axisXTitle: '时间',
201205
categories: [
202206
'2020-08-20',
203207
'2020-08-21',
@@ -263,6 +267,7 @@ describe('SSR render', () => {
263267
height: 400,
264268
type: 'dual-axes',
265269
title: 'This is a dual axes chart',
270+
axisXTitle: '时间',
266271
categories: [
267272
'2020-08-20',
268273
'2020-08-21',
@@ -327,6 +332,7 @@ describe('SSR render', () => {
327332
height: 400,
328333
type: 'dual-axes',
329334
title: 'This is a dual axes chart',
335+
axisXTitle: '时间',
330336
categories: [
331337
'2020-08-20',
332338
'2020-08-21',
-2.97 KB
Loading
-3.36 KB
Loading
-3.55 KB
Loading
-3.39 KB
Loading
-2.07 KB
Loading
-3.55 KB
Loading

bindings/gpt-vis-ssr/src/vis/dual-axes.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export async function DualAxes(options: DualAxesOptions) {
3535
theme = 'default',
3636
renderPlugins,
3737
style = {},
38+
axisXTitle = '',
3839
} = options;
3940
enum ChartType {
4041
Column = 'column',
@@ -60,6 +61,12 @@ export async function DualAxes(options: DualAxesOptions) {
6061
};
6162
}
6263

64+
function getTitleFontStyle(texture: DualAxesOptions['texture']) {
65+
return texture === 'rough'
66+
? { titleFontFamily: FontFamily.ROUGH, labelFontFamily: FontFamily.ROUGH }
67+
: {};
68+
}
69+
6370
function transform(series: DualAxesSeriesItem[], categories: string[]) {
6471
const newChildren = series
6572
.sort((a, b) => {
@@ -74,14 +81,10 @@ export async function DualAxes(options: DualAxesOptions) {
7481
axis: {
7582
y: {
7683
title: axisYTitle,
77-
...(texture === 'rough'
78-
? { titleFontFamily: FontFamily.ROUGH, labelFontFamily: FontFamily.ROUGH }
79-
: {}),
84+
...getTitleFontStyle(texture),
8085
},
8186
x: {
82-
...(texture === 'rough'
83-
? { titleFontFamily: FontFamily.ROUGH, labelFontFamily: FontFamily.ROUGH }
84-
: {}),
87+
...getTitleFontStyle(texture),
8588
},
8689
},
8790
encode: { x: 'category', y: axisYTitle, color: () => axisYTitle },
@@ -124,9 +127,7 @@ export async function DualAxes(options: DualAxesOptions) {
124127
y: {
125128
position: 'right',
126129
title: axisYTitle,
127-
...(texture === 'rough'
128-
? { titleFontFamily: FontFamily.ROUGH, labelFontFamily: FontFamily.ROUGH }
129-
: {}),
130+
...getTitleFontStyle(texture),
130131
},
131132
},
132133
encode: { x: 'category', y: axisYTitle, shape: 'smooth', color: () => axisYTitle },
@@ -178,6 +179,16 @@ export async function DualAxes(options: DualAxesOptions) {
178179
width,
179180
height,
180181
...config,
182+
...(axisXTitle
183+
? {
184+
axis: {
185+
x: {
186+
title: axisXTitle,
187+
...getTitleFontStyle(texture),
188+
},
189+
},
190+
}
191+
: {}),
181192
scale: {
182193
y: {
183194
nice: true,

0 commit comments

Comments
 (0)