Commit 8c9ca3ce authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix bugs

parent 0e32fc0d
...@@ -673,6 +673,9 @@ ...@@ -673,6 +673,9 @@
))) )))
.style("visibility", "visible"); .style("visibility", "visible");
} }
function hideTooltip() {
tooltip.style("display", "none");
}
function showXGridFocus(data) { function showXGridFocus(data) {
main.selectAll('line.xgrid-focus') main.selectAll('line.xgrid-focus')
...@@ -681,6 +684,9 @@ ...@@ -681,6 +684,9 @@
.attr(__axis_rotated ? 'y1' : 'x1', xx) .attr(__axis_rotated ? 'y1' : 'x1', xx)
.attr(__axis_rotated ? 'y2' : 'x2', xx); .attr(__axis_rotated ? 'y2' : 'x2', xx);
} }
function hideXGridFocus() {
main.select('line.xgrid-focus').style("visibility", "hidden");
}
//-- Circle --// //-- Circle --//
...@@ -734,14 +740,14 @@ ...@@ -734,14 +740,14 @@
function getBarW(axis, barTargetsNum, isSub) { function getBarW(axis, barTargetsNum, isSub) {
var barW; var barW;
if (isCategorized) { if (isCategorized) {
barW = (axis.tickOffset() * 2 * 0.6) / barTargetsNum; barW = barTargetsNum ? (axis.tickOffset() * 2 * 0.6) / barTargetsNum : 0;
} else { } else {
barW = (((__axis_rotated ? height : width) * getXDomainRatio(isSub)) / (maxDataCount() - 1)) * 0.6; barW = (((__axis_rotated ? height : width) * getXDomainRatio(isSub)) / (maxDataCount() - 1)) * 0.6;
} }
return barW; return barW;
} }
function getBarH(height, isSub) { function getBarH(height, isSub) {
var h = height === null ? function (v) { return v; } : function (v) { return height - v; }; var h = height === null ? function (v) { return v; } : function (v) { return height > v ? height - v : 0; };
return function (d) { return function (d) {
var scale = isSub ? getSubYScale(d.id) : getYScale(d.id); var scale = isSub ? getSubYScale(d.id) : getYScale(d.id);
return h(scale(d.value)); return h(scale(d.value));
...@@ -895,6 +901,30 @@ ...@@ -895,6 +901,30 @@
//-- Shape --// //-- Shape --//
function getCircles(i, id) {
return (id ? main.selectAll('.-circles-' + id) : main).selectAll('.-circle' + (i || i === 0 ? '-' + i : ''));
}
function expandCircles(i, id) {
getCircles(i, id)
.classed(EXPANDED, true)
.attr('r', __point_focus_expand_r);
}
function unexpandCircles(i) {
getCircles(i)
.filter(function () { return d3.select(this).classed(EXPANDED); })
.classed(EXPANDED, false)
.attr('r', __point_r);
}
function getBars(i) {
return main.selectAll(".-bar" + (i || i === 0 ? '-' + i : ''));
}
function expandBars(i) {
getBars(i).classed(EXPANDED, false);
}
function unexpandBars(i) {
getBars(i).classed(EXPANDED, false);
}
// For main region // For main region
var lineOnMain = (function () { var lineOnMain = (function () {
var line = d3.svg.line() var line = d3.svg.line()
...@@ -1325,31 +1355,19 @@ ...@@ -1325,31 +1355,19 @@
selectedData = newData.concat(selectedData); // Add remained selectedData = newData.concat(selectedData); // Add remained
} }
// Expand circles if needed // Expand shapes if needed
if (__point_focus_expand_enabled) { if (__point_focus_expand_enabled) { expandCircles(i); }
main.selectAll('.-circle-' + i) expandBars(i);
.classed(EXPANDED, true)
.attr('r', __point_focus_expand_r);
}
// Expand bars
main.selectAll(".-bar-" + i)
.classed(EXPANDED, true);
// Show xgrid focus line // Show xgrid focus line
showXGridFocus(selectedData[0]); showXGridFocus(selectedData[0]);
}) })
.on('mouseout', function (d, i) { .on('mouseout', function (d, i) {
main.select('line.xgrid-focus').style("visibility", "hidden"); hideXGridFocus();
tooltip.style("display", "none"); hideTooltip();
// Undo expanded circles // Undo expanded shapes
main.selectAll('.-circle-' + i) unexpandCircles(i);
.filter(function () { return d3.select(this).classed(EXPANDED); }) unexpandBars();
.classed(EXPANDED, false)
.attr('r', __point_r);
// Undo expanded bar
main.selectAll(".-bar-" + i)
.classed(EXPANDED, false);
}) })
.on('mousemove', function (d, i) { .on('mousemove', function (d, i) {
var selectedData; var selectedData;
...@@ -1413,23 +1431,27 @@ ...@@ -1413,23 +1431,27 @@
.attr('width', width) .attr('width', width)
.attr('height', height) .attr('height', height)
.attr('class', "event-rect") .attr('class', "event-rect")
.on('mouseout', function () {
hideXGridFocus();
hideTooltip();
unexpandCircles();
})
.on('mousemove', function () { .on('mousemove', function () {
var mouse = d3.mouse(this), var mouse, closest, selectedData;
if (dragging) { return; } // do nothing when dragging
mouse = d3.mouse(this);
closest = findClosest(c3.data.targets, mouse); closest = findClosest(c3.data.targets, mouse);
// show tooltip when cursor is close to some point // show tooltip when cursor is close to some point
var selectedData = [addName(closest)]; selectedData = [addName(closest)];
showTooltip(selectedData, mouse); showTooltip(selectedData, mouse);
// expand points // expand points
if (__point_focus_expand_enabled) { if (__point_focus_expand_enabled) {
main.selectAll('.-circle') unexpandCircles();
.filter(function () { return d3.select(this).classed(EXPANDED); }) expandCircles(closest.index, closest.id);
.classed(EXPANDED, false)
.attr('r', __point_r);
main.select('.-circles-' + closest.id).select('.-circle-' + closest.index)
.classed(EXPANDED, true)
.attr('r', __point_focus_expand_r);
} }
// Show xgrid focus line // Show xgrid focus line
...@@ -1499,6 +1521,7 @@ ...@@ -1499,6 +1521,7 @@
.attr('y', minY) .attr('y', minY)
.attr('width', maxX - minX) .attr('width', maxX - minX)
.attr('height', maxY - minY); .attr('height', maxY - minY);
// TODO: binary search when multiple xs
main.selectAll('.-shapes').selectAll('.-shape') main.selectAll('.-shapes').selectAll('.-shape')
.filter(function (d) { return __data_selection_isselectable(d); }) .filter(function (d) { return __data_selection_isselectable(d); })
.each(function (d, i) { .each(function (d, i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment