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
Evgeny
c3-closed
Commits
aa780edb
Commit
aa780edb
authored
Nov 03, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate x axis height when tick rotated - #634
parent
b3c739ee
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
14 deletions
+74
-14
c3.js
c3.js
+14
-7
c3.min.js
c3.min.js
+0
-0
axis-spec.js
spec/axis-spec.js
+46
-0
axis.js
src/axis.js
+2
-2
clip.js
src/clip.js
+1
-2
core.js
src/core.js
+5
-1
size.js
src/size.js
+6
-2
No files found.
c3.js
View file @
aa780edb
...
...
@@ -124,7 +124,11 @@
$$
.
legendItemHeight
=
0
;
$$
.
legendOpacityForHidden
=
0.15
;
$$
.
currentMaxTickWidth
=
0
;
$$
.
currentMaxTickWidths
=
{
x
:
0
,
y
:
0
,
y2
:
0
};
$$
.
rotated_padding_left
=
30
;
$$
.
rotated_padding_right
=
config
.
axis_rotated
&&
!
config
.
axis_x_show
?
0
:
30
;
...
...
@@ -2469,12 +2473,16 @@
return
position
.
isInner
?
20
+
$$
.
getMaxTickWidth
(
id
)
:
40
+
$$
.
getMaxTickWidth
(
id
);
};
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
var
$$
=
this
,
config
=
$$
.
config
;
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
if
(
axisId
===
'x'
&&
!
config
.
axis_x_show
)
{
return
8
;
}
if
(
axisId
===
'x'
&&
config
.
axis_x_height
)
{
return
config
.
axis_x_height
;
}
if
(
axisId
===
'y'
&&
!
config
.
axis_y_show
)
{
return
config
.
legend_show
&&
!
$$
.
isLegendRight
&&
!
$$
.
isLegendInset
?
10
:
1
;
}
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
return
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
30
:
40
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
// Calculate x axis height when tick rotated
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
Math
.
cos
(
Math
.
PI
*
(
90
-
config
.
axis_x_tick_rotate
)
/
180
);
}
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
0
:
10
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
};
c3_chart_internal_fn
.
getEventRectWidth
=
function
()
{
...
...
@@ -4147,8 +4155,8 @@
});
}).
remove
();
}
$$
.
currentMaxTickWidth
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidth
:
maxWidth
;
return
$$
.
currentMaxTickWidth
;
$$
.
currentMaxTickWidth
s
[
id
]
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidths
[
id
]
:
maxWidth
;
return
$$
.
currentMaxTickWidth
s
[
id
]
;
};
c3_chart_internal_fn
.
updateAxisLabels
=
function
(
withTransition
)
{
...
...
@@ -4268,8 +4276,7 @@
return
forHorizontal
?
$$
.
width
+
2
+
left
+
right
:
$$
.
margin
.
left
+
20
;
};
c3_chart_internal_fn
.
getAxisClipHeight
=
function
(
forHorizontal
)
{
var
$$
=
this
,
config
=
$$
.
config
;
return
forHorizontal
?
(
config
.
axis_x_height
?
config
.
axis_x_height
:
0
)
+
80
:
$$
.
height
+
8
;
return
forHorizontal
?
this
.
margin
.
bottom
:
this
.
height
+
8
;
};
c3_chart_internal_fn
.
getXAxisClipWidth
=
function
()
{
var
$$
=
this
;
...
...
c3.min.js
View file @
aa780edb
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/axis-spec.js
View file @
aa780edb
...
...
@@ -441,4 +441,50 @@ describe('c3 chart axis', function () {
});
describe
(
'axis.x.tick.rotate'
,
function
()
{
describe
(
'not rotated'
,
function
()
{
it
(
'should update args successfully'
,
function
()
{
args
=
{
data
:
{
x
:
'x'
,
columns
:
[
[
'x'
,
'category 1'
,
'category 2'
,
'category 3'
,
'category 4'
,
'category 5'
,
'category 6'
],
[
'data1'
,
30
,
200
,
100
,
400
,
150
,
250
],
[
'data2'
,
50
,
20
,
10
,
40
,
15
,
25
]
]
},
axis
:
{
x
:
{
type
:
'category'
,
tick
:
{
rotate
:
60
}
}
}
};
expect
(
true
).
toBeTruthy
();
});
it
(
'should rotate tick texts'
,
function
()
{
chart
.
internal
.
main
.
selectAll
(
'.c3-axis-x g.tick'
).
each
(
function
()
{
var
tick
=
d3
.
select
(
this
),
text
=
tick
.
select
(
'text'
),
tspan
=
text
.
select
(
'tspan'
);
expect
(
text
.
attr
(
'transform'
)).
toBe
(
'rotate(60)'
);
expect
(
text
.
attr
(
'y'
)).
toBe
(
'1.5'
);
expect
(
tspan
.
attr
(
'dx'
)).
toBe
(
'6.928203230275509'
);
});
});
it
(
'should have automatically calculated x axis height'
,
function
()
{
var
box
=
chart
.
internal
.
main
.
select
(
'.c3-axis-x'
).
node
().
getBoundingClientRect
();
expect
(
box
.
height
).
toBeGreaterThan
(
50
);
});
});
});
});
src/axis.js
View file @
aa780edb
...
...
@@ -279,8 +279,8 @@ c3_chart_internal_fn.getMaxTickWidth = function (id) {
});
}).
remove
();
}
$$
.
currentMaxTickWidth
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidth
:
maxWidth
;
return
$$
.
currentMaxTickWidth
;
$$
.
currentMaxTickWidth
s
[
id
]
=
maxWidth
<=
0
?
$$
.
currentMaxTickWidths
[
id
]
:
maxWidth
;
return
$$
.
currentMaxTickWidth
s
[
id
]
;
};
c3_chart_internal_fn
.
updateAxisLabels
=
function
(
withTransition
)
{
...
...
src/clip.js
View file @
aa780edb
...
...
@@ -37,8 +37,7 @@ c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) {
return
forHorizontal
?
$$
.
width
+
2
+
left
+
right
:
$$
.
margin
.
left
+
20
;
};
c3_chart_internal_fn
.
getAxisClipHeight
=
function
(
forHorizontal
)
{
var
$$
=
this
,
config
=
$$
.
config
;
return
forHorizontal
?
(
config
.
axis_x_height
?
config
.
axis_x_height
:
0
)
+
80
:
$$
.
height
+
8
;
return
forHorizontal
?
this
.
margin
.
bottom
:
this
.
height
+
8
;
};
c3_chart_internal_fn
.
getXAxisClipWidth
=
function
()
{
var
$$
=
this
;
...
...
src/core.js
View file @
aa780edb
...
...
@@ -119,7 +119,11 @@ c3_chart_internal_fn.initParams = function () {
$$
.
legendItemHeight
=
0
;
$$
.
legendOpacityForHidden
=
0.15
;
$$
.
currentMaxTickWidth
=
0
;
$$
.
currentMaxTickWidths
=
{
x
:
0
,
y
:
0
,
y2
:
0
};
$$
.
rotated_padding_left
=
30
;
$$
.
rotated_padding_right
=
config
.
axis_rotated
&&
!
config
.
axis_x_show
?
0
:
30
;
...
...
src/size.js
View file @
aa780edb
...
...
@@ -74,12 +74,16 @@ c3_chart_internal_fn.getAxisWidthByAxisId = function (id) {
return
position
.
isInner
?
20
+
$$
.
getMaxTickWidth
(
id
)
:
40
+
$$
.
getMaxTickWidth
(
id
);
};
c3_chart_internal_fn
.
getHorizontalAxisHeight
=
function
(
axisId
)
{
var
$$
=
this
,
config
=
$$
.
config
;
var
$$
=
this
,
config
=
$$
.
config
,
h
=
30
;
if
(
axisId
===
'x'
&&
!
config
.
axis_x_show
)
{
return
8
;
}
if
(
axisId
===
'x'
&&
config
.
axis_x_height
)
{
return
config
.
axis_x_height
;
}
if
(
axisId
===
'y'
&&
!
config
.
axis_y_show
)
{
return
config
.
legend_show
&&
!
$$
.
isLegendRight
&&
!
$$
.
isLegendInset
?
10
:
1
;
}
if
(
axisId
===
'y2'
&&
!
config
.
axis_y2_show
)
{
return
$$
.
rotated_padding_top
;
}
return
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
30
:
40
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
// Calculate x axis height when tick rotated
if
(
axisId
===
'x'
&&
!
config
.
axis_rotated
&&
config
.
axis_x_tick_rotate
)
{
h
=
$$
.
getMaxTickWidth
(
axisId
)
*
Math
.
cos
(
Math
.
PI
*
(
90
-
config
.
axis_x_tick_rotate
)
/
180
);
}
return
h
+
(
$$
.
getAxisLabelPositionById
(
axisId
).
isInner
?
0
:
10
)
+
(
axisId
===
'y2'
?
-
10
:
0
);
};
c3_chart_internal_fn
.
getEventRectWidth
=
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