Skip to content

Commit

Permalink
Merge pull request #6 from yubowenok/dev
Browse files Browse the repository at this point in the history
use hash value as data id to avoid potential reorder of data ids during deserialization
  • Loading branch information
yubowenok authored Oct 19, 2016
2 parents 1e88ce0 + 91cccea commit addf300
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ node_js:

before_script:
- npm install -g gulp
- rvm install ruby-2.2.3
- rvm install ruby
- gem install scss_lint

script:
Expand Down
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ gulp.task('default', ['lint', 'build', 'build-doc']);
// Do everything.
gulp.task('all', function(cb) {
runSequence(
'clean',
'dist',
['lint', 'compile-all', 'build-doc'],
'dist',
'build',
cb);
});
23 changes: 8 additions & 15 deletions src/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ visflow.TabularData;
/** @const */
visflow.data = {};

/**
* Counter to set process based dataIds.
* @type {number}
*/
visflow.data.counter = 0;

/**
* Dimension index of item table index.
* @const {number}
Expand All @@ -35,6 +29,9 @@ visflow.data.INDEX_DIM = -1;
/** @const {string} */
visflow.data.INDEX_TEXT = '[index]';

/** @const {string} */
visflow.data.EMPTY_DATA_ID = 'empty';

/**
* @typedef {{
* id: number,
Expand Down Expand Up @@ -121,12 +118,7 @@ visflow.data.registerData = function(data) {
visflow.error('attempt register null/empty data');
return;
}
if (!(data.hash in visflow.data.hashToData)) {
visflow.data.hashToData[data.hash] = data;
data.dataId = ++visflow.data.counter;
} else {
data.dataId = visflow.data.hashToData[data.hash].dataId;
}
visflow.data.hashToData[data.hash] = data;
};

/**
Expand All @@ -141,7 +133,7 @@ visflow.Data = function(data) {
dimensionTypes: [],
dimensionDuplicate: [],
values: [],
dataId: 0,
dataId: visflow.data.EMPTY_DATA_ID,
type: ''
});
return;
Expand Down Expand Up @@ -169,9 +161,10 @@ visflow.Data = function(data) {

/**
* Data id assigned by the running system instance.
* @type {number}
* Use hash value as data id to identify data changes.
* @type {string}
*/
this.dataId = data.dataId;
this.dataId = data.hash;

/**
* Type of data. It will be a hash value of the data's dimensions and
Expand Down
6 changes: 3 additions & 3 deletions src/filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ visflow.Filter = function(params) {

/**
* Last processed data id. By default it is empty data.
* @protected {number}
* @protected {string}
*/
this.lastDataId = 0;
this.lastDataId = visflow.data.EMPTY_DATA_ID;
};

_.inherit(visflow.Filter, visflow.Node);
Expand Down Expand Up @@ -51,7 +51,7 @@ visflow.Filter.prototype.deserialize = function(save) {
visflow.Filter.base.deserialize.call(this, save);
this.lastDataId = save.lastDataId;
if (this.lastDataId == null) {
this.lastDataId = 0;
this.lastDataId = visflow.data.EMPTY_DATA_ID;
visflow.warning('filter lastDataId not saved');
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/value/value-extractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ visflow.ValueExtractor = function(params) {
};

/**
* Last applied data id. Default is empty data (0).
* @protected {number}
* Last applied data id. Default is empty data.
* @protected {string}
*/
this.lastDataId = 0;
this.lastDataId = visflow.data.EMPTY_DATA_ID;
};

_.inherit(visflow.ValueExtractor, visflow.Node);
Expand Down
8 changes: 4 additions & 4 deletions src/visualization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ visflow.Visualization = function(params) {
this.brushPoints = [];

/**
* Last used dataset ID.
* @protected {number}
* Last used dataset ID. Default is empty data.
* @protected {string}
*/
this.lastDataId = 0; // Default: empty data
this.lastDataId = visflow.data.EMPTY_DATA_ID;

/**
* Whether rendering should be using transition. When the view is resized,
Expand Down Expand Up @@ -112,7 +112,7 @@ visflow.Visualization.prototype.deserialize = function(save) {
this.lastDataId = save.lastDataId;
if (this.lastDataId == null) {
visflow.error('lastDataId not saved in visualization');
this.lastDataId = 0;
this.lastDataId = visflow.data.EMPTY_DATA_ID;
}
this.fillOptions(this.options, this.visualizationOptions());
};
Expand Down
4 changes: 2 additions & 2 deletions src/visualization/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ visflow.Network = function(params) {

/**
* Last data id for edges.
* @protected {number}
* @protected {string}
*/
this.lastEdgeDataId = 0;
this.lastEdgeDataId = visflow.data.EMPTY_DATA_ID;

// Navigation state.
/** @private {!Array<number>} */
Expand Down

0 comments on commit addf300

Please sign in to comment.