Skip to content

Commit 3f78850

Browse files
committed
CGPoint is more appropriate here
1 parent 35875d5 commit 3f78850

File tree

10 files changed

+26
-18
lines changed

10 files changed

+26
-18
lines changed

ChartsDemo/Classes/Demos/BubbleChartViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (void)setDataCount:(int)count range:(double)range
119119
[set1 setColor:ChartColorTemplates.colorful[0] alpha:0.50f];
120120
[set1 setDrawValuesEnabled:YES];
121121
BubbleChartDataSet *set2 = [[BubbleChartDataSet alloc] initWithValues:yVals2 label:@"DS 2"];
122-
set1.iconsOffset = CGSizeMake(0, 15);
122+
set1.iconsOffset = CGPointMake(0, 15);
123123
[set2 setColor:ChartColorTemplates.colorful[1] alpha:0.50f];
124124
[set2 setDrawValuesEnabled:YES];
125125
BubbleChartDataSet *set3 = [[BubbleChartDataSet alloc] initWithValues:yVals3 label:@"DS 3"];

ChartsDemo/Classes/Demos/PieChartViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ - (void)setDataCount:(int)count range:(double)range
9999

100100
PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithValues:values label:@"Election Results"];
101101
dataSet.sliceSpace = 2.0;
102-
dataSet.iconsOffset = CGSizeMake(0, 40);
102+
dataSet.iconsOffset = CGPointMake(0, 40);
103103

104104
// add a lot of colors
105105

Source/Charts/Data/Implementations/ChartBaseDataSet.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,12 @@ open class ChartBaseDataSet: NSObject, IChartDataSet
370370
return drawIconsEnabled
371371
}
372372

373-
/// Offset of icons drawn on the chart. For all charts except Pie and Radar it will be ordinary (x offset,y offset). For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase width component of CGSize, and if you want icon to be rendered closet to center, you should decrease height component of CGSize.
374-
open var iconsOffset = CGSize(width: 0,height: 0)
373+
/// Offset of icons drawn on the chart.
374+
///
375+
/// For all charts except Pie and Radar it will be ordinary (x offset,y offset).
376+
///
377+
/// For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase X component of CGPoint, and if you want icon to be rendered closet to center, you should decrease height component of CGPoint.
378+
open var iconsOffset = CGPoint(x: 0, y: 0)
375379

376380
/// Set the visibility of this DataSet. If not visible, the DataSet will not be drawn to the chart upon refreshing it.
377381
open var visible = true

Source/Charts/Data/Interfaces/IChartDataSet.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,12 @@ public protocol IChartDataSet
241241
/// Returns true if y-icon drawing is enabled, false if not
242242
var isDrawIconsEnabled: Bool { get }
243243

244-
/// Offset of icons drawn on the chart. For all charts except Pie and Radar it will be ordinary (x offset,y offset). For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase width component of CGSize, and if you want icon to be rendered closet to center, you should decrease height component of CGSize.
245-
var iconsOffset: CGSize { get set }
244+
/// Offset of icons drawn on the chart.
245+
///
246+
/// For all charts except Pie and Radar it will be ordinary (x offset,y offset).
247+
///
248+
/// For Pie and Radar chart it will be (y offset, distance from center offset); so if you want icon to be rendered under value, you should increase X component of CGPoint, and if you want icon to be rendered closet to center, you should decrease height component of CGPoint.
249+
var iconsOffset: CGPoint { get set }
246250

247251
/// Set the visibility of this DataSet. If not visible, the DataSet will not be drawn to the chart upon refreshing it.
248252
var visible: Bool { get set }

Source/Charts/Renderers/BarChartRenderer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
604604
}
605605

606606
/// Draws an icon at the specified x and y position.
607-
open func drawIcon(context: CGContext, icon: NSUIImage?, xPos: CGFloat, yPos: CGFloat, offset: CGSize)
607+
open func drawIcon(context: CGContext, icon: NSUIImage?, xPos: CGFloat, yPos: CGFloat, offset: CGPoint)
608608
{
609609
let point = CGPoint(x: xPos, y: yPos)
610610
if let iconImage = icon

Source/Charts/Renderers/PieChartRenderer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,14 @@ open class PieChartRenderer: DataRenderer
532532
{
533533
// calculate the icon's position
534534

535-
let x = (labelRadius + dataSet.iconsOffset.height) * sliceXBase + center.x
536-
let y = (labelRadius + dataSet.iconsOffset.height) * sliceYBase + center.y
535+
let x = (labelRadius + dataSet.iconsOffset.y) * sliceXBase + center.x
536+
let y = (labelRadius + dataSet.iconsOffset.y) * sliceYBase + center.y
537537

538538
ChartUtils.drawImage(context: context,
539539
image: icon,
540-
point: CGPoint(x:x, y:y),
540+
point: CGPoint(x: x, y: y),
541541
expectedSize: icon.size,
542-
offset: CGSize(width: 0, height: dataSet.iconsOffset.width))
542+
offset: CGPoint(x: 0, y: dataSet.iconsOffset.x))
543543
}
544544

545545
xIndex += 1

Source/Charts/Renderers/RadarChartRenderer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ open class RadarChartRenderer: LineRadarRenderer
201201
{
202202
let pIcon = ChartUtils.getPosition(
203203
center: center,
204-
dist: CGFloat(e.y) * factor * CGFloat(phaseY) + dataSet.iconsOffset.height,
204+
dist: CGFloat(e.y) * factor * CGFloat(phaseY) + dataSet.iconsOffset.y,
205205
angle: sliceangle * CGFloat(j) * CGFloat(phaseX) + chart.rotationAngle)
206206

207207
ChartUtils.drawImage(context: context,
208208
image: icon,
209209
point: pIcon,
210210
expectedSize: icon.size,
211-
offset: CGSize(width: 0, height: dataSet.iconsOffset.width))
211+
offset: CGPoint(x: 0, y: dataSet.iconsOffset.x))
212212
}
213213

214214
}

Source/Charts/Utils/ChartUtils.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ open class ChartUtils
8080
)
8181
}
8282

83-
open class func drawImage(context: CGContext, image: NSUIImage, point: CGPoint, expectedSize: CGSize, offset: CGSize)
83+
open class func drawImage(context: CGContext, image: NSUIImage, point: CGPoint, expectedSize: CGSize, offset: CGPoint)
8484
{
8585
var drawOffset = CGPoint()
86-
drawOffset.x += point.x + offset.width
86+
drawOffset.x += point.x + offset.x
8787
drawOffset.x -= expectedSize.width / 2
88-
drawOffset.y += point.y + offset.height
88+
drawOffset.y += point.y + offset.y
8989
drawOffset.y -= expectedSize.height / 2
9090

9191
NSUIGraphicsPushContext(context)

Tests/Charts/BarChartTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BarChartTests: FBSnapshotTestCase
2929

3030
dataSet = BarChartDataSet(values: entries, label: "Bar chart unit test data")
3131
dataSet.drawIconsEnabled = false
32-
dataSet.iconsOffset = CGSize(width: 0, height: -10.0)
32+
dataSet.iconsOffset = CGPoint(x: 0, y: -10.0)
3333

3434
let data = BarChartData(dataSet: dataSet)
3535
data.barWidth = 0.85

Tests/Charts/LineChartTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LineChartTests: FBSnapshotTestCase
2929

3030
dataSet = LineChartDataSet(values: entries, label: "First unit test data")
3131
dataSet.drawIconsEnabled = false
32-
dataSet.iconsOffset = CGSize(width: 0, height: 20.0)
32+
dataSet.iconsOffset = CGPoint(x: 0, y: 20.0)
3333

3434
chart = LineChartView(frame: CGRect(x: 0, y: 0, width: 480, height: 350))
3535
chart.backgroundColor = NSUIColor.clear

0 commit comments

Comments
 (0)