Skip to content

Commit

Permalink
Better popup value display
Browse files Browse the repository at this point in the history
The value popup now shows both the x and y coordinates
  • Loading branch information
Alejandro Isaza committed May 17, 2016
1 parent c70c8aa commit e25cc33
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PlotKit/Views/DataView.swift
Expand Up @@ -22,7 +22,7 @@ public class DataView: NSView {
}

/// Return the data value at the specified location in the view or `nil` if there is no data point at that location
public func valueAt(location: NSPoint) -> Double? {
public func pointAt(location: NSPoint) -> Point? {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions PlotKit/Views/HeatMapView.swift
Expand Up @@ -97,8 +97,8 @@ public class HeatMapView: DataView {
CGContextDrawImage(NSGraphicsContext.currentContext()?.CGContext, rect, image)
}

public override func valueAt(location: NSPoint) -> Double? {
public override func pointAt(location: NSPoint) -> Point? {
let point = convertViewPointToData(location)
return valueFunction?(x: point.x, y: point.y)
return Point(x: point.x, y: valueFunction?(x: point.x, y: point.y) ?? 0)
}
}
4 changes: 2 additions & 2 deletions PlotKit/Views/PlotView.swift
Expand Up @@ -259,8 +259,8 @@ public class PlotView: NSView {

for (view, title) in zip(dataViews, dataTitles) {
let loc = view.convertPoint(location, fromView: self)
if let value = view.valueAt(loc) {
valueView.stringValue = "\(title) - \(value)"
if let point = view.pointAt(loc) {
valueView.stringValue = String(format: "\(title) (%f, %f)", point.x, point.y)
valueView.hidden = false
valueView.sizeToFit()
var frame = valueView.frame
Expand Down
8 changes: 4 additions & 4 deletions PlotKit/Views/PointSetView.swift
Expand Up @@ -35,18 +35,18 @@ public class PointSetView: DataView {
self.yInterval = yInterval
}

public override func valueAt(location: NSPoint) -> Double? {
public override func pointAt(location: NSPoint) -> Point? {
var minDistance = CGFloat.max
var minValue = Double?()
var minPoint = Point?()
for point in pointSet.points {
let viewPoint = convertDataPointToView(point)
let d = hypot(location.x - viewPoint.x, location.y - viewPoint.y)
if d < 8 && d < minDistance {
minDistance = d
minValue = point.y
minPoint = point
}
}
return minValue
return minPoint
}

public override func drawRect(rect: CGRect) {
Expand Down

0 comments on commit e25cc33

Please sign in to comment.