Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
PNChart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
klauslanza
2014-08-14 13:26:28 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
afbe58027e947d8377a930173023e3c3a742c650
afbe5802
1 parent
fbd86a1d
fix labels when all same value
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
PNChart/PNLineChart.m
PNChart/PNLineChart.m
View file @
afbe580
...
...
@@ -66,16 +66,28 @@
{
CGFloat
yStep
=
(
_yValueMax
-
_yValueMin
)
/
_yLabelNum
;
CGFloat
yStepHeight
=
_chartCavanHeight
/
_yLabelNum
;
NSString
*
yLabelFormat
=
self
.
yLabelFormat
?:
@"%1.f"
;
if
(
_showLabel
)
{
if
(
yStep
==
0
.
0
)
{
PNChartLabel
*
minLabel
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
.
0
,
_chartCavanHeight
,
_chartMargin
,
_yLabelHeight
)];
minLabel
.
text
=
[
NSString
stringWithFormat
:
yLabelFormat
,
0
.
0
];
[
self
addSubview
:
minLabel
];
PNChartLabel
*
midLabel
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
.
0
,
_chartCavanHeight
/
2
,
_chartMargin
,
_yLabelHeight
)];
midLabel
.
text
=
[
NSString
stringWithFormat
:
yLabelFormat
,
_yValueMax
];
[
self
addSubview
:
midLabel
];
PNChartLabel
*
maxLabel
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
.
0
,
0
.
0
,
_chartMargin
,
_yLabelHeight
)];
maxLabel
.
text
=
[
NSString
stringWithFormat
:
yLabelFormat
,
_yValueMax
*
2
];
[
self
addSubview
:
maxLabel
];
}
else
{
NSInteger
index
=
0
;
NSInteger
num
=
_yLabelNum
+
1
;
while
(
num
>
0
)
{
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
.
0
,
(
_chartCavanHeight
-
index
*
yStepHeight
),
_chartMargin
,
_yLabelHeight
)];
[
label
setTextAlignment
:
NSTextAlignmentRight
];
NSString
*
yLabelFormat
=
self
.
yLabelFormat
?
self
.
yLabelFormat
:
@"%1.f"
;
label
.
text
=
[
NSString
stringWithFormat
:
yLabelFormat
,
_yValueMin
+
(
yStep
*
index
)];
[
self
addSubview
:
label
];
index
+=
1
;
...
...
@@ -227,7 +239,11 @@
yValue
=
chartData
.
getData
(
i
).
y
;
if
(
!
(
_yValueMax
-
_yValueMin
))
{
innerGrade
=
0
.
5
;
}
else
{
innerGrade
=
(
yValue
-
_yValueMin
)
/
(
_yValueMax
-
_yValueMin
);
}
int
x
=
2
*
_chartMargin
+
(
i
*
_xLabelWidth
);
int
y
=
_chartCavanHeight
-
(
innerGrade
*
_chartCavanHeight
)
+
(
_yLabelHeight
/
2
);
...
...
@@ -310,7 +326,6 @@
// setup the color of the chart line
if
(
chartData
.
color
)
{
chartLine
.
strokeColor
=
[
chartData
.
color
CGColor
];
pointLayer
.
strokeColor
=
[
chartData
.
color
CGColor
];
}
else
{
chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
...
...
Please
register
or
login
to post a comment