Browse Source

Add axis.y.default and axis.y2.default option - #442

pull/1616/head
Masayuki Tanaka 10 years ago
parent
commit
53f3442f73
  1. 10
      c3.js
  2. 6
      c3.min.js
  3. 6
      htdocs/index.html
  4. 26
      htdocs/samples/axes_y_default.html
  5. 2
      src/config.js
  6. 8
      src/scale.js

10
c3.js

@ -966,6 +966,7 @@
axis_y_tick_outer: true,
axis_y_padding: {},
axis_y_ticks: 10,
axis_y_default: undefined,
axis_y2_show: false,
axis_y2_max: undefined,
axis_y2_min: undefined,
@ -975,6 +976,7 @@
axis_y2_tick_outer: true,
axis_y2_padding: {},
axis_y2_ticks: 10,
axis_y2_default: undefined,
// grid
grid_x_show: false,
grid_x_type: 'tick',
@ -1138,11 +1140,11 @@
$$.subYMax = config.axis_rotated ? $$.width2 : 1;
// update scales
$$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); });
$$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain());
$$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain());
$$.y = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y_default : $$.y.domain());
$$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y2_default : $$.y2.domain());
$$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); });
$$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain());
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain());
$$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y_default : $$.subY.domain());
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain());
// update axes
$$.xAxisTickFormat = $$.getXAxisTickFormat();
$$.xAxisTickValues = config.axis_x_tick_values ? config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues());

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

6
htdocs/index.html

@ -157,6 +157,12 @@
</div>
</div>
<div class="row">
<div class="col-md-4">
<h3>Default Y Domain</h3>
<a href="./samples/axes_y_default.html">
Set default y domain
</a>
</div>
<div class="col-md-4">
<h3>Y Domain</h3>
<a href="./samples/domain_y.html">

26
htdocs/samples/axes_y_default.html

@ -0,0 +1,26 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/c3.css">
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
data: {
columns: [
['data1'],
['data2'],
],
},
axis: {
y: {
default: [-100, 100]
}
}
});
</script>
</body>
</html>

2
src/config.js

@ -102,6 +102,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_y_tick_outer: true,
axis_y_padding: {},
axis_y_ticks: 10,
axis_y_default: undefined,
axis_y2_show: false,
axis_y2_max: undefined,
axis_y2_min: undefined,
@ -111,6 +112,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_y2_tick_outer: true,
axis_y2_padding: {},
axis_y2_ticks: 10,
axis_y2_default: undefined,
// grid
grid_x_show: false,
grid_x_type: 'tick',

8
src/scale.js

@ -63,11 +63,11 @@ c3_chart_internal_fn.updateScales = function () {
$$.subYMax = config.axis_rotated ? $$.width2 : 1;
// update scales
$$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); });
$$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain());
$$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain());
$$.y = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y_default : $$.y.domain());
$$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? config.axis_y2_default : $$.y2.domain());
$$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); });
$$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain());
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain());
$$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y_default : $$.subY.domain());
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain());
// update axes
$$.xAxisTickFormat = $$.getXAxisTickFormat();
$$.xAxisTickValues = config.axis_x_tick_values ? config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues());

Loading…
Cancel
Save