Эх сурвалжийг харах

Optimize configureAAPlotLinesForChart sample

An An 3 жил өмнө
parent
commit
bebe391f61

+ 45 - 46
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AALabel.kt

@@ -9,61 +9,60 @@
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
 class AALabel {
-    class AALabel {
-        var align: String? = null //标签的对齐方式,可用的值有 "left"、"center" 及 "right"。默认值是根据坐标轴的位置(在图表中的位置)即标签的旋转角度进行智能判断的。 默认是:center.
-        var rotation: Number? = null //标签的旋转角度 默认是:0.
-        var text: String? = null //文字
-        var textAlign: String? = null //文字对齐
-        var useHTML: Boolean? = null //HTML渲染
-        var verticalAlign: String? = null //竖直对齐
-        var style: Any? = null //轴标签的 CSS 样式
-        var x: Number? = null //水平偏移
-        var y: Number? = null // 竖直偏移
+    var align: String? = null //标签的对齐方式,可用的值有 "left"、"center" 及 "right"。默认值是根据坐标轴的位置(在图表中的位置)即标签的旋转角度进行智能判断的。 默认是:center.
+    var rotation: Number? = null //标签的旋转角度 默认是:0.
+    var text: String? = null //文字
+    var textAlign: String? = null //文字对齐
+    var useHTML: Boolean? = null //HTML渲染
+    var verticalAlign: String? = null //竖直对齐
+    var style: Any? = null //轴标签的 CSS 样式
+    var x: Number? = null //水平偏移
+    var y: Number? = null // 竖直偏移
 
 
-        fun align(prop: String?): AALabel {
-            align = prop
-            return this
-        }
+    fun align(prop: String?): AALabel {
+        align = prop
+        return this
+    }
 
-        fun rotation(prop: Number?): AALabel {
-            rotation = prop
-            return this
-        }
+    fun rotation(prop: Number?): AALabel {
+        rotation = prop
+        return this
+    }
 
-        fun text(prop: String?): AALabel {
-            text = prop
-            return this
-        }
+    fun text(prop: String?): AALabel {
+        text = prop
+        return this
+    }
 
-        fun textAlign(prop: String?): AALabel {
-            textAlign = prop
-            return this
-        }
+    fun textAlign(prop: String?): AALabel {
+        textAlign = prop
+        return this
+    }
 
-        fun useHTML(prop: Boolean?): AALabel {
-            useHTML = prop
-            return this
-        }
+    fun useHTML(prop: Boolean?): AALabel {
+        useHTML = prop
+        return this
+    }
 
-        fun verticalAlign(prop: String?): AALabel {
-            verticalAlign = prop
-            return this
-        }
+    fun verticalAlign(prop: String?): AALabel {
+        verticalAlign = prop
+        return this
+    }
 
-        fun style(prop: Any?): AALabel {
-            style = prop
-            return this
-        }
+    fun style(prop: Any?): AALabel {
+        style = prop
+        return this
+    }
 
-        fun x(prop: Number?): AALabel {
-            x = prop
-            return this
-        }
+    fun x(prop: Number?): AALabel {
+        x = prop
+        return this
+    }
 
-        fun y(prop: Number?): AALabel {
-            y = prop
-            return this
-        }
+    fun y(prop: Number?): AALabel {
+        y = prop
+        return this
     }
+
 }

+ 14 - 6
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAStyle.kt

@@ -8,6 +8,8 @@
  */
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
+import com.github.aachartmodel.aainfographics.aachartcreator.AAChartFontWeightType
+
 
 class AAStyle {
     var background: String? = null
@@ -33,6 +35,8 @@ class AAStyle {
     var transition: String? = null
     var whiteSpace: String? = null
     var width: Number? = null
+
+
     fun background(prop: String?): AAStyle {
         background = prop
         return this
@@ -49,7 +53,9 @@ class AAStyle {
     }
 
     fun borderRadius(prop: Number?): AAStyle {
-        borderRadius = prop.toString() + "px"
+        prop?.let {
+            borderRadius = "${prop}px"
+        }
         return this
     }
 
@@ -69,12 +75,14 @@ class AAStyle {
     }
 
     fun fontSize(prop: Number?): AAStyle {
-        fontSize = prop.toString() + "px"
+        prop?.let {
+            fontSize = "${prop}px"
+        }
         return this
     }
 
-    fun fontWeight(prop: String?): AAStyle {
-        fontWeight = prop
+    fun fontWeight(prop: AAChartFontWeightType?): AAStyle {
+        fontWeight = prop?.value
         return this
     }
 
@@ -165,7 +173,7 @@ class AAStyle {
         fun style(
             color: String?,
             fontSize: Float?,
-            fontWeight: String?
+            fontWeight: AAChartFontWeightType?
         ): AAStyle {
             return style(color, fontSize, fontWeight, null)
         }
@@ -173,7 +181,7 @@ class AAStyle {
         fun style(
             color: String?,
             fontSize: Float?,
-            fontWeight: String?,
+            fontWeight: AAChartFontWeightType?,
             textOutline: String?
         ): AAStyle {
             return AAStyle()

+ 26 - 10
sample/src/main/java/com/github/aachartmodel/aainfographics/demo/chartcomposer/ChartOptionsComposer.kt

@@ -173,6 +173,25 @@ object ChartOptionsComposer {
             ))
 
         val aaOptions = aaChartModel.aa_toAAOptions()
+
+        val aaStyle = AAStyle()
+            .color("#FFD700") //#FFD700(纯金色)
+            .backgroundColor(AAColor.Black)
+            .borderRadius(5)
+            .border("6px solid #000000")
+            .opacity(1.0)
+            .fontWeight(AAChartFontWeightType.Bold)
+
+        val aaStyle1 = AAStyle()
+            .color(AAColor.Red) //#FFD700(纯金色)
+            .backgroundColor(AAColor.Black)
+            .borderRadius(5)
+            .border("2px solid red")
+            .opacity(1.0)
+            .fontWeight(AAChartFontWeightType.Bold)
+            .padding("6px")
+            .fontSize(16)
+
         val aaPlotLinesElementsArr = arrayOf(
             AAPlotLinesElement()
                 .color("#1e90ff")//颜色值(16进制)
@@ -181,10 +200,9 @@ object ChartOptionsComposer {
                 .value(12f) //所在位置
                 .zIndex(1) //层叠,标示线在图表中显示的层叠级别,值越大,显示越向前
                 .label(AALabel()
+                    .useHTML(true)
                     .text("PLOT LINES ONE")
-                    .style(AAStyle()
-                        .color("#1e90ff")
-                        .fontWeight(AAChartFontWeightType.Bold))),
+                    .style(aaStyle1)),
             AAPlotLinesElement()
                 .color("#ef476f")//颜色值(16进制)
                 .dashStyle(AAChartLineDashStyleType.LongDashDot)//样式:Dash,Dot,Solid等,默认Solid
@@ -192,10 +210,9 @@ object ChartOptionsComposer {
                 .value(24f) //所在位置
                 .zIndex(1) //层叠,标示线在图表中显示的层叠级别,值越大,显示越向前
                 .label(AALabel()
+                    .useHTML(true)
                     .text("PLOT LINES TWO")
-                    .style(AAStyle()
-                        .color("#ef476f")
-                        .fontWeight(AAChartFontWeightType.Bold))),
+                    .style(aaStyle)),
             AAPlotLinesElement()
                 .color("#1e90ff")//颜色值(16进制)
                 .dashStyle(AAChartLineDashStyleType.LongDash)//样式:Dash,Dot,Solid等,默认Solid
@@ -203,11 +220,10 @@ object ChartOptionsComposer {
                 .value(36f) //所在位置
                 .zIndex(1) //层叠,标示线在图表中显示的层叠级别,值越大,显示越向前
                 .label(AALabel()
+                    .useHTML(true)
                     .text("PLOT LINES THREE")
-                    .style(AAStyle()
-                        .color("#04d69f")
-                        .fontWeight(AAChartFontWeightType.Bold)))
-        )
+                    .style(aaStyle))
+            )
         aaOptions.yAxis?.plotLines(aaPlotLinesElementsArr)
 
         return aaOptions