Skip to content

Commit c840d95

Browse files
authored
Merge pull request #965 from qxqzx13/shuangY
fix:(Chart) fix doubleY yAxis label and chart label
2 parents 765855a + 33495af commit c840d95

File tree

2 files changed

+127
-16
lines changed

2 files changed

+127
-16
lines changed

frontend/src/app/components/ChartGraph/BasicDoubleYChart/BasicDoubleYChart.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ class BasicDoubleYChart extends Chart {
161161
chartDataSet: IChartDataSet<string>,
162162
) {
163163
const _getSeriesByDemisionPostion =
164-
() => (config, styles, settings, data, direction) => {
164+
() => (config, styles, settings, data, direction, yAxisIndex) => {
165165
const [graphType, graphStyle] = getStyles(
166166
styles,
167167
[direction],
168168
['graphType', 'graphStyle'],
169169
);
170170
return {
171+
yAxisIndex,
171172
name: getColumnRenderName(config),
172173
type: graphType || 'line',
173174
sampling: 'average',
@@ -194,6 +195,7 @@ class BasicDoubleYChart extends Chart {
194195
settingConfigs,
195196
chartDataSet,
196197
'leftY',
198+
0,
197199
),
198200
),
199201
)
@@ -205,13 +207,10 @@ class BasicDoubleYChart extends Chart {
205207
settingConfigs,
206208
chartDataSet,
207209
'rightY',
210+
1,
208211
),
209212
),
210-
)
211-
.map((config, index) => {
212-
(config as any).yAxisIndex = index;
213-
return config;
214-
});
213+
);
215214
return series;
216215
}
217216

@@ -290,7 +289,7 @@ class BasicDoubleYChart extends Chart {
290289
['showHorizonLine', 'horizonLineStyle'],
291290
);
292291

293-
const _yAxisTemplate = (position, index, name) => {
292+
const _yAxisTemplate = (position, name) => {
294293
const [showAxis, inverse, font, showLabel] = getStyles(
295294
styles,
296295
[`${position}Y`],
@@ -300,7 +299,6 @@ class BasicDoubleYChart extends Chart {
300299
return {
301300
type: 'value',
302301
position,
303-
offset: index * 20,
304302
showTitleAndUnit: true,
305303
name,
306304
nameLocation: 'middle',
@@ -318,14 +316,17 @@ class BasicDoubleYChart extends Chart {
318316
};
319317
};
320318

321-
const leftYAxis = leftDeminsionConfigs.map((c, index) =>
322-
_yAxisTemplate('left', index, getColumnRenderName(c)),
323-
);
319+
const leftYAxisNames = leftDeminsionConfigs
320+
.map(getColumnRenderName)
321+
.join('/');
322+
const rightYAxisNames = rightDeminsionConfigs
323+
.map(getColumnRenderName)
324+
.join('/');
324325

325-
const rightYAxis = rightDeminsionConfigs.map((c, index) =>
326-
_yAxisTemplate('right', index, getColumnRenderName(c)),
327-
);
328-
return leftYAxis.concat(rightYAxis);
326+
return [
327+
_yAxisTemplate('left', leftYAxisNames),
328+
_yAxisTemplate('right', rightYAxisNames),
329+
];
329330
}
330331

331332
private getLegend(styles, seriesNames) {
@@ -377,7 +378,7 @@ class BasicDoubleYChart extends Chart {
377378
private getLabelStyle(styles, direction) {
378379
const [showLabel, position, LabelFont] = getStyles(
379380
styles,
380-
['label'],
381+
[direction + 'Label'],
381382
['showLabel', 'position', 'font'],
382383
);
383384

frontend/src/app/components/ChartGraph/BasicDoubleYChart/config.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,104 @@ const config: ChartConfig = {
141141
},
142142
],
143143
},
144+
{
145+
label: 'label.leftYTitle',
146+
key: 'leftYLabel',
147+
comType: 'group',
148+
rows: [
149+
{
150+
label: 'label.showLabel',
151+
key: 'showLabel',
152+
default: true,
153+
comType: 'checkbox',
154+
},
155+
{
156+
label: 'label.position',
157+
key: 'position',
158+
comType: 'select',
159+
default: 'top',
160+
options: {
161+
// TODO(Stephen): to be extract customize LabelPosition Component
162+
items: [
163+
{ label: '上', value: 'top' },
164+
{ label: '左', value: 'left' },
165+
{ label: '右', value: 'right' },
166+
{ label: '下', value: 'bottom' },
167+
{ label: '内', value: 'inside' },
168+
{ label: '内左', value: 'insideLeft' },
169+
{ label: '内右', value: 'insideRight' },
170+
{ label: '内上', value: 'insideTop' },
171+
{ label: '内下', value: 'insideBottom' },
172+
{ label: '内左上', value: 'insideTopLeft' },
173+
{ label: '内左下', value: 'insideBottomLeft' },
174+
{ label: '内右上', value: 'insideTopRight' },
175+
{ label: '内右下', value: 'insideBottomRight' },
176+
],
177+
},
178+
},
179+
{
180+
label: 'viz.palette.style.font',
181+
key: 'font',
182+
comType: 'font',
183+
default: {
184+
fontFamily: 'PingFang SC',
185+
fontSize: '12',
186+
fontWeight: 'normal',
187+
fontStyle: 'normal',
188+
color: '#495057',
189+
},
190+
},
191+
],
192+
},
193+
{
194+
label: 'label.rightYTitle',
195+
key: 'rightYLabel',
196+
comType: 'group',
197+
rows: [
198+
{
199+
label: 'label.showLabel',
200+
key: 'showLabel',
201+
default: true,
202+
comType: 'checkbox',
203+
},
204+
{
205+
label: 'label.position',
206+
key: 'position',
207+
comType: 'select',
208+
default: 'top',
209+
options: {
210+
// TODO(Stephen): to be extract customize LabelPosition Component
211+
items: [
212+
{ label: '上', value: 'top' },
213+
{ label: '左', value: 'left' },
214+
{ label: '右', value: 'right' },
215+
{ label: '下', value: 'bottom' },
216+
{ label: '内', value: 'inside' },
217+
{ label: '内左', value: 'insideLeft' },
218+
{ label: '内右', value: 'insideRight' },
219+
{ label: '内上', value: 'insideTop' },
220+
{ label: '内下', value: 'insideBottom' },
221+
{ label: '内左上', value: 'insideTopLeft' },
222+
{ label: '内左下', value: 'insideBottomLeft' },
223+
{ label: '内右上', value: 'insideTopRight' },
224+
{ label: '内右下', value: 'insideBottomRight' },
225+
],
226+
},
227+
},
228+
{
229+
label: 'viz.palette.style.font',
230+
key: 'font',
231+
comType: 'font',
232+
default: {
233+
fontFamily: 'PingFang SC',
234+
fontSize: '12',
235+
fontWeight: 'normal',
236+
fontStyle: 'normal',
237+
color: '#495057',
238+
},
239+
},
240+
],
241+
},
144242
{
145243
label: 'leftY.title',
146244
key: 'leftY',
@@ -473,6 +571,12 @@ const config: ChartConfig = {
473571
label: '数值',
474572
stack: '堆叠',
475573
},
574+
label: {
575+
leftYTitle: '左轴标签',
576+
rightYTitle: '右轴标签',
577+
showLabel: '显示标签',
578+
position: '位置',
579+
},
476580
legend: {
477581
title: '图例',
478582
showLegend: '显示图例',
@@ -542,6 +646,12 @@ const config: ChartConfig = {
542646
label: 'Label',
543647
stack: 'Stack',
544648
},
649+
label: {
650+
leftYTitle: 'Left Y Axis Label',
651+
rightYTitle: 'Right Y Axis Label',
652+
showLabel: 'Show Label',
653+
position: 'Position',
654+
},
545655
legend: {
546656
title: 'Legend',
547657
showLegend: 'Show Legend',

0 commit comments

Comments
 (0)