'use strict';
-var Scale = require('../core/core.scale');
+const Scale = require('../core/core.scale');
-var defaultConfig = {
+const defaultConfig = {
position: 'bottom'
};
-module.exports = Scale.extend({
-
- _parse: function(raw, index) {
+class CategroyScale extends Scale {
+ _parse(raw, index) {
var labels = this._getLabels();
var first = labels.indexOf(raw);
var last = labels.lastIndexOf(raw);
return first === -1 || first !== last ? index : first;
- },
+ }
- determineDataLimits: function() {
+ determineDataLimits() {
var me = this;
var max = me._getLabels().length - 1;
me.min = Math.max(me._userMin || 0, 0);
me.max = Math.min(me._userMax || max, max);
- },
+ }
- buildTicks: function() {
+ buildTicks() {
var me = this;
var labels = me._getLabels();
var min = me.min;
return labels.map(function(l) {
return {value: l};
});
- },
+ }
- getLabelForValue: function(value) {
+ getLabelForValue(value) {
var me = this;
var labels = me._getLabels();
return labels[value];
}
return value;
- },
+ }
- _configure: function() {
+ _configure() {
var me = this;
var offset = me.options.offset;
var ticks = me.ticks;
me._startValue = me.min - (offset ? 0.5 : 0);
me._valueRange = Math.max(ticks.length - (offset ? 0 : 1), 1);
- },
+ }
// Used to get data value locations. Value can either be an index or a numerical value
- getPixelForValue: function(value) {
+ getPixelForValue(value) {
var me = this;
if (typeof value !== 'number') {
}
return me.getPixelForDecimal((value - me._startValue) / me._valueRange);
- },
+ }
- getPixelForTick: function(index) {
+ getPixelForTick(index) {
var ticks = this.ticks;
return index < 0 || index > ticks.length - 1
? null
: this.getPixelForValue(index + this.min);
- },
+ }
- getValueForPixel: function(pixel) {
+ getValueForPixel(pixel) {
var me = this;
var value = Math.round(me._startValue + me.getDecimalForPixel(pixel) * me._valueRange);
return Math.min(Math.max(value, 0), me.ticks.length - 1);
- },
+ }
- getBasePixel: function() {
+ getBasePixel() {
return this.bottom;
}
-});
+}
+module.exports = CategroyScale;
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
'use strict';
-var helpers = require('../helpers/index');
-var LinearScaleBase = require('./scale.linearbase');
-var Ticks = require('../core/core.ticks');
+const helpers = require('../helpers/index');
+const LinearScaleBase = require('./scale.linearbase');
+const Ticks = require('../core/core.ticks');
-var defaultConfig = {
+const defaultConfig = {
position: 'left',
ticks: {
callback: Ticks.formatters.linear
}
};
-module.exports = LinearScaleBase.extend({
- determineDataLimits: function() {
+class LinearScale extends LinearScaleBase {
+ determineDataLimits() {
var me = this;
var DEFAULT_MIN = 0;
var DEFAULT_MAX = 1;
// Common base implementation to handle min, max, beginAtZero
me.handleTickRangeOptions();
- },
+ }
// Returns the maximum number of ticks based on the scale dimension
- _computeTickLimit: function() {
+ _computeTickLimit() {
var me = this;
var tickFont;
}
tickFont = helpers.options._parseFont(me.options.ticks);
return Math.ceil(me.height / tickFont.lineHeight);
- },
+ }
/**
* Called after the ticks are built
* @private
*/
- _handleDirectionalChanges: function(ticks) {
+ _handleDirectionalChanges(ticks) {
// If we are in a vertical orientation the top value is the highest so reverse the array
return this.isHorizontal() ? ticks : ticks.reverse();
- },
+ }
// Utils
- getPixelForValue: function(value) {
+ getPixelForValue(value) {
var me = this;
return me.getPixelForDecimal((value - me._startValue) / me._valueRange);
- },
+ }
- getValueForPixel: function(pixel) {
+ getValueForPixel(pixel) {
return this._startValue + this.getDecimalForPixel(pixel) * this._valueRange;
- },
+ }
- getPixelForTick: function(index) {
+ getPixelForTick(index) {
var ticks = this._tickValues;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index]);
}
-});
+}
+module.exports = LinearScale;
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
'use strict';
-var helpers = require('../helpers/index');
-var Scale = require('../core/core.scale');
+const helpers = require('../helpers/index');
+const Scale = require('../core/core.scale');
-var isNullOrUndef = helpers.isNullOrUndef;
+const isNullOrUndef = helpers.isNullOrUndef;
/**
* Generate a set of linear ticks
return ticks;
}
-module.exports = Scale.extend({
- _parse: function(raw, index) { // eslint-disable-line no-unused-vars
+class LinearScaleBase extends Scale {
+ _parse(raw, index) { // eslint-disable-line no-unused-vars
if (helpers.isNullOrUndef(raw)) {
return NaN;
}
}
return +raw;
- },
+ }
- handleTickRangeOptions: function() {
+ handleTickRangeOptions() {
var me = this;
var opts = me.options;
me.min--;
}
}
- },
+ }
- getTickLimit: function() {
+ getTickLimit() {
var me = this;
var tickOpts = me.options.ticks;
var stepSize = tickOpts.stepSize;
}
return maxTicks;
- },
+ }
- _computeTickLimit: function() {
+ _computeTickLimit() {
return Number.POSITIVE_INFINITY;
- },
+ }
- _handleDirectionalChanges: function(ticks) {
+ _handleDirectionalChanges(ticks) {
return ticks;
- },
+ }
- buildTicks: function() {
+ buildTicks() {
var me = this;
var opts = me.options;
var tickOpts = opts.ticks;
}
return ticks;
- },
+ }
- generateTickLabels: function(ticks) {
+ generateTickLabels(ticks) {
var me = this;
me._tickValues = ticks.map(t => t.value);
Scale.prototype.generateTickLabels.call(me, ticks);
- },
+ }
- _configure: function() {
+ _configure() {
var me = this;
var ticks = me.getTicks();
var start = me.min;
me._endValue = end;
me._valueRange = end - start;
}
-});
+}
+
+module.exports = LinearScaleBase;
'use strict';
-var defaults = require('../core/core.defaults');
-var helpers = require('../helpers/index');
-var Scale = require('../core/core.scale');
-var LinearScaleBase = require('./scale.linearbase');
-var Ticks = require('../core/core.ticks');
+const defaults = require('../core/core.defaults');
+const helpers = require('../helpers/index');
+const Scale = require('../core/core.scale');
+const LinearScaleBase = require('./scale.linearbase');
+const Ticks = require('../core/core.ticks');
-var valueOrDefault = helpers.valueOrDefault;
-var log10 = helpers.math.log10;
+const valueOrDefault = helpers.valueOrDefault;
+const log10 = helpers.math.log10;
/**
* Generate a set of logarithmic ticks
return ticks;
}
-var defaultConfig = {
+const defaultConfig = {
position: 'left',
// label settings
}
};
-module.exports = Scale.extend({
- _parse: function(raw, index) { // eslint-disable-line no-unused-vars
+class LogarithmicScale extends Scale {
+ _parse(raw, index) { // eslint-disable-line no-unused-vars
const value = LinearScaleBase.prototype._parse.apply(this, arguments);
return helpers.isFinite(value) && value >= 0 ? value : undefined;
- },
+ }
- determineDataLimits: function() {
+ determineDataLimits() {
var me = this;
var minmax = me._getMinMax(true);
var min = minmax.min;
me.minNotZero = helpers.isFinite(minPositive) ? minPositive : null;
me.handleTickRangeOptions();
- },
+ }
- handleTickRangeOptions: function() {
+ handleTickRangeOptions() {
var me = this;
var DEFAULT_MIN = 1;
var DEFAULT_MAX = 10;
}
me.min = min;
me.max = max;
- },
+ }
- buildTicks: function() {
+ buildTicks() {
var me = this;
var opts = me.options;
var reverse = !me.isHorizontal();
ticks.reverse();
}
return ticks;
- },
+ }
- generateTickLabels: function(ticks) {
+ generateTickLabels(ticks) {
this._tickValues = ticks.map(t => t.value);
return Scale.prototype.generateTickLabels.call(this, ticks);
- },
+ }
- getPixelForTick: function(index) {
+ getPixelForTick(index) {
var ticks = this._tickValues;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index]);
- },
+ }
/**
* Returns the value of the first tick.
* @return {number} The first tick value.
* @private
*/
- _getFirstTickValue: function(value) {
+ _getFirstTickValue(value) {
var exp = Math.floor(log10(value));
var significand = Math.floor(value / Math.pow(10, exp));
return significand * Math.pow(10, exp);
- },
+ }
- _configure: function() {
+ _configure() {
var me = this;
var start = me.min;
var offset = 0;
me._startValue = log10(start);
me._valueOffset = offset;
me._valueRange = (log10(me.max) - log10(start)) / (1 - offset);
- },
+ }
- getPixelForValue: function(value) {
+ getPixelForValue(value) {
var me = this;
var decimal = 0;
decimal = (log10(value) - me._startValue) / me._valueRange + me._valueOffset;
}
return me.getPixelForDecimal(decimal);
- },
+ }
- getValueForPixel: function(pixel) {
+ getValueForPixel(pixel) {
var me = this;
var decimal = me.getDecimalForPixel(pixel);
return decimal === 0 && me.min === 0
? 0
: Math.pow(10, me._startValue + (decimal - me._valueOffset) * me._valueRange);
}
-});
+}
+module.exports = LogarithmicScale;
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
'use strict';
-var defaults = require('../core/core.defaults');
-var helpers = require('../helpers/index');
-var LinearScaleBase = require('./scale.linearbase');
-var Ticks = require('../core/core.ticks');
+const defaults = require('../core/core.defaults');
+const helpers = require('../helpers/index');
+const LinearScaleBase = require('./scale.linearbase');
+const Ticks = require('../core/core.ticks');
-var valueOrDefault = helpers.valueOrDefault;
-var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
-var resolve = helpers.options.resolve;
+const valueOrDefault = helpers.valueOrDefault;
+const valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
+const resolve = helpers.options.resolve;
-var defaultConfig = {
+const defaultConfig = {
display: true,
// Boolean - Whether to animate scaling the chart from the centre
return helpers.isNumber(param) ? param : 0;
}
-module.exports = LinearScaleBase.extend({
- setDimensions: function() {
+class RadialLinearScale extends LinearScaleBase {
+ setDimensions() {
var me = this;
// Set the unconstrained dimension before label rotation
me.xCenter = Math.floor(me.width / 2);
me.yCenter = Math.floor((me.height - me.paddingTop) / 2);
me.drawingArea = Math.min(me.height - me.paddingTop, me.width) / 2;
- },
+ }
- determineDataLimits: function() {
+ determineDataLimits() {
var me = this;
var minmax = me._getMinMax(false);
var min = minmax.min;
// Common base implementation to handle min, max, beginAtZero
me.handleTickRangeOptions();
- },
+ }
// Returns the maximum number of ticks based on the scale dimension
- _computeTickLimit: function() {
+ _computeTickLimit() {
return Math.ceil(this.drawingArea / getTickBackdropHeight(this.options));
- },
+ }
- generateTickLabels: function(ticks) {
+ generateTickLabels(ticks) {
var me = this;
LinearScaleBase.prototype.generateTickLabels.call(me, ticks);
var label = helpers.callback(me.options.pointLabels.callback, arguments, me);
return label || label === 0 ? label : '';
});
- },
+ }
- fit: function() {
+ fit() {
var me = this;
var opts = me.options;
} else {
me.setCenterPoint(0, 0, 0, 0);
}
- },
+ }
/**
* Set radius reductions and determine new radius and center point
* @private
*/
- setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
+ setReductions(largestPossibleRadius, furthestLimits, furthestAngles) {
var me = this;
var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
Math.floor(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
Math.floor(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
- },
+ }
- setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
+ setCenterPoint(leftMovement, rightMovement, topMovement, bottomMovement) {
var me = this;
var maxRight = me.width - rightMovement - me.drawingArea;
var maxLeft = leftMovement + me.drawingArea;
me.xCenter = Math.floor(((maxLeft + maxRight) / 2) + me.left);
me.yCenter = Math.floor(((maxTop + maxBottom) / 2) + me.top + me.paddingTop);
- },
+ }
- getIndexAngle: function(index) {
+ getIndexAngle(index) {
var chart = this.chart;
var angleMultiplier = 360 / chart.data.labels.length;
var options = chart.options || {};
var angle = (index * angleMultiplier + startAngle) % 360;
return (angle < 0 ? angle + 360 : angle) * Math.PI * 2 / 360;
- },
+ }
- getDistanceFromCenterForValue: function(value) {
+ getDistanceFromCenterForValue(value) {
var me = this;
if (helpers.isNullOrUndef(value)) {
return (me.max - value) * scalingFactor;
}
return (value - me.min) * scalingFactor;
- },
+ }
- getPointPosition: function(index, distanceFromCenter) {
+ getPointPosition(index, distanceFromCenter) {
var me = this;
var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
return {
x: Math.cos(thisAngle) * distanceFromCenter + me.xCenter,
y: Math.sin(thisAngle) * distanceFromCenter + me.yCenter
};
- },
+ }
- getPointPositionForValue: function(index, value) {
+ getPointPositionForValue(index, value) {
return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
- },
+ }
- getBasePosition: function(index) {
+ getBasePosition(index) {
var me = this;
var min = me.min;
var max = me.max;
min < 0 && max < 0 ? max :
min > 0 && max > 0 ? min :
0);
- },
+ }
/**
* @private
*/
- _drawGrid: function() {
+ _drawGrid() {
var me = this;
var ctx = me.ctx;
var opts = me.options;
ctx.restore();
}
- },
+ }
/**
* @private
*/
- _drawLabels: function() {
+ _drawLabels() {
var me = this;
var ctx = me.ctx;
var opts = me.options;
});
ctx.restore();
- },
+ }
/**
* @private
*/
- _drawTitle: helpers.noop
-});
+ _drawTitle() {}
+}
+module.exports = RadialLinearScale;
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
'use strict';
-var adapters = require('../core/core.adapters');
-var defaults = require('../core/core.defaults');
-var helpers = require('../helpers/index');
-var Scale = require('../core/core.scale');
+const adapters = require('../core/core.adapters');
+const defaults = require('../core/core.defaults');
+const helpers = require('../helpers/index');
+const Scale = require('../core/core.scale');
-var resolve = helpers.options.resolve;
-var valueOrDefault = helpers.valueOrDefault;
+const resolve = helpers.options.resolve;
+const valueOrDefault = helpers.valueOrDefault;
// Integer constants are from the ES6 spec.
-var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
+const MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
-var INTERVALS = {
+const INTERVALS = {
millisecond: {
common: true,
size: 1,
}
};
-var UNITS = Object.keys(INTERVALS);
+const UNITS = Object.keys(INTERVALS);
function sorter(a, b) {
return a - b;
: timestamps;
}
-var defaultConfig = {
+const defaultConfig = {
position: 'bottom',
/**
}
};
-module.exports = Scale.extend({
- _parse: function(raw, index) { // eslint-disable-line no-unused-vars
+class TimeScale extends Scale {
+ _parse(raw, index) { // eslint-disable-line no-unused-vars
if (raw === undefined) {
return NaN;
}
return parse(this, raw);
- },
+ }
- _parseObject: function(obj, axis, index) {
+ _parseObject(obj, axis, index) {
if (obj && obj.t) {
return this._parse(obj.t, index);
}
return this._parse(obj[axis], index);
}
return null;
- },
+ }
- _invalidateCaches: function() {
+ _invalidateCaches() {
this._cache = {};
- },
+ }
+
+ constructor(props) {
+ super(props);
- initialize: function() {
var me = this;
var options = me.options;
var time = options.time || (options.time = {});
// missing formats on update
helpers.mergeIf(time.displayFormats, adapter.formats());
+ }
- Scale.prototype.initialize.call(me);
- },
-
- determineDataLimits: function() {
+ determineDataLimits() {
var me = this;
var options = me.options;
var adapter = me._adapter;
// Make sure that max is strictly higher than min (required by the lookup table)
me.min = Math.min(min, max);
me.max = Math.max(min + 1, max);
- },
+ }
- buildTicks: function() {
+ buildTicks() {
var me = this;
var options = me.options;
var timeOpts = options.time;
}
return ticksFromTimestamps(me, ticks, me._majorUnit);
- },
+ }
- getLabelForValue: function(value) {
+ getLabelForValue(value) {
var me = this;
var adapter = me._adapter;
var timeOpts = me.options.time;
return adapter.format(value, timeOpts.tooltipFormat);
}
return adapter.format(value, timeOpts.displayFormats.datetime);
- },
+ }
/**
* Function to format an individual tick mark
* @private
*/
- _tickFormatFunction: function(time, index, ticks, format) {
+ _tickFormatFunction(time, index, ticks, format) {
var me = this;
var adapter = me._adapter;
var options = me.options;
]);
return formatter ? formatter(label, index, ticks) : label;
- },
+ }
- generateTickLabels: function(ticks) {
+ generateTickLabels(ticks) {
var i, ilen, tick;
for (i = 0, ilen = ticks.length; i < ilen; ++i) {
tick = ticks[i];
tick.label = this._tickFormatFunction(tick.value, i, ticks);
}
- },
+ }
/**
* @private
*/
- _getPixelForOffset: function(time) {
+ _getPixelForOffset(time) {
var me = this;
var offsets = me._offsets;
var pos = interpolate(me._table, 'time', time, 'pos');
return me.getPixelForDecimal((offsets.start + pos) * offsets.factor);
- },
+ }
- getPixelForValue: function(value) {
+ getPixelForValue(value) {
var me = this;
if (typeof value !== 'number') {
if (value !== null) {
return me._getPixelForOffset(value);
}
- },
+ }
- getPixelForTick: function(index) {
+ getPixelForTick(index) {
var ticks = this.getTicks();
return index >= 0 && index < ticks.length ?
this._getPixelForOffset(ticks[index].value) :
null;
- },
+ }
- getValueForPixel: function(pixel) {
+ getValueForPixel(pixel) {
var me = this;
var offsets = me._offsets;
var pos = me.getDecimalForPixel(pixel) / offsets.factor - offsets.end;
return interpolate(me._table, 'pos', pos, 'time');
- },
+ }
/**
* @private
*/
- _getLabelSize: function(label) {
+ _getLabelSize(label) {
var me = this;
var ticksOpts = me.options.ticks;
var tickLabelWidth = me.ctx.measureText(label).width;
w: (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation),
h: (tickLabelWidth * sinRotation) + (tickFontSize * cosRotation)
};
- },
+ }
/**
* @private
*/
- _getLabelCapacity: function(exampleTime) {
+ _getLabelCapacity(exampleTime) {
var me = this;
var timeOpts = me.options.time;
var displayFormats = timeOpts.displayFormats;
return capacity > 0 ? capacity : 1;
}
-});
+}
+module.exports = TimeScale;
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;