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
6046ee0f
Commit
6046ee0f
authored
May 05, 2015
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1025 from davidpoore/master
Add title config option to c3 charts core
parents
30ce1f82
35f170a8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
6 deletions
+142
-6
Gruntfile.coffee
Gruntfile.coffee
+1
-0
c3.js
c3.js
+36
-3
title-spec.js
spec/title-spec.js
+68
-0
config.js
src/config.js
+5
-1
core.js
src/core.js
+4
-0
size.js
src/size.js
+12
-2
title.js
src/title.js
+16
-0
No files found.
Gruntfile.coffee
View file @
6046ee0f
...
...
@@ -40,6 +40,7 @@ module.exports = (grunt) ->
'src/grid.js'
,
'src/tooltip.js'
,
'src/legend.js'
,
'src/title.js'
,
'src/axis.js'
,
'src/clip.js'
,
'src/arc.js'
,
...
...
c3.js
View file @
6046ee0f
...
...
@@ -263,6 +263,7 @@
if
(
$$
.
initSubchart
)
{
$$
.
initSubchart
();
}
if
(
$$
.
initTooltip
)
{
$$
.
initTooltip
();
}
if
(
$$
.
initLegend
)
{
$$
.
initLegend
();
}
if
(
$$
.
initTitle
)
{
$$
.
initTitle
();
}
/*-- Main Region --*/
...
...
@@ -608,6 +609,9 @@
$$
.
updateText
(
durationForExit
);
}
// title
if
(
$$
.
redrawTitle
)
{
$$
.
redrawTitle
();
}
// arc
if
(
$$
.
redrawArc
)
{
$$
.
redrawArc
(
duration
,
durationForExit
,
withTransform
);
}
...
...
@@ -1206,7 +1210,11 @@
},
tooltip_init_show
:
false
,
tooltip_init_x
:
0
,
tooltip_init_position
:
{
top
:
'0px'
,
left
:
'50px'
}
tooltip_init_position
:
{
top
:
'0px'
,
left
:
'50px'
},
// title
title_text
:
undefined
,
title_x
:
0
,
title_y
:
0
};
Object
.
keys
(
this
.
additionalConfig
).
forEach
(
function
(
key
)
{
...
...
@@ -2577,8 +2585,13 @@
return
h
>
0
?
h
:
320
/
(
$$
.
hasType
(
'gauge'
)
?
2
:
1
);
};
c3_chart_internal_fn
.
getCurrentPaddingTop
=
function
()
{
var
config
=
this
.
config
;
return
isValue
(
config
.
padding_top
)
?
config
.
padding_top
:
0
;
var
$$
=
this
,
config
=
$$
.
config
,
padding
=
isValue
(
config
.
padding_top
)
?
config
.
padding_top
:
0
;
if
(
$$
.
title
&&
$$
.
title
.
node
())
{
padding
+=
$$
.
getTitlePadding
();
}
return
padding
;
};
c3_chart_internal_fn
.
getCurrentPaddingBottom
=
function
()
{
var
config
=
this
.
config
;
...
...
@@ -2672,6 +2685,11 @@
return
Math
.
max
(
0
,
this
.
xAxis
.
tickInterval
());
};
c3_chart_internal_fn
.
getTitlePadding
=
function
()
{
var
$$
=
this
;
return
$$
.
config
.
title_y
+
$$
.
title
.
node
().
getBBox
().
height
;
};
c3_chart_internal_fn
.
getShapeIndices
=
function
(
typeFilter
)
{
var
$$
=
this
,
config
=
$$
.
config
,
indices
=
{},
i
=
0
,
j
,
k
;
...
...
@@ -4146,6 +4164,21 @@
$$
.
legendHasRendered
=
true
;
};
c3_chart_internal_fn
.
initTitle
=
function
()
{
var
$$
=
this
;
$$
.
title
=
$$
.
svg
.
append
(
"text"
)
.
text
(
$$
.
config
.
title_text
)
.
attr
(
"class"
,
"c3-chart-title"
)
.
attr
(
"x"
,
$$
.
config
.
title_x
)
.
attr
(
"y"
,
$$
.
config
.
title_y
);
};
c3_chart_internal_fn
.
redrawTitle
=
function
()
{
var
$$
=
this
;
$$
.
title
.
attr
(
"x"
,
$$
.
config
.
title_x
)
.
attr
(
"y"
,
$$
.
config
.
title_y
||
$$
.
title
.
node
().
getBBox
().
height
);
};
function
Axis
(
owner
)
{
API
.
call
(
this
,
owner
);
}
...
...
spec/title-spec.js
0 → 100644
View file @
6046ee0f
describe
(
'c3 chart title'
,
function
()
{
'use strict'
;
var
chart
,
config
;
describe
(
'when given a title config option'
,
function
()
{
describe
(
'with no x or y value'
,
function
()
{
beforeEach
(
function
(
done
)
{
config
=
{
data
:
{
columns
:
[
[
'data1'
,
30
,
200
,
100
,
400
,
150
,
250
]
]
},
title
:
{
text
:
'new title'
}
};
chart
=
window
.
initChart
(
chart
,
config
,
done
);
});
it
(
'renders the title at the default config position'
,
function
()
{
var
titleEl
=
d3
.
select
(
".c3-chart-title"
);
expect
(
titleEl
.
attr
(
"x"
)).
toEqual
(
'0'
);
expect
(
titleEl
.
attr
(
"y"
)).
toEqual
(
titleEl
.
node
().
getBBox
().
height
.
toString
());
});
it
(
'renders the title text'
,
function
()
{
var
titleEl
=
d3
.
select
(
".c3-chart-title"
);
expect
(
titleEl
.
node
().
textContent
).
toEqual
(
'new title'
);
});
});
describe
(
'with x and y values'
,
function
()
{
beforeEach
(
function
(
done
)
{
config
=
{
data
:
{
columns
:
[
[
'data1'
,
30
,
200
,
100
,
400
,
150
,
250
]
]
},
title
:
{
text
:
'positioned title'
,
x
:
50
,
y
:
10
}
};
chart
=
window
.
initChart
(
chart
,
config
,
done
);
});
it
(
'renders the title at the default config position'
,
function
()
{
var
titleEl
=
d3
.
select
(
".c3-chart-title"
);
expect
(
titleEl
.
attr
(
"x"
)).
toEqual
(
'50'
);
expect
(
titleEl
.
attr
(
"y"
)).
toEqual
(
'10'
);
});
it
(
'renders the title text'
,
function
()
{
var
titleEl
=
d3
.
select
(
".c3-chart-title"
);
expect
(
titleEl
.
node
().
textContent
).
toEqual
(
'positioned title'
);
});
it
(
'adds the correct amount of padding to fit the title'
,
function
()
{
expect
(
chart
.
internal
.
getCurrentPaddingTop
()).
toEqual
(
config
.
title
.
y
+
d3
.
select
(
'.c3-chart-title'
).
node
().
getBBox
().
height
);
});
});
});
});
\ No newline at end of file
src/config.js
View file @
6046ee0f
...
...
@@ -191,7 +191,11 @@ c3_chart_internal_fn.getDefaultConfig = function () {
},
tooltip_init_show
:
false
,
tooltip_init_x
:
0
,
tooltip_init_position
:
{
top
:
'0px'
,
left
:
'50px'
}
tooltip_init_position
:
{
top
:
'0px'
,
left
:
'50px'
},
// title
title_text
:
undefined
,
title_x
:
0
,
title_y
:
0
};
Object
.
keys
(
this
.
additionalConfig
).
forEach
(
function
(
key
)
{
...
...
src/core.js
View file @
6046ee0f
...
...
@@ -258,6 +258,7 @@ c3_chart_internal_fn.initWithData = function (data) {
if
(
$$
.
initSubchart
)
{
$$
.
initSubchart
();
}
if
(
$$
.
initTooltip
)
{
$$
.
initTooltip
();
}
if
(
$$
.
initLegend
)
{
$$
.
initLegend
();
}
if
(
$$
.
initTitle
)
{
$$
.
initTitle
();
}
/*-- Main Region --*/
...
...
@@ -603,6 +604,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$
.
updateText
(
durationForExit
);
}
// title
if
(
$$
.
redrawTitle
)
{
$$
.
redrawTitle
();
}
// arc
if
(
$$
.
redrawArc
)
{
$$
.
redrawArc
(
duration
,
durationForExit
,
withTransform
);
}
...
...
src/size.js
View file @
6046ee0f
...
...
@@ -8,8 +8,13 @@ c3_chart_internal_fn.getCurrentHeight = function () {
return
h
>
0
?
h
:
320
/
(
$$
.
hasType
(
'gauge'
)
?
2
:
1
);
};
c3_chart_internal_fn
.
getCurrentPaddingTop
=
function
()
{
var
config
=
this
.
config
;
return
isValue
(
config
.
padding_top
)
?
config
.
padding_top
:
0
;
var
$$
=
this
,
config
=
$$
.
config
,
padding
=
isValue
(
config
.
padding_top
)
?
config
.
padding_top
:
0
;
if
(
$$
.
title
&&
$$
.
title
.
node
())
{
padding
+=
$$
.
getTitlePadding
();
}
return
padding
;
};
c3_chart_internal_fn
.
getCurrentPaddingBottom
=
function
()
{
var
config
=
this
.
config
;
...
...
@@ -102,3 +107,8 @@ c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) {
c3_chart_internal_fn
.
getEventRectWidth
=
function
()
{
return
Math
.
max
(
0
,
this
.
xAxis
.
tickInterval
());
};
c3_chart_internal_fn
.
getTitlePadding
=
function
()
{
var
$$
=
this
;
return
$$
.
config
.
title_y
+
$$
.
title
.
node
().
getBBox
().
height
;
};
src/title.js
0 → 100644
View file @
6046ee0f
c3_chart_internal_fn
.
initTitle
=
function
()
{
var
$$
=
this
;
$$
.
title
=
$$
.
svg
.
append
(
"text"
)
.
text
(
$$
.
config
.
title_text
)
.
attr
(
"class"
,
"c3-chart-title"
)
.
attr
(
"x"
,
$$
.
config
.
title_x
)
.
attr
(
"y"
,
$$
.
config
.
title_y
);
};
c3_chart_internal_fn
.
redrawTitle
=
function
()
{
var
$$
=
this
;
$$
.
title
.
attr
(
"x"
,
$$
.
config
.
title_x
)
.
attr
(
"y"
,
$$
.
config
.
title_y
||
$$
.
title
.
node
().
getBBox
().
height
);
};
\ No newline at end of file
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