Bladeren bron

Refactor AAXAxis and AAYAxis extend AAAxis

An An 3 jaren geleden
bovenliggende
commit
4ff0c6d03d

+ 48 - 90
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAXAxis.kt

@@ -8,64 +8,23 @@
  */
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
-enum class AAChartAxisType(val value: String) {
-    Linear("linear"),
-    Logarithmic("logarithmic"),
-    Datetime("datetime"),
-    Category("category"),
-}
-
-class AAXAxis {
-    var alternateGridColor: Any? = null
-    var title: AATitle? = null
-    var type: String? = null
-    var dateTimeLabelFormats: AADateTimeLabelFormats? = null
-    var plotBands: Array<AAPlotBandsElement>? = null
-    var plotLines: Array<AAPlotLinesElement>? = null
-    var categories: Array<String>? = null
-    var linkedTo: Int? = null
-    var reversed: Boolean? = null
-    var opposite: Boolean? = null
-    var lineWidth: Float? = null //x轴轴线宽度
-    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轴网格线颜色
-    var gridLineDashStyle: String? = null //x轴网格线样式
-    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 tickInterval: Int? = null//x轴刻度点间隔数(设置每隔几个点显示一个 X轴的内容:
-    var crosshair: AACrosshair? = null //准星线样式设置
-    var tickmarkPlacement: String? =
-        null //本参数只对分类轴有效。 当值为 on 时刻度线将在分类上方显示;当值为 between 时,刻度线将在两个分类中间显示。当 tickInterval 为 1 时,默认是 between,其他情况默认是 on。 默认是:null.
-    var tickWidth: Float? = null//坐标轴刻度线的宽度,设置为 0 时则不显示刻度线
-    var tickLength: Float? = null//坐标轴刻度线的长度。 默认是:10.
-    var tickPosition: String? =
-        null //刻度线相对于轴线的位置,可用的值有 inside 和 outside,分别表示在轴线的内部和外部。 默认是:outside.
-    var tickPositions: Array<Any>? = null // Custom x-axis coordinates
+
+class AAXAxis: AAAxis() {
+    fun allowDecimals(prop: Boolean?): AAXAxis {
+        allowDecimals = prop
+        return this
+    }
 
     fun alternateGridColor(prop: Any): AAXAxis {
         alternateGridColor = prop
         return this
     }
 
+    fun crosshair(prop: AACrosshair): AAXAxis {
+        crosshair = prop
+        return this
+    }
+
     fun title(prop: AATitle): AAXAxis {
         title = prop
         return this
@@ -106,11 +65,30 @@ class AAXAxis {
         return this
     }
 
-    fun opposite(prop: Boolean?): AAXAxis {
-        opposite = prop
+    fun gridLineWidth(prop: Float?): AAXAxis {
+        gridLineWidth = prop
+        return this
+    }
+
+    fun gridLineColor(prop: String): AAXAxis {
+        gridLineColor = prop
+        return this
+    }
+
+    fun gridLineDashStyle(prop: String): AAXAxis {
+        gridLineDashStyle = prop
+        return this
+    }
+
+    fun gridLineInterpolation(prop: String): AAXAxis {
+        gridLineInterpolation = prop
         return this
     }
 
+    fun labels(prop: AALabels): AAXAxis {
+        labels = prop
+        return this
+    }
 
     fun lineWidth(prop: Float?): AAXAxis {
         lineWidth = prop
@@ -122,6 +100,11 @@ class AAXAxis {
         return this
     }
 
+    fun off(prop: Float?): AAXAxis {
+        off = prop
+        return this
+    }
+
     fun max(prop: Float?): AAXAxis {
         max = prop
         return this
@@ -182,43 +165,28 @@ class AAXAxis {
         return this
     }
 
-    fun tickColor(prop: String?): AAXAxis {
-        tickColor = prop
-        return this
-    }
-
-    fun gridLineWidth(prop: Float?): AAXAxis {
-        gridLineWidth = prop
-        return this
-    }
-
-    fun gridLineColor(prop: String): AAXAxis {
-        gridLineColor = prop
-        return this
-    }
-
-    fun gridLineDashStyle(prop: String): AAXAxis {
-        gridLineDashStyle = prop
+    fun visible(prop: Boolean?): AAXAxis {
+        visible = prop
         return this
     }
 
-    fun off(prop: Float?): AAXAxis {
-        off = prop
+    fun startOnTick(prop: Boolean?): AAXAxis {
+        startOnTick = prop
         return this
     }
 
-    fun labels(prop: AALabels): AAXAxis {
-        labels = prop
+    fun opposite(prop: Boolean?): AAXAxis {
+        opposite = prop
         return this
     }
 
-    fun visible(prop: Boolean?): AAXAxis {
-        visible = prop
+    fun tickColor(prop: String?): AAXAxis {
+        tickColor = prop
         return this
     }
 
-    fun startOnTick(prop: Boolean?): AAXAxis {
-        startOnTick = prop
+    fun tickPositions(prop: Array<Any>): AAXAxis {
+        tickPositions = prop
         return this
     }
 
@@ -227,11 +195,6 @@ class AAXAxis {
         return this
     }
 
-    fun crosshair(prop: AACrosshair): AAXAxis {
-        crosshair = prop
-        return this
-    }
-
     fun tickmarkPlacement(prop: String): AAXAxis {
         tickmarkPlacement = prop
         return this
@@ -251,9 +214,4 @@ class AAXAxis {
         tickPosition = prop
         return this
     }
-
-    fun tickPositions(prop: Array<Any>): AAXAxis {
-        tickPositions = prop
-        return this
-    }
-}
+}

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

@@ -8,58 +8,29 @@
  */
 package com.github.aachartmodel.aainfographics.aaoptionsmodel
 
-class AAYAxis {
-    var alternateGridColor: Any? = null
-    var title: AATitle? = null
-    var type: String? = null
-    var dateTimeLabelFormats: AADateTimeLabelFormats? = null
-    var plotBands: Array<AAPlotBandsElement>? = null
-    var plotLines: Array<AAPlotLinesElement>? = null
-    var categories: Array<String>? = null
-    var reversed: Boolean? = null
-    var gridLineWidth: Float? = null// y 轴网格线宽度
-    var gridLineColor: String? = null  // y 轴网格线颜色
-    var gridLineDashStyle: String? = null //网格线线条样式,所有可用的线条样式参考:Highcharts线条样式
-    var gridLineInterpolation: String? =
-        null //Polar charts only. Whether the grid lines should draw as a polygon with straight lines between categories, or as circles. Can be either circle or polygon. 默认是:null.
-    var labels: AALabels? = null//用于设置 y 轴文字相关的
-    var lineWidth: Float? = null // y 轴线宽度
-    var lineColor: String? = null // y 轴线颜色
-    var off: Float? = null // y 轴线水平偏移
-    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])
-    var visible: Boolean? = null //y轴是否允许显示
-    var opposite: Boolean? =
-        null//是否将坐标轴显示在对立面,默认情况下 x 轴是在图表的下方显示,y 轴是在左方,坐标轴显示在对立面后,x 轴是在上方显示,y 轴是在右方显示(即坐标轴会显示在对立面)。该配置一般是用于多坐标轴区分展示,另外在 Highstock 中,y 轴默认是在对立面显示的。 默认是:false.
-    var tickInterval: Int? = null
-    var crosshair: AACrosshair? = null  //准星线样式设置
-    var stackLabels: String? = null
-    var tickWidth: Float? = null//坐标轴刻度线的宽度,设置为 0 时则不显示刻度线
-    var tickLength: Float? = null//坐标轴刻度线的长度。 默认是:10.
-    var tickPosition: String? =
-        null //刻度线相对于轴线的位置,可用的值有 inside 和 outside,分别表示在轴线的内部和外部。 默认是:outside.
+class AAYAxis: AAAxis() {
+    var stackLabels: Any? = null
+    fun stackLabels(prop: Any?): AAYAxis {
+        stackLabels = prop
+        return this
+    }
+//////////////////////////////////////////////
+
+    fun allowDecimals(prop: Boolean?): AAYAxis {
+        allowDecimals = prop
+        return this
+    }
 
     fun alternateGridColor(prop: Any): AAYAxis {
         alternateGridColor = prop
         return this
     }
 
+    fun crosshair(prop: AACrosshair): AAYAxis {
+        crosshair = prop
+        return this
+    }
+
     fun title(prop: AATitle): AAYAxis {
         title = prop
         return this
@@ -85,11 +56,16 @@ class AAYAxis {
         return this
     }
 
-    fun categories(prop: Array<String>): AAYAxis {
+    fun categories(prop: Array<String>?): AAYAxis {
         categories = prop
         return this
     }
 
+    fun linkedTo(prop: Int?): AAYAxis {
+        linkedTo = prop
+        return this
+    }
+
     fun reversed(prop: Boolean?): AAYAxis {
         reversed = prop
         return this
@@ -135,11 +111,6 @@ class AAYAxis {
         return this
     }
 
-    fun allowDecimals(prop: Boolean?): AAYAxis {
-        allowDecimals = prop
-        return this
-    }
-
     fun max(prop: Float?): AAYAxis {
         max = prop
         return this
@@ -200,13 +171,13 @@ class AAYAxis {
         return this
     }
 
-    fun tickPositions(prop: Array<Any>): AAYAxis {
-        tickPositions = prop
+    fun visible(prop: Boolean?): AAYAxis {
+        visible = prop
         return this
     }
 
-    fun visible(prop: Boolean?): AAYAxis {
-        visible = prop
+    fun startOnTick(prop: Boolean?): AAYAxis {
+        startOnTick = prop
         return this
     }
 
@@ -215,18 +186,23 @@ class AAYAxis {
         return this
     }
 
-    fun tickInterval(prop: Int?): AAYAxis {
-        tickInterval = prop
+    fun tickColor(prop: String?): AAYAxis {
+        tickColor = prop
         return this
     }
 
-    fun crosshair(prop: AACrosshair): AAYAxis {
-        crosshair = prop
+    fun tickPositions(prop: Array<Any>): AAYAxis {
+        tickPositions = prop
         return this
     }
 
-    fun stackLabels(prop: String): AAYAxis {
-        stackLabels = prop
+    fun tickInterval(prop: Int?): AAYAxis {
+        tickInterval = prop
+        return this
+    }
+
+    fun tickmarkPlacement(prop: String): AAYAxis {
+        tickmarkPlacement = prop
         return this
     }