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
f1bdcfbe
Commit
f1bdcfbe
authored
Aug 18, 2016
by
Evgeny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stable version of ticks rotation
parent
949e1951
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
54 deletions
+66
-54
c3.js
c3.js
+33
-27
c3.min.js
c3.min.js
+0
-0
axis.js
src/axis.js
+26
-25
core.js
src/core.js
+7
-2
No files found.
c3.js
View file @
f1bdcfbe
...
...
@@ -796,16 +796,21 @@
false
;
// MEMO: this needs to be called before updateLegend and it means this ALWAYS needs to be called)
$$
.
updateSizes
();
transitions
=
$$
.
generateAxisTransitions
(
options
.
withTransitionForAxis
?
config
.
transition_duration
:
0
);
// MEMO: called in updateLegend in redraw if withLegend
if
(
!
(
options
.
withLegend
&&
config
.
legend_show
))
{
transitions
=
$$
.
generateAxisTransitions
(
options
.
withTransitionForAxis
?
config
.
transition_duration
:
0
);
// Update scales
$$
.
updateScales
();
$$
.
updateSvgSize
();
// Update g positions
$$
.
transformAll
(
options
.
withTransitionForTransform
,
transitions
);
}
// Draw with new sizes & scales
$$
.
redrawAxis
(
transitions
);
// MEMO: Draw with new sizes & scales
$$
.
updateScales
();
$$
.
updateSvgSize
();
$$
.
redraw
(
options
,
transitions
);
};
c3_chart_internal_fn
.
redrawWithoutRescale
=
function
()
{
...
...
@@ -4952,32 +4957,28 @@
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
)
{
var
$$
=
this
;
if
(
$$
.
config
.
maxTickTextWidth
[
id
]){
return
$$
.
config
.
maxTickTextWidth
[
id
]
+
(
$$
.
config
.
tick_text_padding
||
0
);
}
if
(
id
===
'x'
){
var
ticks
=
$$
.
getXAxisTickValues
();
var
ticks
=
$$
.
getXAxisTickValues
();
if
(
ticks
){
var
m
=
0
;
if
(
ticks
){
var
m
=
0
;
if
(
$$
.
config
.
axis_x_tick_format
){
ticks
=
ticks
.
map
(
$$
.
config
.
axis_x_tick_format
);
}
if
(
$$
.
config
.
axis_x_tick_format
){
ticks
=
ticks
.
map
(
$$
.
config
.
axis_x_tick_format
);
}
ticks
=
ticks
.
map
(
$$
.
shorten
.
bind
(
$$
));
ticks
=
ticks
.
map
(
$$
.
shorten
.
bind
(
$$
));
ticks
.
forEach
(
function
(
tick
){
m
=
Math
.
max
(
m
,
tick
.
toString
().
length
);
});
ticks
.
forEach
(
function
(
tick
){
m
=
Math
.
max
(
m
,
tick
.
toString
().
length
);
});
return
m
*
11.5
;
return
m
*
5.5
;
}
}
if
(
!
$$
.
config
.
axis_rotated
){
if
(
$$
.
config
.
axis_x_tick_rotate
!==
0
){
return
$$
.
getMaxTickWidthAllowed
();
}
if
(
$$
.
config
.
maxTickTextWidth
[
id
]){
return
$$
.
config
.
maxTickTextWidth
[
id
]
+
(
$$
.
config
.
tick_text_padding
||
0
);
}
return
$$
.
config
.
maxTickTextWidth
.
default
;
...
...
@@ -5076,6 +5077,10 @@
$$
.
rotateTickText
(
$$
.
axes
.
x
,
transitions
.
axisX
,
config
.
axis_x_tick_rotate
);
$$
.
rotateTickText
(
$$
.
axes
.
subx
,
transitions
.
axisSubX
,
config
.
axis_x_tick_rotate
);
}
//$$.updateSizes();
//$$.updateScales();
//$$.updateSvgSize();
};
c3_chart_internal_fn
.
tuneAxisTicks
=
function
(){
...
...
@@ -5097,7 +5102,7 @@
}
// No overlapping for rotation 45
if
(
45
<
widthForTick
){
if
(
maxTickWidth
/
Math
.
sqrt
(
2
)
<
widthForTick
){
$$
.
config
.
axis_x_tick_rotate
=
-
45
;
return
;
}
...
...
@@ -5113,14 +5118,15 @@
var
$$
=
this
;
var
widthCoef
,
heightCoef
;
var
width
=
$$
.
getCurrentWidth
();
var
widthPadding
=
0
;
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticksNum
=
ticks
.
length
;
widthCoef
=
width
/
ticksNum
;
widthCoef
=
width
/
ticksNum
+
widthPadding
;
var
heightPadding
=
-
30
;
// Excel shortens ticks the way so they don't take more than half of all chart
var
padding
=
-
10
;
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
padding
;
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
return
Math
.
max
(
widthCoef
,
heightCoef
);
};
...
...
@@ -5322,7 +5328,7 @@
text
=
text
.
toString
();
var
maxTicks
=
$$
.
getMaxTickWidthAllowed
()
/
11
.5
;
var
maxTicks
=
$$
.
getMaxTickWidthAllowed
()
/
7
.5
;
if
(
text
.
length
<=
maxTicks
){
return
text
;
...
...
c3.min.js
View file @
f1bdcfbe
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/axis.js
View file @
f1bdcfbe
...
...
@@ -330,32 +330,28 @@ c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) {
c3_chart_internal_fn
.
getMaxTickWidth
=
function
(
id
)
{
var
$$
=
this
;
if
(
$$
.
config
.
maxTickTextWidth
[
id
]){
return
$$
.
config
.
maxTickTextWidth
[
id
]
+
(
$$
.
config
.
tick_text_padding
||
0
);
}
var
ticks
=
$$
.
getXAxisTickValues
();
if
(
id
===
'x'
){
var
ticks
=
$$
.
getXAxisTickValues
();
if
(
ticks
){
var
m
=
0
;
if
(
ticks
){
var
m
=
0
;
if
(
$$
.
config
.
axis_x_tick_format
){
ticks
=
ticks
.
map
(
$$
.
config
.
axis_x_tick_format
);
}
if
(
$$
.
config
.
axis_x_tick_format
){
ticks
=
ticks
.
map
(
$$
.
config
.
axis_x_tick_format
);
}
ticks
=
ticks
.
map
(
$$
.
shorten
.
bind
(
$$
));
ticks
=
ticks
.
map
(
$$
.
shorten
.
bind
(
$$
));
ticks
.
forEach
(
function
(
tick
){
m
=
Math
.
max
(
m
,
tick
.
toString
().
length
);
});
ticks
.
forEach
(
function
(
tick
){
m
=
Math
.
max
(
m
,
tick
.
toString
().
length
);
});
return
m
*
11.5
;
return
m
*
5.5
;
}
}
if
(
!
$$
.
config
.
axis_rotated
){
if
(
$$
.
config
.
axis_x_tick_rotate
!==
0
){
return
$$
.
getMaxTickWidthAllowed
();
}
if
(
$$
.
config
.
maxTickTextWidth
[
id
]){
return
$$
.
config
.
maxTickTextWidth
[
id
]
+
(
$$
.
config
.
tick_text_padding
||
0
);
}
return
$$
.
config
.
maxTickTextWidth
.
default
;
...
...
@@ -454,6 +450,10 @@ c3_chart_internal_fn.redrawAxis = function (transitions, isHidden) {
$$
.
rotateTickText
(
$$
.
axes
.
x
,
transitions
.
axisX
,
config
.
axis_x_tick_rotate
);
$$
.
rotateTickText
(
$$
.
axes
.
subx
,
transitions
.
axisSubX
,
config
.
axis_x_tick_rotate
);
}
//$$.updateSizes();
//$$.updateScales();
//$$.updateSvgSize();
};
c3_chart_internal_fn
.
tuneAxisTicks
=
function
(){
...
...
@@ -475,7 +475,7 @@ c3_chart_internal_fn.tuneAxisTicks = function(){
}
// No overlapping for rotation 45
if
(
45
<
widthForTick
){
if
(
maxTickWidth
/
Math
.
sqrt
(
2
)
<
widthForTick
){
$$
.
config
.
axis_x_tick_rotate
=
-
45
;
return
;
}
...
...
@@ -491,14 +491,15 @@ c3_chart_internal_fn.getMaxTickWidthAllowed = function(){
var
$$
=
this
;
var
widthCoef
,
heightCoef
;
var
width
=
$$
.
getCurrentWidth
();
var
widthPadding
=
0
;
var
width
=
$$
.
getCurrentWidth
()
-
$$
.
margin
.
left
-
$$
.
margin
.
right
;
var
ticks
=
$$
.
getXAxisTickValues
()
||
[];
var
ticksNum
=
ticks
.
length
;
widthCoef
=
width
/
ticksNum
;
widthCoef
=
width
/
ticksNum
+
widthPadding
;
var
heightPadding
=
-
30
;
// Excel shortens ticks the way so they don't take more than half of all chart
var
padding
=
-
10
;
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
padding
;
heightCoef
=
$$
.
getCurrentHeight
()
/
2
+
heightPadding
;
return
Math
.
max
(
widthCoef
,
heightCoef
);
};
...
...
@@ -700,7 +701,7 @@ c3_chart_internal_fn.shorten = function(text){
text
=
text
.
toString
();
var
maxTicks
=
$$
.
getMaxTickWidthAllowed
()
/
11
.5
;
var
maxTicks
=
$$
.
getMaxTickWidthAllowed
()
/
7
.5
;
if
(
text
.
length
<=
maxTicks
){
return
text
;
...
...
src/core.js
View file @
f1bdcfbe
...
...
@@ -791,16 +791,21 @@ c3_chart_internal_fn.updateAndRedraw = function (options) {
false
;
// MEMO: this needs to be called before updateLegend and it means this ALWAYS needs to be called)
$$
.
updateSizes
();
transitions
=
$$
.
generateAxisTransitions
(
options
.
withTransitionForAxis
?
config
.
transition_duration
:
0
);
// MEMO: called in updateLegend in redraw if withLegend
if
(
!
(
options
.
withLegend
&&
config
.
legend_show
))
{
transitions
=
$$
.
generateAxisTransitions
(
options
.
withTransitionForAxis
?
config
.
transition_duration
:
0
);
// Update scales
$$
.
updateScales
();
$$
.
updateSvgSize
();
// Update g positions
$$
.
transformAll
(
options
.
withTransitionForTransform
,
transitions
);
}
// Draw with new sizes & scales
$$
.
redrawAxis
(
transitions
);
// MEMO: Draw with new sizes & scales
$$
.
updateScales
();
$$
.
updateSvgSize
();
$$
.
redraw
(
options
,
transitions
);
};
c3_chart_internal_fn
.
redrawWithoutRescale
=
function
()
{
...
...
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