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
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions D3v4 Upgrade Notes.md → D3v4-Upgrade-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@
- Consider removing transitions for zooming and brushing
- d3 stack to D3v4
- Changing .tension call in lineChart


### For end users

- Changes to `xUnits` interface.
- geoChart
- Color scheme
- tension in curves

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am documenting all of these in Changelog.md, and also in the API documentation. We could do a D3-style CHANGES summary as well

27 changes: 13 additions & 14 deletions src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ dc.coordinateGridMixin = function (_chart) {
* @method xUnits
* @memberof dc.coordinateGridMixin
* @instance
* @todo Add docs for utilities
* @example
* // set x units to count days
* chart.xUnits(d3.timeDays);
Expand All @@ -276,15 +275,16 @@ dc.coordinateGridMixin = function (_chart) {
*
* // A custom xUnits function can be used as long as it follows the following interface:
* // units in integer
* function(start, end, xDomain) {
* function(start, end) {
* // simply calculates how many integers in the domain
* return Math.abs(end - start);
* };
* }
*
* // fixed units
* function(start, end, xDomain) {
* function(start, end) {
* // be aware using fixed units will disable the focus/zoom ability on the chart
* return 1000;
* }
* @param {Function} [xUnits=dc.units.integers]
* @returns {Function|dc.coordinateGridMixin}
*/
Expand Down 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