|
| 1 | +package com.github.mikephil.charting.components |
| 2 | + |
| 3 | +import android.graphics.Color |
| 4 | +import android.graphics.Typeface |
| 5 | +import com.github.mikephil.charting.utils.Utils |
| 6 | + |
| 7 | +/** |
| 8 | + * This class encapsulates everything both Axis, Legend and LimitLines have in common. |
| 9 | + */ |
| 10 | +abstract class ComponentBase { |
| 11 | + |
| 12 | + /** |
| 13 | + * flag that indicates if this axis / legend is enabled or not |
| 14 | + */ |
| 15 | + var isEnabled: Boolean = true |
| 16 | + |
| 17 | + /** |
| 18 | + * the offset in pixels this component has on the x-axis |
| 19 | + */ |
| 20 | + @JvmField |
| 21 | + protected var mXOffset: Float = 5f |
| 22 | + |
| 23 | + /** |
| 24 | + * the offset in pixels this component has on the Y-axis |
| 25 | + */ |
| 26 | + @JvmField |
| 27 | + protected var mYOffset: Float = 5f |
| 28 | + |
| 29 | + /** |
| 30 | + * the typeface used for the labels |
| 31 | + */ |
| 32 | + var typeface: Typeface? = null |
| 33 | + |
| 34 | + /** |
| 35 | + * the text size of the labels |
| 36 | + */ |
| 37 | + @JvmField |
| 38 | + protected var mTextSize: Float = Utils.convertDpToPixel(10f) |
| 39 | + |
| 40 | + /** |
| 41 | + * the text color to use for the labels |
| 42 | + */ |
| 43 | + open var textColor: Int = Color.BLACK |
| 44 | + |
| 45 | + /** |
| 46 | + * Returns the used offset on the x-axis for drawing the axis or legend |
| 47 | + * labels. This offset is applied before and after the label. |
| 48 | + */ |
| 49 | + var xOffset: Float |
| 50 | + get() = mXOffset |
| 51 | + set(xOffset) { |
| 52 | + mXOffset = Utils.convertDpToPixel(xOffset) |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the used offset on the x-axis for drawing the axis labels. This |
| 57 | + * offset is applied before and after the label. |
| 58 | + */ |
| 59 | + var yOffset: Float |
| 60 | + get() = mYOffset |
| 61 | + set(yOffset) { |
| 62 | + mYOffset = Utils.convertDpToPixel(yOffset) |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * returns the text size that is currently set for the labels, in pixels |
| 67 | + */ |
| 68 | + var textSize: Float |
| 69 | + get() = mTextSize |
| 70 | + set(size) { |
| 71 | + var sizeLocal = size |
| 72 | + if (sizeLocal > 24f) sizeLocal = 24f |
| 73 | + if (sizeLocal < 6f) sizeLocal = 6f |
| 74 | + |
| 75 | + mTextSize = Utils.convertDpToPixel(sizeLocal) |
| 76 | + } |
| 77 | +} |
0 commit comments