Browse Source

Fix axis.x.extent to axis.x.selection based on d3.v4

pull/2246/head
Masayuki Tanaka 7 years ago
parent
commit
ba8a95060d
  1. 8
      htdocs/samples/axes_x_selection.html
  2. 3
      src/config.js
  3. 6
      src/core.js
  4. 8
      src/subchart.js

8
htdocs/samples/axes_x_extent.html → htdocs/samples/axes_x_selection.html

@ -7,7 +7,7 @@
<div id="chart2"></div>
<div id="chart3"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
@ -21,7 +21,7 @@
},
axis: {
x: {
extent: [2, 4.5]
selection: [2, 4.5]
}
},
subchart: {
@ -42,7 +42,7 @@
axis: {
x: {
type: 'timeseries',
extent: ['2014-03-01', '2014-04-20']
selection: ['2014-03-01', '2014-04-20']
}
},
subchart: {
@ -60,7 +60,7 @@
},
axis: {
x: {
extent: [1, 4.2]
selection: [1, 4.2]
}
},
zoom: {

3
src/config.js

@ -13,7 +13,6 @@ c3_chart_internal_fn.getDefaultConfig = function () {
padding_bottom: undefined,
resize_auto: true,
zoom_enabled: false,
zoom_extent: undefined,
zoom_privileged: false,
zoom_rescale: false,
zoom_onzoom: function () {},
@ -112,7 +111,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_x_min: undefined,
axis_x_padding: {},
axis_x_height: undefined,
axis_x_extent: undefined,
axis_x_selection: undefined,
axis_x_label: {},
axis_y_show: true,
axis_y_type: undefined,

6
src/core.js

@ -283,15 +283,15 @@ c3_chart_internal_fn.initWithData = function (data) {
// Define g for chart
$$.initChartElements();
// Set default extent if defined
if (config.axis_x_extent) { $$.brush.extent($$.getDefaultExtent()); }
// Add Axis
$$.axis.init();
// Set targets
$$.updateTargets($$.data.targets);
// Set default extent if defined
if (config.axis_x_selection) { $$.brush.selectionAsValue($$.getDefaultSelection()); }
// Draw with targets
if (binding) {
$$.updateDimension();

8
src/subchart.js

@ -253,11 +253,11 @@ c3_chart_internal_fn.transformContext = function (withTransition, transitions) {
$$.context.attr("transform", $$.getTranslate('context'));
subXAxis.attr("transform", $$.getTranslate('subx'));
};
c3_chart_internal_fn.getDefaultExtent = function () {
c3_chart_internal_fn.getDefaultSelection = function () {
var $$ = this, config = $$.config,
extent = isFunction(config.axis_x_extent) ? config.axis_x_extent($$.getXDomain($$.data.targets)) : config.axis_x_extent;
selection = isFunction(config.axis_x_selection) ? config.axis_x_selection($$.getXDomain($$.data.targets)) : config.axis_x_selection;
if ($$.isTimeSeries()) {
extent = [$$.parseDate(extent[0]), $$.parseDate(extent[1])];
selection = [$$.parseDate(selection[0]), $$.parseDate(selection[1])];
}
return extent;
return selection;
};

Loading…
Cancel
Save