Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resubmit of #2730 #3002

Merged
merged 5 commits into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
17E994DA88777AA1D8CCFC58 /* BarChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31AA65EA27776F8C653C7E8 /* BarChartDataSet.swift */; };
203A39685CC96FC625F616E4 /* IHighlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998F2BFE318471AFC05B50AC /* IHighlighter.swift */; };
219192CA6B4895319AB49DCA /* BarLineScatterCandleBubbleRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B1C588E9DF6FFD56D7ADF8E /* BarLineScatterCandleBubbleRenderer.swift */; };
224EFF991FBAAC4700CF9B3B /* EquatableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224EFF981FBAAC4700CF9B3B /* EquatableTests.swift */; };
23649EFC635A76022F07FFA6 /* PieChartDataEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */; };
23FA50B2730D8C7ACA091C4F /* BarChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F279974FE650E57A061B09 /* BarChartRenderer.swift */; };
24151B0729D77251A8494D70 /* LineRadarRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 105FFC9D3773A9C7A60A897F /* LineRadarRenderer.swift */; };
Expand Down Expand Up @@ -182,6 +183,7 @@
1F3D55A7E6176D52DC957D27 /* XAxisRendererHorizontalBarChart.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XAxisRendererHorizontalBarChart.swift; path = Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift; sourceTree = "<group>"; };
2194AA554712E6BA2677F114 /* BubbleChartRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = BubbleChartRenderer.swift; path = Source/Charts/Renderers/BubbleChartRenderer.swift; sourceTree = "<group>"; };
219BC9CEA037F897E92E45D1 /* IScatterChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = IScatterChartDataSet.swift; path = Source/Charts/Data/Interfaces/IScatterChartDataSet.swift; sourceTree = "<group>"; };
224EFF981FBAAC4700CF9B3B /* EquatableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EquatableTests.swift; path = Tests/Charts/EquatableTests.swift; sourceTree = "<group>"; };
23D35CF6F9177D77B6B97AE1 /* XShapeRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XShapeRenderer.swift; path = Source/Charts/Renderers/Scatter/XShapeRenderer.swift; sourceTree = "<group>"; };
2440DB759AB93B4A928A3F6F /* RadarChartView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = RadarChartView.swift; path = Source/Charts/Charts/RadarChartView.swift; sourceTree = "<group>"; };
2465CB73738EBAFB46C57288 /* CombinedHighlighter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = CombinedHighlighter.swift; path = Source/Charts/Highlight/CombinedHighlighter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -510,6 +512,7 @@
isa = PBXGroup;
children = (
5C3F5E1A69EC06E86505F7B1 /* BarChartTests.swift */,
224EFF981FBAAC4700CF9B3B /* EquatableTests.swift */,
7AB9062A28AAB9469752A954 /* ChartUtilsTests.swift */,
D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */,
064989451F5C99C7006E8BB3 /* Snapshot.swift */,
Expand Down Expand Up @@ -945,6 +948,7 @@
8E1192F7A7152E9DA92C56A9 /* ChartUtilsTests.swift in Sources */,
2BF85BEA981B359A65E9BF67 /* LineChartTests.swift in Sources */,
064989461F5C99C7006E8BB3 /* Snapshot.swift in Sources */,
224EFF991FBAAC4700CF9B3B /* EquatableTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 2 additions & 4 deletions Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

let h = getHighlightByTouchPoint(recognizer.location(in: self))

if h?.isEqual(lastHighlighted) ?? true
if h === nil || h == self.lastHighlighted
{
highlightValue(nil, callDelegate: true)
lastHighlighted = nil
Expand Down Expand Up @@ -748,9 +748,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

let lastHighlighted = self.lastHighlighted

if (h === nil && lastHighlighted !== nil) ||
(h !== nil && lastHighlighted === nil) ||
(lastHighlighted !== nil && !(h?.isEqual(lastHighlighted) ?? true))
if h != lastHighlighted
{
self.lastHighlighted = h
self.highlightValue(h, callDelegate: true)
Expand Down
57 changes: 13 additions & 44 deletions Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,7 @@ open class ChartDataEntry: ChartDataEntryBase

self.x = x
}

// MARK: NSObject

open override func isEqual(_ object: Any?) -> Bool
{
if !super.isEqual(object)
{
return false
}

if fabs((object! as AnyObject).x - x) > Double.ulpOfOne
{
return false
}

return true
}

// MARK: NSObject

open override var description: String
Expand All @@ -108,32 +91,18 @@ open class ChartDataEntry: ChartDataEntryBase
}
}

public func ==(lhs: ChartDataEntry, rhs: ChartDataEntry) -> Bool
{
if lhs === rhs
{
return true
}

if !lhs.isKind(of: type(of: rhs))
{
return false
}

if lhs.data !== rhs.data && !lhs.data!.isEqual(rhs.data)
{
return false
}

if fabs(lhs.x - rhs.x) > Double.ulpOfOne
{
return false
}

if fabs(lhs.y - rhs.y) > Double.ulpOfOne
{
return false
// MARK: Equatable
extension ChartDataEntry/*: Equatable*/ {
open override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? ChartDataEntry else { return false }

if self === object
{
return true
}

return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
&& y == object.y
&& x == object.x
}

return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,7 @@ open class ChartDataEntryBase: NSObject
self.icon = icon
self.data = data
}

// MARK: NSObject

open override func isEqual(_ object: Any?) -> Bool
{
if object == nil
{
return false
}

if !(object! as AnyObject).isKind(of: type(of: self))
{
return false
}

if (object! as AnyObject).data !== data && !((object! as AnyObject).data??.isEqual(self.data))!
{
return false
}

if fabs((object! as AnyObject).y - y) > Double.ulpOfOne
{
return false
}

return true
}


// MARK: NSObject

open override var description: String
Expand All @@ -106,27 +79,17 @@ open class ChartDataEntryBase: NSObject
}
}

public func ==(lhs: ChartDataEntryBase, rhs: ChartDataEntryBase) -> Bool
{
if lhs === rhs
{
return true
}

if !lhs.isKind(of: type(of: rhs))
{
return false
}

if lhs.data !== rhs.data && !lhs.data!.isEqual(rhs.data)
{
return false
}

if fabs(lhs.y - rhs.y) > Double.ulpOfOne
{
return false
// MARK: Equatable
extension ChartDataEntryBase/*: Equatable*/ {
open override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? ChartDataEntryBase else { return false }

if self === object
{
return true
}

return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
&& y == object.y
}

return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ open class ChartDataSet: ChartBaseDataSet
{
for entry in values
{
if (entry.isEqual(e))
if entry == e
{
return true
}
Expand Down
92 changes: 16 additions & 76 deletions Source/Charts/Highlight/Highlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,84 +174,24 @@ open class Highlight: NSObject
{
return "Highlight, x: \(_x), y: \(_y), dataIndex (combined charts): \(dataIndex), dataSetIndex: \(_dataSetIndex), stackIndex (only stacked barentry): \(_stackIndex)"
}

open override func isEqual(_ object: Any?) -> Bool
{
if object == nil
{
return false
}

if !(object! as AnyObject).isKind(of: type(of: self))
{
return false
}

if (object! as AnyObject).x != _x
{
return false
}

if (object! as AnyObject).y != _y
{
return false
}

if (object! as AnyObject).dataIndex != dataIndex
{
return false
}

if (object! as AnyObject).dataSetIndex != _dataSetIndex
{
return false
}

if (object! as AnyObject).stackIndex != _stackIndex
}


// MARK: Equatable
extension Highlight /*: Equatable*/ {
open override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? Highlight else { return false }

if self === object
{
return false
return true
}

return true
}
}

func ==(lhs: Highlight, rhs: Highlight) -> Bool
{
if lhs === rhs
{
return true
}

if !lhs.isKind(of: type(of: rhs))
{
return false
}

if lhs._x != rhs._x
{
return false
}

if lhs._y != rhs._y
{
return false
}

if lhs.dataIndex != rhs.dataIndex
{
return false
}

if lhs._dataSetIndex != rhs._dataSetIndex
{
return false
}

if lhs._stackIndex != rhs._stackIndex
{
return false
return _x == object._x
&& _y == object._y
&& dataIndex == object.dataIndex
&& _dataSetIndex == object._dataSetIndex
&& _stackIndex == object._stackIndex

}

return true
}
45 changes: 45 additions & 0 deletions Tests/Charts/EquatableTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// EquatableTests.swift
Copy link
Member

@liuxuan30 liuxuan30 Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the same template as yours for combined chart test. Shall we include the license info just like source code template, or test file is fine with default Xcode template?
The old test file does not have a template as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should be putting in the license info to be consistent. Do we keep it the same, but whose name do we use?

Copy link
Member

@liuxuan30 liuxuan30 Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use the same template as source code. I don't know the rule of names.
Personally I just use Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda, and I don't need to specify who created the file.
I think this is a good question, as I saw some files with yours template:

//
//  DemoBaseViewController.swift
//  ChartsDemo-iOS
//
//  Created by Jacob Christie on 2017-07-03.
//  Copyright © 2017 jc. All rights reserved.
//

I guess we need an unified one. @petester42 @danielgindi @PhilJay insights?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I just use the Xcode default.

// Charts
//
// Created by Jacob Christie on 2017-11-13.
//

import XCTest
@testable import Charts

class EquatableTests: XCTestCase {
func testChartDataEntryEquality() {
let image = UIImage()
let data = NSObject()
let entry1 = ChartDataEntry(x: 5, y: 3, icon: image, data: data)
let entry2 = ChartDataEntry(x: 5, y: 3, icon: image, data: data)

XCTAssertTrue(entry1 == entry2)
}

func testChartDataEntryInequality() {
let image = UIImage()
let data1 = NSObject()
let data2 = NSObject()
let entry1 = ChartDataEntry(x: 5, y: 3, icon: image, data: data1)
let entry2 = ChartDataEntry(x: 5, y: 3, icon: image, data: data2)

XCTAssertFalse(entry1 == entry2)
}

func testHighlightEquality() {
let high1 = Highlight(x: 5, y: 3, xPx: 1, yPx: -1, dataSetIndex: 8, stackIndex: 8, axis: .right)
let high2 = Highlight(x: 5, y: 3, xPx: 1, yPx: -1, dataSetIndex: 8, stackIndex: 8, axis: .right)

XCTAssertTrue(high1 == high2)
}

func testHighlightInequality() {
let high1 = Highlight(x: 5, y: 3, xPx: 1, yPx: -1, dataSetIndex: 8, stackIndex: 8, axis: .left)
let high2 = Highlight(x: 5, y: 3, xPx: 1, yPx: -1, dataSetIndex: 8, stackIndex: 9, axis: .left)

XCTAssertFalse(high1 == high2)
}
}