Skip to content

Commit

Permalink
Merge pull request ChartsOrg#2 from RedAirship/feature/show-one-marke…
Browse files Browse the repository at this point in the history
…r-refactored

refactor: support multiple bar items only displaying 1 marker in a mo…
  • Loading branch information
ryantan committed Jul 8, 2021
2 parents f0fc757 + c5b01e2 commit 8726b51
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 8726b51

Please sign in to comment.