Browse Source

Improve performance for update event rects on timeseries - #553

pull/729/head
Masayuki Tanaka 10 years ago
parent
commit
5533e803e8
  1. 19
      c3.js
  2. 2
      c3.min.js
  3. 15
      src/data.js
  4. 4
      src/interaction.js

19
c3.js

@ -1572,13 +1572,20 @@
}) })
}; };
}; };
c3_chart_internal_fn.updateXs = function () {
var $$ = this;
$$.xs = [];
$$.data.targets[0].values.forEach(function (v) {
$$.xs[v.index] = v.x;
});
};
c3_chart_internal_fn.getPrevX = function (i) { c3_chart_internal_fn.getPrevX = function (i) {
var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); var x = this.xs[i - 1];
return value ? value.x : null; return typeof x !== 'undefined' ? x : null;
}; };
c3_chart_internal_fn.getNextX = function (i) { c3_chart_internal_fn.getNextX = function (i) {
var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); var x = this.xs[i + 1];
return value ? value.x : null; return typeof x !== 'undefined' ? x : null;
}; };
c3_chart_internal_fn.getMaxDataCount = function () { c3_chart_internal_fn.getMaxDataCount = function () {
var $$ = this; var $$ = this;
@ -2173,6 +2180,10 @@
} }
else { else {
if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) {
// update index for x that is used by prevX and nextX
$$.updateXs();
rectW = function (d) { rectW = function (d) {
var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index); var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index);

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

15
src/data.js

@ -100,13 +100,20 @@ c3_chart_internal_fn.cloneTarget = function (target) {
}) })
}; };
}; };
c3_chart_internal_fn.updateXs = function () {
var $$ = this;
$$.xs = [];
$$.data.targets[0].values.forEach(function (v) {
$$.xs[v.index] = v.x;
});
};
c3_chart_internal_fn.getPrevX = function (i) { c3_chart_internal_fn.getPrevX = function (i) {
var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); var x = this.xs[i - 1];
return value ? value.x : null; return typeof x !== 'undefined' ? x : null;
}; };
c3_chart_internal_fn.getNextX = function (i) { c3_chart_internal_fn.getNextX = function (i) {
var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); var x = this.xs[i + 1];
return value ? value.x : null; return typeof x !== 'undefined' ? x : null;
}; };
c3_chart_internal_fn.getMaxDataCount = function () { c3_chart_internal_fn.getMaxDataCount = function () {
var $$ = this; var $$ = this;

4
src/interaction.js

@ -59,6 +59,10 @@ c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) {
} }
else { else {
if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) {
// update index for x that is used by prevX and nextX
$$.updateXs();
rectW = function (d) { rectW = function (d) {
var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index); var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index);

Loading…
Cancel
Save