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
d8125d90
Commit
d8125d90
authored
Mar 16, 2016
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change text size calculation algorithm
parent
1a704760
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
47 deletions
+37
-47
c3.axis.js
src/c3.axis.js
+2
-26
config.js
src/config.js
+2
-1
core.js
src/core.js
+24
-0
legend.js
src/legend.js
+3
-1
text.js
src/text.js
+6
-19
No files found.
src/c3.axis.js
View file @
d8125d90
...
...
@@ -159,29 +159,6 @@ function c3_axis(d3, params, $$) {
var
tickPosition
=
scale
(
d
)
+
(
tickCentered
?
0
:
tickOffset
);
return
range
[
0
]
<
tickPosition
&&
tickPosition
<
range
[
1
]
?
innerTickSize
:
0
;
}
// Seek a specific value in the stylesheets of a document
function
getStyleValue
(
selector
,
property
)
{
var
css
,
rule
,
sheet
,
value
;
for
(
var
styleId
=
0
;
styleId
<
document
.
styleSheets
.
length
;
styleId
++
)
{
sheet
=
document
.
styleSheets
[
styleId
];
for
(
var
ruleId
=
0
;
ruleId
<
sheet
.
cssRules
.
length
;
ruleId
++
)
{
rule
=
sheet
.
cssRules
[
ruleId
];
css
=
rule
.
cssText
;
if
(
css
.
indexOf
(
selector
)
!==
-
1
)
{
if
(
css
.
indexOf
(
property
)
!==
-
1
)
{
try
{
value
=
css
.
split
(
property
)[
1
].
split
(
':'
)[
1
].
split
(
';'
)[
0
];
return
value
.
trim
();
}
catch
(
e
)
{
// Error will be caught in case of incorrect CSS
return
undefined
;
}
}
}
}
}
}
text
=
tick
.
select
(
"text"
);
tspan
=
text
.
selectAll
(
'tspan'
)
...
...
@@ -195,14 +172,13 @@ function c3_axis(d3, params, $$) {
tspan
.
enter
().
append
(
'tspan'
);
tspan
.
exit
().
remove
();
var
fontSize
;
var
fontSize
=
parseFloat
(
getStyleValue
(
'.c3-axis-y .tick'
,
'font-size'
))
;
tspan
.
text
(
function
(
d
)
{
fontSize
=
parseFloat
(
getStyleValue
(
'.c3-axis-y .tick'
,
'font-size'
));
if
(
d
.
splitted
.
length
)
{
$$
.
config
.
maxTickTextWidth
=
Math
.
max
(
$$
.
config
.
maxTickTextWidth
||
0
,
d
.
splitted
.
length
*
fontSize
/
$$
.
config
.
t
ick_t
ext_h_to_w
d
.
splitted
.
length
*
fontSize
/
$$
.
config
.
text_h_to_w
);
}
return
d
.
splitted
;
...
...
src/config.js
View file @
d8125d90
...
...
@@ -196,7 +196,8 @@ c3_chart_internal_fn.getDefaultConfig = function () {
tooltip_init_position
:
{
top
:
'0px'
,
left
:
'50px'
},
// default additional tick padding
tick_text_padding
:
0
,
tick_text_h_to_w
:
1.76
,
// change this when you change font-family!
text_h_to_w
:
1.76
,
// used when size is not available yet
default_tick_width
:
30
,
// caching
...
...
src/core.js
View file @
d8125d90
...
...
@@ -43,6 +43,30 @@ c3_chart_fn = c3.chart.fn;
c3_chart_internal_fn
=
c3
.
chart
.
internal
.
fn
;
// Seek a specific value in the stylesheets of a document
function
getStyleValue
(
selector
,
property
)
{
var
css
,
rule
,
sheet
,
value
;
for
(
var
styleId
=
0
;
styleId
<
document
.
styleSheets
.
length
;
styleId
++
)
{
sheet
=
document
.
styleSheets
[
styleId
];
for
(
var
ruleId
=
0
;
ruleId
<
sheet
.
cssRules
.
length
;
ruleId
++
)
{
rule
=
sheet
.
cssRules
[
ruleId
];
css
=
rule
.
cssText
;
if
(
css
.
indexOf
(
selector
)
!==
-
1
)
{
if
(
css
.
indexOf
(
property
)
!==
-
1
)
{
try
{
value
=
css
.
split
(
property
)[
1
].
split
(
':'
)[
1
].
split
(
';'
)[
0
];
return
value
.
trim
();
}
catch
(
e
)
{
// Error will be caught in case of incorrect CSS
return
undefined
;
}
}
}
}
}
}
c3_chart_internal_fn
.
init
=
function
()
{
var
$$
=
this
,
config
=
$$
.
config
;
...
...
src/legend.js
View file @
d8125d90
...
...
@@ -137,6 +137,8 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
options
=
options
||
{};
withTransition
=
getOption
(
options
,
"withTransition"
,
true
);
withTransitionForTransform
=
getOption
(
options
,
"withTransitionForTransform"
,
true
);
$$
.
clearLegendItemTextBoxCache
();
function
legendText
(
id
){
return
isDefined
(
config
.
data_names
[
id
])
?
config
.
data_names
[
id
]
:
isDefined
(
config
.
data_names
.
id
)
?
config
.
data_names
.
id
:
id
;
...
...
@@ -144,7 +146,7 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
function
getTextBox
(
textElement
,
id
)
{
if
(
!
legendItemTextBox
[
id
])
{
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
CLASS
.
legendItem
);
legendItemTextBox
[
id
]
=
$$
.
getTextRect
(
textElement
.
textContent
,
'.c3-legend-item'
);
}
return
legendItemTextBox
[
id
];
}
...
...
src/text.js
View file @
d8125d90
...
...
@@ -48,25 +48,12 @@ c3_chart_internal_fn.redrawText = function (xForText, yForText, forFlow, withTra
];
};
c3_chart_internal_fn
.
getTextRect
=
function
(
text
,
cls
)
{
var
body
=
this
.
d3
.
select
(
'body'
).
classed
(
'c3'
,
true
),
svg
=
body
.
append
(
"svg"
).
style
(
'visibility'
,
'hidden'
),
rect
;
svg
.
selectAll
(
'.dummy'
)
.
data
([
text
])
.
enter
().
append
(
'text'
)
.
classed
(
cls
?
cls
:
""
,
true
)
.
text
(
text
)
.
each
(
function
()
{
rect
=
this
.
getBoundingClientRect
();
});
svg
.
remove
();
body
.
classed
(
'c3'
,
false
);
// jsdom can't compute real size of text element
// getBoundingClientRect() returns zero-sized rect in jsdom
// This is a hack to estimate size depending on text length and average glyph size
if
(
isNode
()){
// 4 is average glyph size. Warning! This may break on font change.
// 8 is size of square near the text.
rect
.
width
=
text
.
length
*
4
-
8
;
}
return
rect
;
var
fontSize
=
parseFloat
(
getStyleValue
(
cls
,
'font-size'
));
return
{
height
:
fontSize
,
width
:
text
.
length
*
fontSize
/
this
.
config
.
text_h_to_w
};
};
c3_chart_internal_fn
.
generateXYForText
=
function
(
areaIndices
,
barIndices
,
lineIndices
,
forX
)
{
var
$$
=
this
,
...
...
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