Skip to content

Commit

Permalink
refactor: support multiple bar items only displaying 1 marker in a mo…
Browse files Browse the repository at this point in the history
…re generic way
  • Loading branch information
ryantan committed Jul 8, 2021
1 parent f0fc757 commit c5b01e2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,36 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
isDrawMarkersEnabled,
valuesToHighlight()
else { return }


// Find unique data indexes.
var uniqueIndices: [Int] = []

for highlight in highlighted {
if uniqueIndices.contains(highlight.dataIndex) {
continue
}

uniqueIndices.append(highlight.dataIndex)
}

for highlight in highlighted
// Find tallest items given each data index.
var filteredHighlighted: [Highlight] = []
for index in uniqueIndices {
let itemsWithSameIndex = highlighted.filter { $0.dataIndex == index }

var drawYMax: CGFloat = 1000.0
var tallestItem = itemsWithSameIndex[0]
for item in itemsWithSameIndex {
if item.drawY < drawYMax {
drawYMax = item.drawY
tallestItem = item
}
}
filteredHighlighted.append(tallestItem)
}

for highlight in filteredHighlighted
{
guard
let set = data?[highlight.dataSetIndex],
Expand Down

0 comments on commit c5b01e2

Please sign in to comment.