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

Fix x axis ticks - #41

parent 683c9af6
...@@ -313,6 +313,7 @@ ...@@ -313,6 +313,7 @@
//-- Scales --// //-- Scales --//
function updateScales() { function updateScales() {
var xAxisTickFormat, xAxisTicks;
// update edges // update edges
xMin = __axis_rotated ? 1 : 0; xMin = __axis_rotated ? 1 : 0;
xMax = __axis_rotated ? height : width; xMax = __axis_rotated ? height : width;
...@@ -330,10 +331,12 @@ ...@@ -330,10 +331,12 @@
subY = getY(subYMin, subYMax); subY = getY(subYMin, subYMax);
subY2 = getY(subYMin, subYMax); subY2 = getY(subYMin, subYMax);
// update axes // update axes
xAxis = getXAxis(x, xOrient, getXAxisTickFormat()); xAxisTickFormat = getXAxisTickFormat();
yAxis = getYAxis(y, yOrient, __axis_y_tick_format); xAxisTicks = getXAxisTicks();
yAxis2 = getYAxis(y2, y2Orient, __axis_y2_tick_format); xAxis = getXAxis(x, xOrient, xAxisTickFormat, xAxisTicks);
subXAxis = getXAxis(subX, subXOrient, getXAxisTickFormat()); subXAxis = getXAxis(subX, subXOrient, xAxisTickFormat, xAxisTicks);
yAxis = getYAxis(y, yOrient, __axis_y_tick_format, __axis_y_ticks);
yAxis2 = getYAxis(y2, y2Orient, __axis_y2_tick_format, __axis_y2_ticks);
// update for arc // update for arc
updateArc(); updateArc();
} }
...@@ -381,11 +384,11 @@ ...@@ -381,11 +384,11 @@
//-- Axes --// //-- Axes --//
function getXAxis(scale, orient, tickFormat) { function getXAxis(scale, orient, tickFormat, ticks) {
var axis = (isCategorized ? categoryAxis() : d3.svg.axis()).scale(scale).orient(orient); var axis = (isCategorized ? categoryAxis() : d3.svg.axis()).scale(scale).orient(orient);
// Set tick format // Set tick
axis.tickFormat(tickFormat); axis.tickFormat(tickFormat).ticks(ticks);
// Set categories // Set categories
if (isCategorized) { if (isCategorized) {
...@@ -397,8 +400,8 @@ ...@@ -397,8 +400,8 @@
return axis; return axis;
} }
function getYAxis(scale, orient, tickFormat) { function getYAxis(scale, orient, tickFormat, ticks) {
return d3.svg.axis().scale(scale).orient(orient).tickFormat(tickFormat); return d3.svg.axis().scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks).outerTickSize(0);
} }
function getAxisId(id) { function getAxisId(id) {
return id in __data_axes ? __data_axes[id] : 'y'; return id in __data_axes ? __data_axes[id] : 'y';
...@@ -414,6 +417,10 @@ ...@@ -414,6 +417,10 @@
} }
return format; return format;
} }
function getXAxisTicks() {
var maxDataCount = getMaxDataCount();
return maxDataCount < 10 ? maxDataCount : 10;
}
//-- Arc --// //-- Arc --//
...@@ -1489,12 +1496,6 @@ ...@@ -1489,12 +1496,6 @@
subY.domain(y.domain()); subY.domain(y.domain());
subY2.domain(y2.domain()); subY2.domain(y2.domain());
// Set axes attrs
xAxis.ticks(data.length < 10 ? data.length : 10);
subXAxis.ticks(data.length < 10 ? data.length : 10);
yAxis.ticks(__axis_y_ticks).outerTickSize(0);
yAxis2.ticks(__axis_y2_ticks).outerTickSize(0);
// Save original x domain for zoom update // Save original x domain for zoom update
orgXDomain = x.domain(); orgXDomain = x.domain();
......
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