Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinate mixin cleanup - xUnits #1410

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixes part of #1398. Used _chart.isOrdinal, updated documentation, …
…rearranged the code to make it more explicit about what it does.
  • Loading branch information
kum-deepak committed Apr 15, 2018
commit 1031f686612c3de843053f4edf5cf0f046fe3122
19 changes: 9 additions & 10 deletions src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,26 +390,25 @@ dc.coordinateGridMixin = function (_chart) {

/**
* Returns the number of units displayed on the x axis using the unit measure configured by
* {@link dc.coordinateGridMixin#xUnits xUnits}.
* {@link dc.coordinateGridMixin#xUnits xUnits}. If it is an Ordinal chart, it will return
* number of items in the domain.
* @method xUnitCount
* @memberof dc.coordinateGridMixin
* @instance
* @returns {Number}
*/
_chart.xUnitCount = function () {
if (_unitCount === undefined) {
var units;
if (_chart.xUnits() === dc.units.ordinal) {
if (_chart.isOrdinal()) {
// In this case it number of items in domain
units = _chart.x().domain();
_unitCount = _chart.x().domain().length;
} else {
units = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1]);
}
_unitCount = _chart.xUnits()(_chart.x().domain()[0], _chart.x().domain()[1]);

if (units instanceof Array) {
_unitCount = units.length;
} else {
_unitCount = units;
// Sometimes xUnits() may return an array while sometimes directly the count
if (_unitCount instanceof Array) {
_unitCount = _unitCount.length;
}
}
}

Expand Down