Skip to content

Commit 6f65da1

Browse files
committed
Refactor axis title to use AAAxisTitle type
Changed axis title property in AAAxis, AAXAxis, and AAYAxis to use AAAxisTitle instead of AATitle for better type clarity. Deprecated old title methods accepting AATitle, added conversion logic for backward compatibility, and updated AATitle and AASubtitle properties to be public for easier access.
1 parent c32700e commit 6f65da1

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAAxis.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ enum class AAChartAxisType(val value: String) {
1212
var allowDecimals: Boolean? = null
1313
var alternateGridColor: Any? = null
1414
var crosshair: AACrosshair? = null //准星线样式设置
15-
var title: AATitle? = null
15+
var title: AAAxisTitle? = null
1616
var type: String? = null
1717
var dateTimeLabelFormats: AADateTimeLabelFormats? = null
1818
var plotBands: Array<AAPlotBandsElement>? = null

charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AASubtitle.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import com.github.aachartmodel.aainfographics.aachartcreator.AAChartVerticalAlig
1313

1414

1515
class AASubtitle {
16-
private var text: String? = null
17-
private var style: AAStyle? = null
18-
private var align: String? = null
19-
private var verticalAlign: String? = null
20-
private var x: Number? = null
21-
private var y: Number? = null
22-
private var userHTML: Boolean? = null
16+
var text: String? = null
17+
var style: AAStyle? = null
18+
var align: String? = null
19+
var verticalAlign: String? = null
20+
var x: Number? = null
21+
var y: Number? = null
22+
var userHTML: Boolean? = null
2323

2424
fun text(prop: String?): AASubtitle {
2525
text = prop

charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AATitle.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import com.github.aachartmodel.aainfographics.aachartcreator.AAChartAlignType
1212
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartVerticalAlignType
1313

1414
class AATitle {
15-
private var text: String? = null
16-
private var style: AAStyle? = null
17-
private var align: String? = null
18-
private var verticalAlign: String? = null
19-
private var x: Number? = null
20-
private var y: Number? = null
21-
private var userHTML: Boolean? = null
15+
var text: String? = null
16+
var style: AAStyle? = null
17+
var align: String? = null
18+
var verticalAlign: String? = null
19+
var x: Number? = null
20+
var y: Number? = null
21+
var userHTML: Boolean? = null
2222

2323
fun text(prop: String?): AATitle {
2424
text = prop

charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAXAxis.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,37 @@ open class AAXAxis: AAAxis() {
2525
return this
2626
}
2727

28-
fun title(prop: AATitle): AAXAxis {
28+
fun title(prop: AAAxisTitle): AAXAxis {
2929
title = prop
3030
return this
3131
}
3232

33+
34+
// 为了保持向后兼容性,添加对 AATitle 的支持
35+
// 同时添加方法废弃警告⚠️, 提示用户使用新的 AAAxisTitle 类型
36+
@Deprecated("Use `fun title(prop: AAAxisTitle): AAXAxis` instead. AATitle is deprecated for axis titles.")
37+
fun title(prop: AATitle?): AAXAxis {
38+
if (prop != null) {
39+
// 将AATitle转换为AAAxisTitle
40+
val axisTitle = AAAxisTitle()
41+
.text(prop.text)
42+
.style(prop.style)
43+
44+
// 如果AATitle有x和y属性, 也将它们设置到AAAxisTitle中
45+
prop.x?.let { x ->
46+
axisTitle.x(x)
47+
}
48+
prop.y?.let { y ->
49+
axisTitle.y(y)
50+
}
51+
52+
title = axisTitle
53+
} else {
54+
title = null
55+
}
56+
return this
57+
}
58+
3359
fun type(prop: AAChartAxisType): AAXAxis {
3460
type = prop.value
3561
return this

charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAYAxis.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,36 @@ open class AAYAxis: AAAxis() {
3131
return this
3232
}
3333

34-
fun title(prop: AATitle): AAYAxis {
34+
fun title(prop: AAAxisTitle): AAYAxis {
3535
title = prop
3636
return this
3737
}
3838

39+
// 为了保持向后兼容性,添加对 AATitle 的支持
40+
// 同时添加方法废弃警告⚠️, 提示用户使用新的 AAAxisTitle 类型
41+
@Deprecated("Use `fun title(prop: AAAxisTitle): AAYAxis` instead. AATitle is deprecated for axis titles.")
42+
fun title(prop: AATitle?): AAYAxis {
43+
if (prop != null) {
44+
// 将AATitle转换为AAAxisTitle
45+
val axisTitle = AAAxisTitle()
46+
.text(prop.text)
47+
.style(prop.style)
48+
49+
// 如果AATitle有x和y属性, 也将它们设置到AAAxisTitle中
50+
prop.x?.let { x ->
51+
axisTitle.x(x)
52+
}
53+
prop.y?.let { y ->
54+
axisTitle.y(y)
55+
}
56+
57+
title = axisTitle
58+
} else {
59+
title = null
60+
}
61+
return this
62+
}
63+
3964
fun type(prop: AAChartAxisType): AAYAxis {
4065
type = prop.value
4166
return this

0 commit comments

Comments
 (0)