Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5c9778d1
Commit
5c9778d1
authored
Mar 31, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename and reorder additional methods for clarity
parent
47a6524d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
67 deletions
+69
-67
app/assets/javascripts/burndown_chart/burndown_chart.js
app/assets/javascripts/burndown_chart/burndown_chart.js
+69
-67
No files found.
app/assets/javascripts/burndown_chart/burndown_chart.js
View file @
5c9778d1
...
...
@@ -98,7 +98,7 @@ export default class BurndownChart {
.
y
(
d
=>
this
.
yScale
(
d
.
value
));
// render the chart
this
.
queu
eRender
();
this
.
schedul
eRender
();
}
// set data and force re-render
...
...
@@ -128,8 +128,8 @@ export default class BurndownChart {
this
.
idealData
=
[
idealStart
,
idealEnd
];
}
this
.
queu
eLineAnimation
=
true
;
this
.
queu
eRender
();
this
.
schedul
eLineAnimation
=
true
;
this
.
schedul
eRender
();
}
handleMousemove
()
{
...
...
@@ -141,68 +141,12 @@ export default class BurndownChart {
const
d0
=
this
.
data
[
i
-
1
];
const
d1
=
this
.
data
[
i
];
if
(
d1
==
null
||
dateOffset
-
d0
.
date
<
d1
.
date
-
dateOffset
)
{
this
.
handle
Tooltip
(
d0
);
this
.
render
Tooltip
(
d0
);
}
else
{
this
.
handle
Tooltip
(
d1
);
this
.
render
Tooltip
(
d1
);
}
}
handleTooltip
(
datum
)
{
if
(
this
.
currentPoint
===
datum
)
return
;
this
.
currentPoint
=
datum
;
// generate tooltip content
const
format
=
d3
.
time
.
format
(
'
%b %-d, %Y
'
);
const
date
=
format
(
datum
.
date
);
const
tooltip
=
`
${
datum
.
value
}
Remaining /
${
date
}
`
;
// move the tooltip point of origin to the point on the graph
const
x
=
this
.
xScale
(
datum
.
date
);
const
y
=
this
.
yScale
(
datum
.
value
);
const
textSize
=
this
.
tooltipGroup
.
select
(
'
text
'
).
text
(
tooltip
).
node
().
getBBox
();
const
width
=
textSize
.
width
+
(
tooltipPadding
.
x
*
2
);
const
height
=
textSize
.
height
+
(
tooltipPadding
.
y
*
2
);
// calculate bounraries
const
xMin
=
0
-
x
-
margin
.
left
;
const
yMin
=
0
-
y
-
margin
.
top
;
const
xMax
=
(
this
.
chartWidth
+
margin
.
right
)
-
x
-
width
;
const
yMax
=
(
this
.
chartHeight
+
margin
.
bottom
)
-
y
-
height
;
// try to fit tooltip above point
let
xOffset
=
0
-
Math
.
floor
(
width
/
2
);
let
yOffset
=
0
-
tooltipDistance
-
height
;
if
(
yOffset
<=
yMin
)
{
// else try to fit tooltip to the right
xOffset
=
tooltipDistance
;
yOffset
=
0
-
Math
.
floor
(
height
/
2
);
if
(
xOffset
>=
xMax
)
{
// else place tooltip on the left
xOffset
=
0
-
tooltipDistance
-
width
;
}
}
// ensure coordinates keep the entire tooltip in-bounds
xOffset
=
Math
.
max
(
xMin
,
Math
.
min
(
xMax
,
xOffset
));
yOffset
=
Math
.
max
(
yMin
,
Math
.
min
(
yMax
,
yOffset
));
// move everything into place
this
.
chartFocus
.
attr
(
'
transform
'
,
`translate(
${
x
}
,
${
y
}
)`
);
this
.
tooltipGroup
.
attr
(
'
transform
'
,
`translate(
${
xOffset
}
,
${
yOffset
}
)`
);
this
.
tooltipGroup
.
select
(
'
text
'
)
.
attr
(
'
dy
'
,
'
1em
'
)
.
attr
(
'
x
'
,
tooltipPadding
.
x
)
.
attr
(
'
y
'
,
tooltipPadding
.
y
);
this
.
tooltipGroup
.
select
(
'
rect
'
)
.
attr
(
'
width
'
,
width
)
.
attr
(
'
height
'
,
height
);
}
// reset width and height to match the svg element, then re-render if necessary
handleResize
()
{
const
dimensions
=
this
.
canvas
.
node
().
getBoundingClientRect
();
...
...
@@ -217,13 +161,19 @@ export default class BurndownChart {
this
.
xScale
.
range
([
0
,
this
.
chartWidth
]);
this
.
yScale
.
range
([
this
.
chartHeight
,
0
]);
this
.
queueRender
();
this
.
scheduleRender
();
}
}
scheduleRender
()
{
if
(
this
.
queuedRender
==
null
)
{
this
.
queuedRender
=
requestAnimationFrame
(()
=>
this
.
render
());
}
}
render
()
{
this
.
queuedRender
=
null
;
this
.
currentPoint
=
null
;
// force recalculate tooltip
this
.
renderedTooltipPoint
=
null
;
// force tooltip re-render
this
.
xAxis
.
ticks
(
Math
.
floor
(
this
.
chartWidth
/
120
));
this
.
yAxis
.
ticks
(
Math
.
min
(
Math
.
floor
(
this
.
chartHeight
/
60
),
this
.
yMax
));
...
...
@@ -303,8 +253,8 @@ export default class BurndownChart {
this
.
actualLinePath
.
datum
(
this
.
data
).
attr
(
'
d
'
,
this
.
line
);
this
.
idealLinePath
.
datum
(
this
.
idealData
).
attr
(
'
d
'
,
this
.
line
);
if
(
this
.
queu
eLineAnimation
===
true
)
{
this
.
queu
eLineAnimation
=
false
;
if
(
this
.
schedul
eLineAnimation
===
true
)
{
this
.
schedul
eLineAnimation
=
false
;
// hide tooltips until animation is finished
this
.
chartFocus
.
attr
(
'
opacity
'
,
0
);
...
...
@@ -316,8 +266,60 @@ export default class BurndownChart {
}
}
queueRender
()
{
this
.
queuedRender
=
this
.
queuedRender
||
requestAnimationFrame
(()
=>
this
.
render
());
renderTooltip
(
datum
)
{
if
(
this
.
renderedTooltipPoint
===
datum
)
return
;
this
.
renderedTooltipPoint
=
datum
;
// generate tooltip content
const
format
=
d3
.
time
.
format
(
'
%b %-d, %Y
'
);
const
date
=
format
(
datum
.
date
);
const
tooltip
=
`
${
datum
.
value
}
Remaining /
${
date
}
`
;
// move the tooltip point of origin to the point on the graph
const
x
=
this
.
xScale
(
datum
.
date
);
const
y
=
this
.
yScale
(
datum
.
value
);
const
textSize
=
this
.
tooltipGroup
.
select
(
'
text
'
).
text
(
tooltip
).
node
().
getBBox
();
const
width
=
textSize
.
width
+
(
tooltipPadding
.
x
*
2
);
const
height
=
textSize
.
height
+
(
tooltipPadding
.
y
*
2
);
// calculate bounraries
const
xMin
=
0
-
x
-
margin
.
left
;
const
yMin
=
0
-
y
-
margin
.
top
;
const
xMax
=
(
this
.
chartWidth
+
margin
.
right
)
-
x
-
width
;
const
yMax
=
(
this
.
chartHeight
+
margin
.
bottom
)
-
y
-
height
;
// try to fit tooltip above point
let
xOffset
=
0
-
Math
.
floor
(
width
/
2
);
let
yOffset
=
0
-
tooltipDistance
-
height
;
if
(
yOffset
<=
yMin
)
{
// else try to fit tooltip to the right
xOffset
=
tooltipDistance
;
yOffset
=
0
-
Math
.
floor
(
height
/
2
);
if
(
xOffset
>=
xMax
)
{
// else place tooltip on the left
xOffset
=
0
-
tooltipDistance
-
width
;
}
}
// ensure coordinates keep the entire tooltip in-bounds
xOffset
=
Math
.
max
(
xMin
,
Math
.
min
(
xMax
,
xOffset
));
yOffset
=
Math
.
max
(
yMin
,
Math
.
min
(
yMax
,
yOffset
));
// move everything into place
this
.
chartFocus
.
attr
(
'
transform
'
,
`translate(
${
x
}
,
${
y
}
)`
);
this
.
tooltipGroup
.
attr
(
'
transform
'
,
`translate(
${
xOffset
}
,
${
yOffset
}
)`
);
this
.
tooltipGroup
.
select
(
'
text
'
)
.
attr
(
'
dy
'
,
'
1em
'
)
.
attr
(
'
x
'
,
tooltipPadding
.
x
)
.
attr
(
'
y
'
,
tooltipPadding
.
y
);
this
.
tooltipGroup
.
select
(
'
rect
'
)
.
attr
(
'
width
'
,
width
)
.
attr
(
'
height
'
,
height
);
}
animateResize
(
seconds
=
5
)
{
...
...
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