Sfoglia il codice sorgente

Update: tighter tap selection for pill, cleanup chart code

Jon Fawcett 5 anni fa
parent
commit
fc5e2e522d
2 ha cambiato i file con 2 aggiunte e 68 eliminazioni
  1. 2 10
      LoopFollow/Controllers/Graphs.swift
  2. 0 58
      LoopFollow/helpers/Chart.swift

+ 2 - 10
LoopFollow/Controllers/Graphs.swift

@@ -20,14 +20,7 @@ extension MainViewController {
         if entry.data as? String == "hide"{
             BGChart.highlightValue(nil, callDelegate: false)
         }
-    }
-    
-    func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
-        if chartView == BGChart {
-            let currentMatrix = chartView.viewPortHandler.touchMatrix
-            //BGChartFull.viewPortHandler.refresh(newMatrix: currentMatrix, chart: BGChartFull, invalidate: true)
-            //BGChartFull.highlightValue(x: Double(currentMatrix.tx), y: Double(currentMatrix.ty), dataSetIndex: 0)
-        }
+        
     }
     
     func chartScaled(_ chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat) {
@@ -126,7 +119,6 @@ extension MainViewController {
         lineBolus.axisDependency = YAxis.AxisDependency.right
         lineBolus.valueFormatter = ChartYDataValueFormatter()
         lineBolus.valueTextColor = NSUIColor.label
-        lineBolus.fillFormatter = BolusFillFormatter()
         lineBolus.fillColor = NSUIColor.systemBlue
         lineBolus.fillAlpha = 0.6
         
@@ -155,7 +147,6 @@ extension MainViewController {
         lineCarbs.axisDependency = YAxis.AxisDependency.right
         lineCarbs.valueFormatter = ChartYDataValueFormatter()
         lineCarbs.valueTextColor = NSUIColor.label
-        lineCarbs.fillFormatter = CarbFillFormatter()
         lineCarbs.fillColor = NSUIColor.systemOrange
         lineCarbs.fillAlpha = 0.6
        
@@ -339,6 +330,7 @@ extension MainViewController {
         BGChart.rightAxis.granularityEnabled = true
         BGChart.rightAxis.granularity = 50
         
+        BGChart.maxHighlightDistance = 15.0
         BGChart.legend.enabled = false
         BGChart.scaleYEnabled = false
         BGChart.drawGridBackgroundEnabled = true

+ 0 - 58
LoopFollow/helpers/Chart.swift

@@ -16,18 +16,6 @@ final class OverrideFillFormatter: IFillFormatter {
     }
 }
 
-final class CarbFillFormatter: IFillFormatter {
-    func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
-        return 315
-    }
-}
-
-final class BolusFillFormatter: IFillFormatter {
-    func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
-        return 345
-    }
-}
-
 final class basalFillFormatter: IFillFormatter {
     func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
         return 0
@@ -83,52 +71,6 @@ final class ChartYMMOLValueFormatter: IAxisValueFormatter {
 }
 
 
-
-
-class ChartMarker: MarkerView {
-    private var text = String()
-
-    private let drawAttributes: [NSAttributedString.Key: Any] = [
-        .font: UIFont.systemFont(ofSize: 15),
-        //.foregroundColor: UIColor.white,
-        //.backgroundColor: UIColor.darkGray
-        .foregroundColor: UIColor.label,
-        .backgroundColor: UIColor.secondarySystemBackground
-    ]
-
-    override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
-        if entry.data != nil {
-            text = entry.data as? String ?? ""
-        } else {
-            text = String(entry.y)
-        }
-    }
-
-    override func draw(context: CGContext, point: CGPoint) {
-        super.draw(context: context, point: point)
-
-        let sizeForDrawing = text.size(withAttributes: drawAttributes)
-        bounds.size = sizeForDrawing
-        offset = CGPoint(x: -sizeForDrawing.width / 2, y: -sizeForDrawing.height - 4)
-
-        let offset = offsetForDrawing(atPoint: point)
-        let originPoint = CGPoint(x: point.x + offset.x, y: point.y + offset.y)
-        let rectForText = CGRect(origin: originPoint, size: sizeForDrawing)
-        drawText(text: text, rect: rectForText, withAttributes: drawAttributes)
-    }
-
-    private func drawText(text: String, rect: CGRect, withAttributes attributes: [NSAttributedString.Key: Any]? = nil) {
-        let size = bounds.size
-        let centeredRect = CGRect(
-            x: rect.origin.x + (rect.size.width - size.width) / 2,
-            y: rect.origin.y + (rect.size.height - size.height) / 2,
-            width: size.width,
-            height: size.height
-        )
-        text.draw(in: centeredRect, withAttributes: attributes)
-    }
-}
-
 class PillMarker: MarkerImage {
 
     private (set) var color: UIColor