Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
c3-closed
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
charts
c3-closed
Commits
7ba10e29
Commit
7ba10e29
authored
Aug 18, 2016
by
Evgeny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve algorithm for axis rotated
parent
f1bdcfbe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
18 deletions
+72
-18
c3.js
c3.js
+36
-9
c3.min.js
c3.min.js
+0
-0
axis.js
src/axis.js
+31
-8
core.js
src/core.js
+4
-0
size.js
src/size.js
+1
-1
No files found.
c3.js
View file @
7ba10e29
...
@@ -1121,6 +1121,10 @@
...
@@ -1121,6 +1121,10 @@
return
undefined
;
return
undefined
;
};
};
c3_chart_internal_fn
.
rotateCoeff
=
function
(
x
){
return
Math
.
abs
(
Math
.
sin
(
Math
.
PI
*
x
/
180
));
};
c3_chart_internal_fn
.
getDefaultConfig
=
function
()
{
c3_chart_internal_fn
.
getDefaultConfig
=
function
()
{
var
config
=
{
var
config
=
{
bindto
:
'#chart'
,
bindto
:
'#chart'
,
...
@@ -2821,7 +2825,7 @@
...
@@ -2821,7 +2825,7 @@
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
// Calculate x axis height when tick rotated
// Calculate x axis height when tick rotated
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
Math
.
sin
(
Math
.
PI
*
Math
.
abs
(
config
.
axis_x_tick_rotate
)
/
180
)
+
45
;
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
$$
.
rotateCoeff
(
config
.
axis_x_tick_rotate
)
+
45
;
}
}
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
10
:
15
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
10
:
15
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
};
};
...
@@ -4931,7 +4935,7 @@
...
@@ -4931,7 +4935,7 @@
};
};
c3_chart_internal_fn
.
xForRotatedTickText
=
function
(
r
)
{
c3_chart_internal_fn
.
xForRotatedTickText
=
function
(
r
)
{
return
8
*
Math
.
sin
(
Math
.
PI
*
(
r
/
180
)
);
return
8
*
Math
.
sin
(
Math
.
PI
*
r
/
180
);
};
};
c3_chart_internal_fn
.
yForRotatedTickText
=
function
(
r
)
{
c3_chart_internal_fn
.
yForRotatedTickText
=
function
(
r
)
{
return
11.5
-
2.5
*
(
r
/
15
)
*
(
r
>
0
?
1
:
-
1
);
return
11.5
-
2.5
*
(
r
/
15
)
*
(
r
>
0
?
1
:
-
1
);
...
@@ -5116,19 +5120,42 @@
...
@@ -5116,19 +5120,42 @@
c3_chart_internal_fn
.
getMaxTickWidthAllowed
=
function
(){
c3_chart_internal_fn
.
getMaxTickWidthAllowed
=
function
(){
var
$$
=
this
;
var
$$
=
this
;
var
widthCoef
,
heightCoef
;
var
sizeCoef
,
ticksCoef
;
sizeCoef
=
$$
.
getSizeCoef
();
ticksCoef
=
$$
.
getTicksCoef
();
return
Math
.
max
(
sizeCoef
,
ticksCoef
);
};
c3_chart_internal_fn
.
getTicksCoef
=
function
(){
var
$$
=
this
;
var
widthPadding
=
0
;
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticksNum
=
ticks
.
length
;
var
ticksNum
=
ticks
.
length
;
widthCoef
=
width
/
ticksNum
+
widthPadding
;
var
heightPadding
=
-
30
;
if
(
$$
.
config
.
axis_rotated
){
var
height
=
$$
.
getCurrentHeight
()
-
$$
.
margin
.
top
-
$$
.
margin
.
bottom
;
return
height
/
ticksNum
;
}
else
{
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
return
width
/
ticksNum
;
}
};
c3_chart_internal_fn
.
getSizeCoef
=
function
(){
var
$$
=
this
;
// Excel shortens ticks the way so they don't take more than half of all chart
// Excel shortens ticks the way so they don't take more than half of all chart
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
if
(
$$
.
config
.
axis_rotated
){
var
widthPadding
=
-
30
;
return
$$
.
getCurrentWidth
()
/
2
+
widthPadding
;
}
else
{
var
heightPadding
=
-
30
;
return
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
}
return
Math
.
max
(
widthCoef
,
heightCoef
);
};
};
c3_chart_internal_fn
.
tuneAxis
=
function
(
sync
,
callback
){
c3_chart_internal_fn
.
tuneAxis
=
function
(
sync
,
callback
){
...
...
c3.min.js
View file @
7ba10e29
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/axis.js
View file @
7ba10e29
...
@@ -304,7 +304,7 @@ c3_chart_internal_fn.textAnchorForY2AxisLabel = function () {
...
@@ -304,7 +304,7 @@ c3_chart_internal_fn.textAnchorForY2AxisLabel = function () {
};
};
c3_chart_internal_fn
.
xForRotatedTickText
=
function
(
r
)
{
c3_chart_internal_fn
.
xForRotatedTickText
=
function
(
r
)
{
return
8
*
Math
.
sin
(
Math
.
PI
*
(
r
/
180
)
);
return
8
*
Math
.
sin
(
Math
.
PI
*
r
/
180
);
};
};
c3_chart_internal_fn
.
yForRotatedTickText
=
function
(
r
)
{
c3_chart_internal_fn
.
yForRotatedTickText
=
function
(
r
)
{
return
11.5
-
2.5
*
(
r
/
15
)
*
(
r
>
0
?
1
:
-
1
);
return
11.5
-
2.5
*
(
r
/
15
)
*
(
r
>
0
?
1
:
-
1
);
...
@@ -489,19 +489,42 @@ c3_chart_internal_fn.tuneAxisTicks = function(){
...
@@ -489,19 +489,42 @@ c3_chart_internal_fn.tuneAxisTicks = function(){
c3_chart_internal_fn
.
getMaxTickWidthAllowed
=
function
(){
c3_chart_internal_fn
.
getMaxTickWidthAllowed
=
function
(){
var
$$
=
this
;
var
$$
=
this
;
var
widthCoef
,
heightCoef
;
var
sizeCoef
,
ticksCoef
;
sizeCoef
=
$$
.
getSizeCoef
();
ticksCoef
=
$$
.
getTicksCoef
();
return
Math
.
max
(
sizeCoef
,
ticksCoef
);
};
c3_chart_internal_fn
.
getTicksCoef
=
function
(){
var
$$
=
this
;
var
widthPadding
=
0
;
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticksNum
=
ticks
.
length
;
var
ticksNum
=
ticks
.
length
;
widthCoef
=
width
/
ticksNum
+
widthPadding
;
var
heightPadding
=
-
30
;
if
(
$$
.
config
.
axis_rotated
){
var
height
=
$$
.
getCurrentHeight
()
-
$$
.
margin
.
top
-
$$
.
margin
.
bottom
;
return
height
/
ticksNum
;
}
else
{
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
return
width
/
ticksNum
;
}
};
c3_chart_internal_fn
.
getSizeCoef
=
function
(){
var
$$
=
this
;
// Excel shortens ticks the way so they don't take more than half of all chart
// Excel shortens ticks the way so they don't take more than half of all chart
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
if
(
$$
.
config
.
axis_rotated
){
var
widthPadding
=
-
30
;
return
$$
.
getCurrentWidth
()
/
2
+
widthPadding
;
}
else
{
var
heightPadding
=
-
30
;
return
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
}
return
Math
.
max
(
widthCoef
,
heightCoef
);
};
};
c3_chart_internal_fn
.
tuneAxis
=
function
(
sync
,
callback
){
c3_chart_internal_fn
.
tuneAxis
=
function
(
sync
,
callback
){
...
...
src/core.js
View file @
7ba10e29
...
@@ -1115,3 +1115,7 @@ c3_chart_internal_fn.updateValue = function(d){
...
@@ -1115,3 +1115,7 @@ c3_chart_internal_fn.updateValue = function(d){
}
}
return
undefined
;
return
undefined
;
};
};
c3_chart_internal_fn
.
rotateCoeff
=
function
(
x
){
return
Math
.
abs
(
Math
.
sin
(
Math
.
PI
*
x
/
180
));
};
src/size.js
View file @
7ba10e29
...
@@ -86,7 +86,7 @@ c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) {
...
@@ -86,7 +86,7 @@ c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) {
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
// Calculate x axis height when tick rotated
// Calculate x axis height when tick rotated
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
Math
.
sin
(
Math
.
PI
*
Math
.
abs
(
config
.
axis_x_tick_rotate
)
/
180
)
+
45
;
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
$$
.
rotateCoeff
(
config
.
axis_x_tick_rotate
)
+
45
;
}
}
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
10
:
15
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
10
:
15
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment