*gridLines*.zeroLineColor | Color | "rgba(0, 0, 0, 0.25)" | Stroke color of the grid line for the first index (index 0).
*gridLines*.offsetGridLines | Boolean | false | If true, offset labels from grid lines.
**scaleLabel** | Object | | Title for the entire axis.
-*scaleLabel*.display | Boolean | false |
+*scaleLabel*.display | Boolean | false |
*scaleLabel*.labelString | String | "" | The text for the title. (i.e. "# of People", "Response Choices")
*scaleLabel*.fontColor | Color | "#666" | Font color for the scale title.
*scaleLabel*.fontFamily| String | "Helvetica Neue" | Font family for the scale title, follows CSS font-family options.
*ticks*.display | Boolean | true | If true, show the ticks.
*ticks*.suggestedMin | Number | - | User defined minimum number for the scale, overrides minimum value *except for if* it is higher than the minimum value.
*ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value.
-*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value.
+*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value.
*ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value
*ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what
*ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart.
// string - By default, no rounding is applied. To round, set to a supported time unit eg. 'week', 'month', 'year', etc.
round: false,
-
+
+ // Number - By default, the week and therefore the scale starts on the locale defined week if the unit is 'week'. To override the start day of the week, set this to an integer between 1 and 7 - see http://momentjs.com/docs/#/get-set/iso-weekday/
+ isoWeekday: false,
+
// Moment js for each of the units. Replaces `displayFormat`
// To override, use a pattern string from http://momentjs.com/docs/#/displaying/format/
displayFormats: {
min: 0
}
})
-```
\ No newline at end of file
+```
unit: false, // false == automatic or override with week, month, year, etc.
round: false, // none, or override with week, month, year, etc.
displayFormat: false, // DEPRECATED
+ isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
// defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
displayFormats: {
getLabelMoment: function(datasetIndex, index) {
return this.labelMoments[datasetIndex][index];
},
+ getMomentStartOf: function(tick) {
+ if (this.options.time.unit === 'week' && this.options.time.isoWeekday !== false) {
+ return tick.clone().startOf('isoWeek').isoWeekday(this.options.time.isoWeekday);
+ } else {
+ return tick.clone().startOf(this.tickUnit);
+ }
+ },
determineDataLimits: function() {
this.labelMoments = [];
unitDefinition = time.units[unitDefinitionIndex];
this.tickUnit = unitDefinition.name;
- var leadingUnitBuffer = this.firstTick.diff(this.firstTick.clone().startOf(this.tickUnit), this.tickUnit, true);
- var trailingUnitBuffer = this.lastTick.clone().add(1, this.tickUnit).startOf(this.tickUnit).diff(this.lastTick, this.tickUnit, true);
+ var leadingUnitBuffer = this.firstTick.diff(this.getMomentStartOf(this.firstTick), this.tickUnit, true);
+ var trailingUnitBuffer = this.getMomentStartOf(this.lastTick.clone().add(1, this.tickUnit)).diff(this.lastTick, this.tickUnit, true);
this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
}
// Only round the first tick if we have no hard minimum
if (!this.options.time.min) {
- this.firstTick.startOf(this.tickUnit);
+ this.firstTick = this.getMomentStartOf(this.firstTick);
roundedStart = this.firstTick;
} else {
- roundedStart = this.firstTick.clone().startOf(this.tickUnit);
+ roundedStart = this.getMomentStartOf(this.firstTick);
}
// Only round the last tick if we have no hard maximum
if (!this.options.time.max) {
- var roundedEnd = this.lastTick.clone().startOf(this.tickUnit);
+ var roundedEnd = this.getMomentStartOf(this.lastTick);
if (roundedEnd.diff(this.lastTick, this.tickUnit, true) !== 0) {
// Do not use end of because we need this to be in the next time unit
- this.lastTick.add(1, this.tickUnit).startOf(this.tickUnit);
+ this.lastTick = this.getMomentStartOf(this.lastTick.add(1, this.tickUnit));
}
}
this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
}
}
-
+
this.ctx.restore();
},
// Get tooltip label
format: false,
unit: false,
round: false,
+ isoWeekday: false,
displayFormat: false,
displayFormats: {
'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM
expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 5, 2015' ]);
});
+ it('Should use the isoWeekday option', function() {
+ var scaleID = 'myScale';
+
+ var mockData = {
+ labels: [
+ "2015-01-01T20:00:00", // Thursday
+ "2015-01-02T20:00:00", // Friday
+ "2015-01-03T20:00:00" // Saturday
+ ]
+ };
+
+ var mockContext = window.createMockContext();
+ var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
+ config.time.unit = 'week';
+ // Wednesday
+ config.time.isoWeekday = 3;
+ var Constructor = Chart.scaleService.getScaleConstructor('time');
+ var scale = new Constructor({
+ ctx: mockContext,
+ options: config, // use default config for scale
+ chart: {
+ data: mockData
+ },
+ id: scaleID
+ });
+
+ scale.update(400, 50);
+ expect(scale.ticks).toEqual([ 'Dec 31, 2014', 'Jan 7, 2015' ]);
+ });
+
it('should get the correct pixel for a value', function() {
chartInstance = window.acquireChart({
type: 'line',