Explorar o código

Add minor grid and minor tick properties for AAXAxis and AAYAxis

An An %!s(int64=3) %!d(string=hai) anos
pai
achega
b51ffbe42b

+ 65 - 3
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAXAxis.kt

@@ -20,6 +20,19 @@ class AAXAxis {
     var lineColor: String? = null //x轴轴线线颜色
     var max: Float? = null //x轴最大值
     var min: Float? = null//x轴最小值(设置为0就不会有负数)
+    var minRange: Int? = null
+    var minTickInterval: Int? = null //The minimum tick interval allowed in axis values. For example on zooming in on an axis with daily data, this can be used to prevent the axis from showing hours. Defaults to the closest distance between two points on the axis.
+    var minorGridLineColor: String? = null //Color of the minor, secondary grid lines.
+    var minorGridLineDashStyle: String? = null //The dash or dot style of the minor grid lines.
+    var minorGridLineWidth: Float? = null //Width of the minor, secondary grid lines.
+    var minorTickColor: String? = null //Color for the minor tick marks.
+    var minorTickInterval: Any? = null /*Specific tick interval in axis units for the minor ticks. On a linear axis, if "auto", the minor tick interval is calculated as a fifth of the tickInterval. If null or undefined, minor ticks are not shown.
+     On logarithmic axes, the unit is the power of the value. For example, setting the minorTickInterval to 1 puts one tick on each of 0.1, 1, 10, 100 etc. Setting the minorTickInterval to 0.1 produces 9 ticks between 1 and 10, 10 and 100 etc.
+    If user settings dictate minor ticks to become too dense, they don't make sense, and will be ignored to prevent performance problems.*/
+    var minorTickLength: Float? = null //The pixel length of the minor tick marks.
+    var minorTickPosition: String? = null //The position of the minor tick marks relative to the axis line. Can be one of inside and outside. Defaults to outside.
+    var minorTickWidth: Float? = null //The pixel width of the minor tick mark.
+
     var tickColor: String? = null //x轴轴线下方刻度线颜色
     var gridLineWidth: Float? = null //x轴网格线宽度
     var gridLineColor: String? = null //x轴网格线颜色
@@ -27,8 +40,7 @@ class AAXAxis {
     var off: Float? = null//x轴垂直偏移
     var labels: AALabels? = null //用于设置 x 轴文字相关的
     var visible: Boolean? = null //用于设置 x 轴以及 x 轴文字是否显示
-    var startOnTick: Boolean? =
-        null //Whether to force the axis to start on a tick. Use this option with the minPadding option to control the axis start. 默认是:false.
+    var startOnTick: Boolean? = null //Whether to force the axis to start on a tick. Use this option with the minPadding option to control the axis start. 默认是:false.
     var tickInterval: Int? = null//x轴刻度点间隔数(设置每隔几个点显示一个 X轴的内容:
     var crosshair: AACrosshair? = null //准星线样式设置
     var tickmarkPlacement: String? =
@@ -94,7 +106,57 @@ class AAXAxis {
         return this
     }
 
-    fun tickColor(prop: String): AAXAxis {
+    fun minRange(prop: Int?): AAXAxis {
+        minRange = prop
+        return this
+    }
+
+    fun minTickInterval(prop: Int?): AAXAxis {
+        minTickInterval = prop
+        return this
+    }
+
+    fun minorGridLineColor(prop: String?): AAXAxis {
+        minorGridLineColor = prop
+        return this
+    }
+
+    fun minorGridLineDashStyle(prop: String?): AAXAxis {
+        minorGridLineDashStyle = prop
+        return this
+    }
+
+    fun minorGridLineWidth(prop: Float?): AAXAxis {
+        minorGridLineWidth = prop
+        return this
+    }
+
+    fun minorTickColor(prop: String?): AAXAxis {
+        minorTickColor = prop
+        return this
+    }
+
+    fun minorTickInterval(prop: Any?): AAXAxis {
+        minorTickInterval = prop
+        return this
+    }
+
+    fun minorTickLength(prop: Float?): AAXAxis {
+        minorTickLength = prop
+        return this
+    }
+
+    fun minorTickPosition(prop: String?): AAXAxis {
+        minorTickPosition = prop
+        return this
+    }
+
+    fun minorTickWidth(prop: Float?): AAXAxis {
+        minorTickWidth = prop
+        return this
+    }
+
+    fun tickColor(prop: String?): AAXAxis {
         tickColor = prop
         return this
     }

+ 62 - 0
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAYAxis.kt

@@ -27,6 +27,18 @@ class AAYAxis {
     var allowDecimals: Boolean? = null //y轴是否允许显示小数
     var max: Float? = null //y轴最大值
     var min: Float? = null //y轴最小值(设置为0就不会有负数)
+    var minRange: Int? = null
+    var minTickInterval: Int? = null //The minimum tick interval allowed in axis values. For example on zooming in on an axis with daily data, this can be used to prevent the axis from showing hours. Defaults to the closest distance between two points on the axis.
+    var minorGridLineColor: String? = null //Color of the minor, secondary grid lines.
+    var minorGridLineDashStyle: String? = null //The dash or dot style of the minor grid lines.
+    var minorGridLineWidth: Float? = null //Width of the minor, secondary grid lines.
+    var minorTickColor: String? = null //Color for the minor tick marks.
+    var minorTickInterval: Any? = null /*Specific tick interval in axis units for the minor ticks. On a linear axis, if "auto", the minor tick interval is calculated as a fifth of the tickInterval. If null or undefined, minor ticks are not shown.
+     On logarithmic axes, the unit is the power of the value. For example, setting the minorTickInterval to 1 puts one tick on each of 0.1, 1, 10, 100 etc. Setting the minorTickInterval to 0.1 produces 9 ticks between 1 and 10, 10 and 100 etc.
+    If user settings dictate minor ticks to become too dense, they don't make sense, and will be ignored to prevent performance problems.*/
+    var minorTickLength: Float? = null //The pixel length of the minor tick marks.
+    var minorTickPosition: String? = null //The position of the minor tick marks relative to the axis line. Can be one of inside and outside. Defaults to outside.
+    var minorTickWidth: Float? = null //The pixel width of the minor tick mark.
 
     // var minPadding:   //Padding of the min value relative to the length of the axis. A padding of 0.05 will make a 100px axis 5px longer. This is useful when you don't want the lowest data value to appear on the edge of the plot area. 默认是:0.05.
     var tickPositions: Array<Any>? = null //自定义Y轴坐标(如:[0, 25, 50, 75 , 100])
@@ -127,6 +139,56 @@ class AAYAxis {
         return this
     }
 
+    fun minRange(prop: Int?): AAYAxis {
+        minRange = prop
+        return this
+    }
+
+    fun minTickInterval(prop: Int?): AAYAxis {
+        minTickInterval = prop
+        return this
+    }
+
+    fun minorGridLineColor(prop: String?): AAYAxis {
+        minorGridLineColor = prop
+        return this
+    }
+
+    fun minorGridLineDashStyle(prop: String?): AAYAxis {
+        minorGridLineDashStyle = prop
+        return this
+    }
+
+    fun minorGridLineWidth(prop: Float?): AAYAxis {
+        minorGridLineWidth = prop
+        return this
+    }
+
+    fun minorTickColor(prop: String?): AAYAxis {
+        minorTickColor = prop
+        return this
+    }
+
+    fun minorTickInterval(prop: Any?): AAYAxis {
+        minorTickInterval = prop
+        return this
+    }
+
+    fun minorTickLength(prop: Float?): AAYAxis {
+        minorTickLength = prop
+        return this
+    }
+
+    fun minorTickPosition(prop: String?): AAYAxis {
+        minorTickPosition = prop
+        return this
+    }
+
+    fun minorTickWidth(prop: Float?): AAYAxis {
+        minorTickWidth = prop
+        return this
+    }
+
     fun tickPositions(prop: Array<Any>): AAYAxis {
         tickPositions = prop
         return this

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

@@ -75,14 +75,28 @@ class ChartOptionsComposer {
 
             val aaOptions = aaChartModel.aa_toAAOptions()
 
+            aaOptions.yAxis?.labels?.format = "{value} %"//给y轴添加单位
+
+            aaOptions.xAxis!!
+                    .gridLineColor(AAColor.DarkGray)
+                    .gridLineWidth(1f)
+                    .minorGridLineColor(AAColor.LightGray)
+                    .minorGridLineWidth(0.5f)
+                    .minorTickInterval("auto")
+
+            aaOptions.yAxis!!
+                    .gridLineColor(AAColor.DarkGray)
+                    .gridLineWidth(1f)
+                    .minorGridLineColor(AAColor.LightGray)
+                    .minorGridLineWidth(0.5f)
+                    .minorTickInterval("auto")
+
             aaOptions.legend!!
                 .enabled(true)
                 .verticalAlign(AAChartVerticalAlignType.Top)
                 .layout(AAChartLayoutType.Vertical)
                 .align(AAChartAlignType.Right)
 
-            aaOptions.yAxis?.labels?.format = "{value} %"//给y轴添加单位
-
             aaOptions.defaultOptions = AALang()
                 .resetZoom("重置缩放比例")
                 .thousandsSep(",")