Pārlūkot izejas kodu

🚀 Enhance AALabel and AAStyle

An An 3 gadi atpakaļ
vecāks
revīzija
2428f411d3

+ 54 - 9
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AALabel.kt

@@ -9,16 +9,61 @@
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
 class AALabel {
-    var text: String? = null
-    var style: Any? = null
+    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 // 竖直偏移
 
-    fun text(prop: String): AALabel {
-        text = prop
-        return this
-    }
 
-    fun style(prop: Any): AALabel {
-        style = prop
-        return this
+        fun align(prop: String?): AALabel {
+            align = prop
+            return this
+        }
+
+        fun rotation(prop: Number?): AALabel {
+            rotation = prop
+            return this
+        }
+
+        fun text(prop: String?): AALabel {
+            text = prop
+            return this
+        }
+
+        fun textAlign(prop: String?): AALabel {
+            textAlign = prop
+            return this
+        }
+
+        fun useHTML(prop: Boolean?): AALabel {
+            useHTML = prop
+            return this
+        }
+
+        fun verticalAlign(prop: String?): AALabel {
+            verticalAlign = prop
+            return this
+        }
+
+        fun style(prop: Any?): AALabel {
+            style = prop
+            return this
+        }
+
+        fun x(prop: Number?): AALabel {
+            x = prop
+            return this
+        }
+
+        fun y(prop: Number?): AALabel {
+            y = prop
+            return this
+        }
     }
 }

+ 156 - 11
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAStyle.kt

@@ -8,34 +8,179 @@
  */
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
-import com.github.aachartmodel.aainfographics.aachartcreator.AAChartFontWeightType
-
 
 class AAStyle {
+    var background: String? = null
+    var backgroundColor: String? = null
+    var border: String? = null
+    var borderRadius: String? = null
+    var color: String? = null
+    var cursor: String? = null
+    var fontFamily: String? = null
+    var fontSize: String? = null
+    var fontWeight: String? = null
+    var height: Number? = null
+    var lineWidth: Number? = null
+    var opacity: Number? = null
+    var padding: String? = null
+    var pointerEvents: String? = null
+    var position: String? = null
+    var textAlign: String? = null
+    var textDecoration: String? = null
+    var textOutline: String? = null
+    var textOverflow: String? = null
+    var top: String? = null
+    var transition: String? = null
+    var whiteSpace: String? = null
+    var width: Number? = null
+    fun background(prop: String?): AAStyle {
+        background = prop
+        return this
+    }
+
+    fun backgroundColor(prop: String?): AAStyle {
+        backgroundColor = prop
+        return this
+    }
 
-    private var color: String? = null
-    private var fontSize: String? = null
-    private var fontWeight: String? = null
-    private var textOutline: String? = null
+    fun border(prop: String?): AAStyle {
+        border = prop
+        return this
+    }
+
+    fun borderRadius(prop: Number?): AAStyle {
+        borderRadius = prop.toString() + "px"
+        return this
+    }
 
     fun color(prop: String?): AAStyle {
         color = prop
         return this
     }
 
-    fun fontSize(prop: Float?): AAStyle {
-        fontSize = "${prop}px"
+    fun cursor(prop: String?): AAStyle {
+        cursor = prop
+        return this
+    }
+
+    fun fontFamily(prop: String?): AAStyle {
+        fontFamily = prop
+        return this
+    }
+
+    fun fontSize(prop: Number?): AAStyle {
+        fontSize = prop.toString() + "px"
+        return this
+    }
+
+    fun fontWeight(prop: String?): AAStyle {
+        fontWeight = prop
+        return this
+    }
+
+    fun height(prop: Number?): AAStyle {
+        height = prop
+        return this
+    }
+
+    fun lineWidth(prop: Number?): AAStyle {
+        lineWidth = prop
+        return this
+    }
+
+    fun opacity(prop: Number?): AAStyle {
+        opacity = prop
+        return this
+    }
+
+    fun padding(prop: String?): AAStyle {
+        padding = prop
+        return this
+    }
+
+    fun pointerEvents(prop: String?): AAStyle {
+        pointerEvents = prop
+        return this
+    }
+
+    fun position(prop: String?): AAStyle {
+        position = prop
         return this
     }
 
-    fun fontWeight(prop: AAChartFontWeightType?): AAStyle {
-        fontWeight = prop?.value
+    fun textAlign(prop: String?): AAStyle {
+        textAlign = prop
         return this
     }
 
-    fun textOutline(prop: String): AAStyle {
+    fun textDecoration(prop: String?): AAStyle {
+        textDecoration = prop
+        return this
+    }
+
+    fun textOutline(prop: String?): AAStyle {
         textOutline = prop
         return this
     }
 
+    fun textOverflow(prop: String?): AAStyle {
+        textOverflow = prop
+        return this
+    }
+
+    fun top(prop: String?): AAStyle {
+        top = prop
+        return this
+    }
+
+    fun transition(prop: String?): AAStyle {
+        transition = prop
+        return this
+    }
+
+    fun whiteSpace(prop: String?): AAStyle {
+        whiteSpace = prop
+        return this
+    }
+
+    fun width(prop: Number?): AAStyle {
+        width = prop
+        return this
+    }
+
+    companion object {
+        fun style(
+            color: String?
+        ): AAStyle {
+            return style(color, null)
+        }
+
+        fun style(
+            color: String?,
+            fontSize: Float?
+        ): AAStyle {
+            return style(color, fontSize, null)
+        }
+
+        fun style(
+            color: String?,
+            fontSize: Float?,
+            fontWeight: String?
+        ): AAStyle {
+            return style(color, fontSize, fontWeight, null)
+        }
+
+        fun style(
+            color: String?,
+            fontSize: Float?,
+            fontWeight: String?,
+            textOutline: String?
+        ): AAStyle {
+            return AAStyle()
+                .color(color)
+                .fontSize(fontSize)
+                .fontWeight(fontWeight)
+                .textOutline(textOutline)
+        }
+    }
 }