Browse Source

Add AASVGAttributes

An An 2 years ago
parent
commit
7fbf58fcad

+ 39 - 3
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAStates.kt

@@ -90,12 +90,12 @@ class AASelect {
 }
 
 class AAHalo {
-    var attributes: Map<*, *>? = null
+    var attributes: Map<String, *>? = null
     var opacity: Float? = null
     var size: Number? = null
 
-    fun attributes(prop: Map<*, *>?): AAHalo {
-        attributes = prop
+    fun attributes(prop: AASVGAttributes?): AAHalo {
+        attributes = prop?.toDic()
         return this
     }
 
@@ -124,3 +124,39 @@ class AAInactive {
     }
 }
 
+class AASVGAttributes {
+    var fill: String? = null
+    var stroke: String? = null
+    var strokeWidth: Number? = null
+
+    fun fill(prop: String?): AASVGAttributes {
+        fill = prop
+        return this
+    }
+
+    fun stroke(prop: String?): AASVGAttributes {
+        stroke = prop
+        return this
+    }
+
+    fun strokeWidth(prop: Number?): AASVGAttributes {
+        strokeWidth = prop
+        return this
+    }
+
+    fun toDic(): Map<String, Any> {
+        val dic: MutableMap<String, Any> = HashMap()
+        if (strokeWidth != null) {
+            dic["stroke-width"] = strokeWidth!!
+        }
+        if (fill != null) {
+            dic["fill"] = fill!!
+        }
+        if (stroke != null) {
+            dic["stroke"] = stroke!!
+        }
+        return dic
+    }
+
+}
+

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

@@ -639,20 +639,22 @@ object CustomStyleChartComposer  {
                             .halo(AAHalo()
                                 .size(130)
                                 .opacity(0.8f)
-                                .attributes(mapOf(
-                                    "stroke-width" to 50,
-                                    "fill" to "#00BFFF",
-                                    "stroke" to "#00FA9A"
-                                ))))
+                                .attributes(
+                                    AASVGAttributes()
+                                        .strokeWidth(50)
+                                        .fill("#00BFFF")
+                                        .stroke("#00FA9A")
+                                )))
                         .select(AASelect()
                             .halo(AAHalo()
                                 .size(130)
                                 .opacity(1.0f)
-                                .attributes(mapOf(
-                                    "stroke-width" to 150,
-                                    "fill" to AARgba(138, 43, 226, 1.0f),
-                                    "stroke" to AARgba(30, 144, 255, 1.0f)
-                                )))))))
+                                .attributes(
+                                    AASVGAttributes()
+                                        .strokeWidth(150)
+                                        .fill(AARgba(138, 43, 226, 1.0f))
+                                        .stroke(AARgba(30, 144, 255, 1.0f))
+                                ))))))
     }
 
     fun customSplineChartMarkerStatesHoverStyle(): AAChartModel {