Browse Source

added configurable domain trimming

pull/603/head
michalkop93 10 years ago
parent
commit
7a0a8c4e09
  1. 1
      Gruntfile.coffee
  2. 51
      c3.js
  3. 6
      c3.min.js
  4. 33
      src/api.domain.js
  5. 2
      src/config.js
  6. 18
      src/domain.js

1
Gruntfile.coffee

@ -65,6 +65,7 @@ module.exports = (grunt) ->
'src/api.color.js', 'src/api.color.js',
'src/api.x.js', 'src/api.x.js',
'src/api.axis.js', 'src/api.axis.js',
'src/api.domain.js',
'src/api.legend.js', 'src/api.legend.js',
'src/api.chart.js', 'src/api.chart.js',
'src/api.tooltip.js', 'src/api.tooltip.js',

51
c3.js

@ -965,6 +965,8 @@
axis_x_height: undefined, axis_x_height: undefined,
axis_x_extent: undefined, axis_x_extent: undefined,
axis_x_label: {}, axis_x_label: {},
axis_x_domain_min: undefined,
axis_x_domain_max: undefined,
axis_y_show: true, axis_y_show: true,
axis_y_max: undefined, axis_y_max: undefined,
axis_y_min: undefined, axis_y_min: undefined,
@ -1382,14 +1384,16 @@
return $$.x.domain(); return $$.x.domain();
}; };
c3_chart_internal_fn.trimXDomain = function (domain) { c3_chart_internal_fn.trimXDomain = function (domain) {
var $$ = this; var $$ = this, config = $$.config, d3 = $$.d3;
if (domain[0] <= $$.orgXDomain[0]) { var min = d3.min([$$.orgXDomain[0], config.axis_x_domain_min]);
domain[1] = +domain[1] + ($$.orgXDomain[0] - domain[0]); var max = d3.max([$$.orgXDomain[1], config.axis_x_domain_max]);
domain[0] = $$.orgXDomain[0]; if (domain[0] <= min) {
domain[1] = +domain[1] + (min - domain[0]);
domain[0] = min;
} }
if ($$.orgXDomain[1] <= domain[1]) { if (max <= domain[1]) {
domain[0] = +domain[0] - (domain[1] - $$.orgXDomain[1]); domain[0] = +domain[0] - (domain[1] - max);
domain[1] = $$.orgXDomain[1]; domain[1] = max;
} }
return domain; return domain;
}; };
@ -6095,6 +6099,39 @@
} }
}; };
c3_chart_fn.domain = function () {};
c3_chart_fn.domain.max = function (max) {
var $$ = this.internal, config = $$.config, d3 = $$.d3;
if (max === 0 || max) {
config.axis_x_domain_max = d3.max([$$.orgXDomain[1], max]);
}
else {
return config.axis_x_domain_max;
}
};
c3_chart_fn.domain.min = function (min) {
var $$ = this.internal, config = $$.config, d3 = $$.d3;
if (min === 0 || min) {
config.axis_x_domain_min = d3.min([$$.orgXDomain[0], min]);
}
else {
return config.axis_x_domain_min;
}
};
c3_chart_fn.domain.range = function (range) {
if (arguments.length) {
if (isDefined(range.max)) { this.domain.max(range.max); }
if (isDefined(range.min)) { this.domain.min(range.min); }
} else {
return {
max: this.domain.max(),
min: this.domain.min()
};
}
};
c3_chart_fn.legend = function () {}; c3_chart_fn.legend = function () {};
c3_chart_fn.legend.show = function (targetIds) { c3_chart_fn.legend.show = function (targetIds) {
var $$ = this.internal; var $$ = this.internal;

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

33
src/api.domain.js

@ -0,0 +1,33 @@
c3_chart_fn.domain = function () {};
c3_chart_fn.domain.max = function (max) {
var $$ = this.internal, config = $$.config, d3 = $$.d3;
if (max === 0 || max) {
config.axis_x_domain_max = d3.max([$$.orgXDomain[1], max]);
}
else {
return config.axis_x_domain_max;
}
};
c3_chart_fn.domain.min = function (min) {
var $$ = this.internal, config = $$.config, d3 = $$.d3;
if (min === 0 || min) {
config.axis_x_domain_min = d3.min([$$.orgXDomain[0], min]);
}
else {
return config.axis_x_domain_min;
}
};
c3_chart_fn.domain.range = function (range) {
if (arguments.length) {
if (isDefined(range.max)) { this.domain.max(range.max); }
if (isDefined(range.min)) { this.domain.min(range.min); }
} else {
return {
max: this.domain.max(),
min: this.domain.min()
};
}
};

2
src/config.js

@ -95,6 +95,8 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_x_height: undefined, axis_x_height: undefined,
axis_x_extent: undefined, axis_x_extent: undefined,
axis_x_label: {}, axis_x_label: {},
axis_x_domain_min: undefined,
axis_x_domain_max: undefined,
axis_y_show: true, axis_y_show: true,
axis_y_max: undefined, axis_y_max: undefined,
axis_y_min: undefined, axis_y_min: undefined,

18
src/domain.js

@ -213,14 +213,16 @@ c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withU
return $$.x.domain(); return $$.x.domain();
}; };
c3_chart_internal_fn.trimXDomain = function (domain) { c3_chart_internal_fn.trimXDomain = function (domain) {
var $$ = this; var $$ = this, config = $$.config, d3 = $$.d3;
if (domain[0] <= $$.orgXDomain[0]) { var min = d3.min([$$.orgXDomain[0], config.axis_x_domain_min]);
domain[1] = +domain[1] + ($$.orgXDomain[0] - domain[0]); var max = d3.max([$$.orgXDomain[1], config.axis_x_domain_max]);
domain[0] = $$.orgXDomain[0]; if (domain[0] <= min) {
} domain[1] = +domain[1] + (min - domain[0]);
if ($$.orgXDomain[1] <= domain[1]) { domain[0] = min;
domain[0] = +domain[0] - (domain[1] - $$.orgXDomain[1]); }
domain[1] = $$.orgXDomain[1]; if (max <= domain[1]) {
domain[0] = +domain[0] - (domain[1] - max);
domain[1] = max;
} }
return domain; return domain;
}; };

Loading…
Cancel
Save