Skip to content

Commit

Permalink
Zoom option and marker view improvement (#12)
Browse files Browse the repository at this point in the history
This PR implements new features:
* Add zoom enable option to the chart creation
* Hide marker view when chart is not pressed.
  • Loading branch information
rodiguif authored and tiagogoncalves committed Dec 4, 2019
1 parent 2d92d1e commit e0b492f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import trikita.anvil.BaseDSL.WRAP
import trikita.anvil.BaseDSL.init
import trikita.anvil.BaseDSL.margin
import trikita.anvil.BaseDSL.size
import trikita.anvil.BaseDSL.text
import trikita.anvil.BaseDSL.textSize
import trikita.anvil.BaseDSL.typeface
import trikita.anvil.BaseDSL.v
import trikita.anvil.DSL.linearLayout
import trikita.anvil.DSL.orientation
import trikita.anvil.DSL.text
import trikita.anvil.DSL.textColor
import trikita.anvil.DSL.textView

Expand All @@ -34,6 +34,7 @@ class ForecastChartComponent(context: Context) : LinearLayout(context), Anvil.Re
private var forecastedData: Line? = null
private var endDateData: BarEntry? = null
private var unit: String = ""
private var zoomEnabled: Boolean = false

public override fun onAttachedToWindow() {
super.onAttachedToWindow()
Expand Down Expand Up @@ -139,28 +140,31 @@ class ForecastChartComponent(context: Context) : LinearLayout(context), Anvil.Re
actualData,
forecastedData,
endDateData,
unit
unit,
zoomEnabled
)
}
}
}
}

fun loadForecastChart(expectedData: Line, actualData: Line, forecastedData: Line,
endDateData: BarEntry, unit: String){
endDateData: BarEntry, unit: String, zoomEnabled: Boolean = false){
this.expectedData = expectedData
this.actualData = actualData
this.forecastedData = forecastedData
this.endDateData = endDateData
this.unit = unit
this.zoomEnabled = zoomEnabled
}

fun loadForecastChart(actualData: Line, forecastedData: Line,
endDateData: BarEntry, unit: String){
endDateData: BarEntry, unit: String, zoomEnabled: Boolean = false){
this.expectedData = Line(arrayListOf(), "", 0, false)
this.actualData = actualData
this.forecastedData = forecastedData
this.endDateData = endDateData
this.unit = unit
this.zoomEnabled = zoomEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object ForecastChart{

fun createForecastChart(context: Context, combinedChart: CombinedChart, expectedData: Line,
actualData: Line, forecastedData: Line, endDateData: BarEntry,
unit: String) {
unit: String, zoomEnabled: Boolean) {

val production = setupLineDataSet(expectedData)
val actual = setupLineDataSet(actualData)
Expand All @@ -43,6 +43,6 @@ object ForecastChart{
combinedData.setData(barData)

combinedChart.data = combinedData
configChart(context, combinedChart, unit)
configChart(context, combinedChart, unit, zoomEnabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ object SetupChart{
return barDataSet
}

fun configChart(context: Context, combinedChart: CombinedChart, unit: String){
fun configChart(context: Context, combinedChart: CombinedChart, unit: String,
zoomEnabled: Boolean){
combinedChart.legend.form = Legend.LegendForm.LINE
combinedChart.legend.xEntrySpace = LEGEND_SIZE
combinedChart.legend.textSize = LEGEND_SIZE
Expand All @@ -62,6 +63,7 @@ object SetupChart{

combinedChart.description = null
combinedChart.setPinchZoom(true)
combinedChart.setScaleEnabled(zoomEnabled)

val marker = ForecastMarkerView(
context,
Expand All @@ -71,5 +73,9 @@ object SetupChart{
combinedChart.marker = marker
combinedChart.extraLeftOffset = SIDE_OFFSET
combinedChart.extraRightOffset = SIDE_OFFSET

combinedChart.setOnClickListener {
combinedChart.highlightValue(null)
}
}
}

0 comments on commit e0b492f

Please sign in to comment.