Skip to content

Commit

Permalink
Use a single gobal ID for each chart
Browse files Browse the repository at this point in the history
  • Loading branch information
jrideout committed Oct 15, 2013
1 parent 461120b commit 693168b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
10 changes: 7 additions & 3 deletions dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ dc.renderlet = function(_){
};

dc.instanceOfChart = function (o) {
return o instanceof Object && o.__dc_flag__;
return o instanceof Object && o.__dc_flag__ && true;
};

dc.errors = {};
Expand Down Expand Up @@ -691,7 +691,7 @@ Every function on base chart are also inherited available on all concrete chart
**/
dc.baseChart = function (_chart) {
_chart.__dc_flag__ = true;
_chart.__dc_flag__ = dc.utils.uniqueId();

var _dimension;
var _group;
Expand Down Expand Up @@ -957,7 +957,7 @@ dc.baseChart = function (_chart) {
var a = _chart.anchor();
if (a && a.id) return a.id;
if (a && a.replace) return a.replace('#','');
return ""+dc.utils.uniqueId();
return "" + _chart.chartID();
};

/**
Expand Down Expand Up @@ -1475,6 +1475,10 @@ dc.baseChart = function (_chart) {
return _chart;
};

_chart.chartID = function () {
return _chart.__dc_flag__;
};

return _chart;
};

Expand Down
4 changes: 2 additions & 2 deletions dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dc.min.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/base-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Every function on base chart are also inherited available on all concrete chart
**/
dc.baseChart = function (_chart) {
_chart.__dc_flag__ = true;
_chart.__dc_flag__ = dc.utils.uniqueId();

var _dimension;
var _group;
Expand Down Expand Up @@ -271,7 +271,7 @@ dc.baseChart = function (_chart) {
var a = _chart.anchor();
if (a && a.id) return a.id;
if (a && a.replace) return a.replace('#','');
return ""+dc.utils.uniqueId();
return "" + _chart.chartID();
};

/**
Expand Down Expand Up @@ -789,5 +789,9 @@ dc.baseChart = function (_chart) {
return _chart;
};

_chart.chartID = function () {
return _chart.__dc_flag__;
};

return _chart;
};
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@ dc.renderlet = function(_){
};

dc.instanceOfChart = function (o) {
return o instanceof Object && o.__dc_flag__;
return o instanceof Object && o.__dc_flag__ && true;
};
4 changes: 2 additions & 2 deletions test/base-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ suite.addBatch({
assert.fail("Exception should have been triggered");
} catch (e) {
assert.isTrue(e instanceof dc.errors.InvalidStateException);
assert.match(e.toString(), /Mandatory attribute chart.dimension is missing on chart\[#\d\]/);
assert.match(e.toString(), /Mandatory attribute chart.dimension is missing on chart\[#\d+\]/);
}
}
},
Expand All @@ -149,7 +149,7 @@ suite.addBatch({
assert.fail("Exception should have been triggered");
} catch (e) {
assert.isTrue(e instanceof dc.errors.InvalidStateException);
assert.match(e.toString(), /Mandatory attribute chart.group is missing on chart\[#\d\]/);
assert.match(e.toString(), /Mandatory attribute chart.group is missing on chart\[#\d+\]/);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/coordinate-grid-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ suite.addBatch({
assert.fail("Exception should have been triggered");
}catch(e){
assert.isTrue(e instanceof dc.errors.InvalidStateException);
assert.match(e.toString(), /Mandatory attribute chart.x is missing on chart\[#\d\]/);
assert.match(e.toString(), /Mandatory attribute chart.x is missing on chart\[#\d+\]/);
}
}
},
Expand Down
10 changes: 7 additions & 3 deletions web/js/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ dc.renderlet = function(_){
};

dc.instanceOfChart = function (o) {
return o instanceof Object && o.__dc_flag__;
return o instanceof Object && o.__dc_flag__ && true;
};

dc.errors = {};
Expand Down Expand Up @@ -691,7 +691,7 @@ Every function on base chart are also inherited available on all concrete chart
**/
dc.baseChart = function (_chart) {
_chart.__dc_flag__ = true;
_chart.__dc_flag__ = dc.utils.uniqueId();

var _dimension;
var _group;
Expand Down Expand Up @@ -957,7 +957,7 @@ dc.baseChart = function (_chart) {
var a = _chart.anchor();
if (a && a.id) return a.id;
if (a && a.replace) return a.replace('#','');
return ""+dc.utils.uniqueId();
return "" + _chart.chartID();
};

/**
Expand Down Expand Up @@ -1475,6 +1475,10 @@ dc.baseChart = function (_chart) {
return _chart;
};

_chart.chartID = function () {
return _chart.__dc_flag__;
};

return _chart;
};

Expand Down

0 comments on commit 693168b

Please sign in to comment.