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
Implemented aligment by senior unit in time axis. #4267
Changes from 8 commits
4888830
a47c7e3
90eeedd
9d90575
a6fba63
deee58f
d7424cf
3f39647
abe456f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,15 +55,25 @@ module.exports = function(Chart) { | |
var ticks = []; | ||
if (options.maxTicks) { | ||
var stepSize = options.stepSize; | ||
ticks.push(options.min !== undefined ? options.min : niceRange.min); | ||
var cur = moment(niceRange.min); | ||
while (cur.add(stepSize, options.unit).valueOf() < niceRange.max) { | ||
ticks.push(cur.valueOf()); | ||
var startTick = options.min !== undefined ? options.min : niceRange.min; | ||
var majorUnit = options.majorUnit; | ||
var majorUnitStart = majorUnit ? majorUnitStart = moment(startTick).add(1, majorUnit).startOf(majorUnit) : startTick; | ||
var startRange = majorUnitStart.valueOf() - startTick; | ||
var stepValue = interval[options.unit].size * stepSize; | ||
var startFraction = startRange % stepValue; | ||
var alignedTick = startTick; | ||
if (startFraction && majorUnit && !options.timeOpts.round && !options.timeOpts.isoWeekday) { | ||
alignedTick += startFraction - stepValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how that's related to my question... |
||
ticks.push(alignedTick); | ||
} else { | ||
ticks.push(startTick); | ||
} | ||
var cur = moment(alignedTick); | ||
var realMax = options.max || niceRange.max; | ||
if (ticks[ticks.length - 1] !== realMax) { | ||
ticks.push(realMax); | ||
while (cur.add(stepSize, options.unit).valueOf() < realMax) { | ||
ticks.push(cur.valueOf()); | ||
} | ||
ticks.push(cur.valueOf()); | ||
} | ||
return ticks; | ||
} | ||
|
@@ -128,6 +138,22 @@ module.exports = function(Chart) { | |
return unit; | ||
}, | ||
|
||
/** | ||
* Determine major unit accordingly to passed unit | ||
* @param unit {String} relative unit | ||
* @return {String} major unit | ||
*/ | ||
determineMajorUnit: function(unit) { | ||
var units = Object.keys(interval); | ||
var majorUnit = null; | ||
var unitIndex = units.indexOf(unit); | ||
if (unitIndex < units.length - 1) { | ||
majorUnit = units[unitIndex + 1]; | ||
} | ||
|
||
return majorUnit; | ||
}, | ||
|
||
/** | ||
* Determines how we scale the unit | ||
* @param min {Number} the scale minimum | ||
|
@@ -169,7 +195,7 @@ module.exports = function(Chart) { | |
generateTicks: function(options, dataRange) { | ||
var niceMin; | ||
var niceMax; | ||
var isoWeekday = options.isoWeekday; | ||
var isoWeekday = options.timeOpts.isoWeekday; | ||
if (options.unit === 'week' && isoWeekday !== false) { | ||
niceMin = moment(dataRange.min).startOf('isoWeek').isoWeekday(isoWeekday).valueOf(); | ||
niceMax = moment(dataRange.max).startOf('isoWeek').isoWeekday(isoWeekday); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has
majorUnitStart =
twice. You only need it once: