import defaults from './core.defaults';
import Element from './core.element';
-import helpers from '../helpers';
+import {_alignPixel, _measureText} from '../helpers/helpers.canvas';
+import {callback as call, each, extend, isArray, isFinite, isNullOrUndef, isObject, valueOrDefault} from '../helpers/helpers.core';
+import {_factorize, toDegrees, toRadians} from '../helpers/helpers.math';
+import {_parseFont, resolve, toPadding} from '../helpers/helpers.options';
import Ticks from './core.ticks';
-const alignPixel = helpers.canvas._alignPixel;
-const isArray = helpers.isArray;
-const isFinite = helpers.isFinite;
-const isNullOrUndef = helpers.isNullOrUndef;
-const valueOrDefault = helpers.valueOrDefault;
-const resolve = helpers.options.resolve;
-
defaults._set('scale', {
display: true,
offset: false,
}
function garbageCollect(caches, length) {
- helpers.each(caches, function(cache) {
+ each(caches, function(cache) {
var gc = cache.gc;
var gcLen = gc.length / 2;
var i;
return 0;
}
- const font = helpers.options._parseFont(options);
- const padding = helpers.options.toPadding(options.padding);
+ const font = _parseFont(options);
+ const padding = toPadding(options.padding);
return font.lineHeight + padding.height;
}
return Math.max(spacing, 1);
}
- factors = helpers.math._factorize(evenMajorSpacing);
+ factors = _factorize(evenMajorSpacing);
for (i = 0, ilen = factors.length - 1; i < ilen; i++) {
factor = factors[i];
if (factor > spacing) {
// Any function can be extended by the scale type
beforeUpdate() {
- helpers.callback(this.options.beforeUpdate, [this]);
+ call(this.options.beforeUpdate, [this]);
}
/**
// TODO: make maxWidth, maxHeight private
me.maxWidth = maxWidth;
me.maxHeight = maxHeight;
- me.margins = helpers.extend({
+ me.margins = extend({
left: 0,
right: 0,
top: 0,
}
afterUpdate() {
- helpers.callback(this.options.afterUpdate, [this]);
+ call(this.options.afterUpdate, [this]);
}
//
beforeSetDimensions() {
- helpers.callback(this.options.beforeSetDimensions, [this]);
+ call(this.options.beforeSetDimensions, [this]);
}
setDimensions() {
const me = this;
me.paddingBottom = 0;
}
afterSetDimensions() {
- helpers.callback(this.options.afterSetDimensions, [this]);
+ call(this.options.afterSetDimensions, [this]);
}
// Data limits
beforeDataLimits() {
- helpers.callback(this.options.beforeDataLimits, [this]);
+ call(this.options.beforeDataLimits, [this]);
}
determineDataLimits() {}
afterDataLimits() {
- helpers.callback(this.options.afterDataLimits, [this]);
+ call(this.options.afterDataLimits, [this]);
}
//
beforeBuildTicks() {
- helpers.callback(this.options.beforeBuildTicks, [this]);
+ call(this.options.beforeBuildTicks, [this]);
}
buildTicks() {}
afterBuildTicks() {
- helpers.callback(this.options.afterBuildTicks, [this]);
+ call(this.options.afterBuildTicks, [this]);
}
beforeTickToLabelConversion() {
- helpers.callback(this.options.beforeTickToLabelConversion, [this]);
+ call(this.options.beforeTickToLabelConversion, [this]);
}
/**
* Convert ticks to label strings
let i, ilen, tick;
for (i = 0, ilen = ticks.length; i < ilen; i++) {
tick = ticks[i];
- tick.label = helpers.callback(tickOpts.callback, [tick.value, i, ticks], me);
+ tick.label = call(tickOpts.callback, [tick.value, i, ticks], me);
}
}
afterTickToLabelConversion() {
- helpers.callback(this.options.afterTickToLabelConversion, [this]);
+ call(this.options.afterTickToLabelConversion, [this]);
}
//
beforeCalculateLabelRotation() {
- helpers.callback(this.options.beforeCalculateLabelRotation, [this]);
+ call(this.options.beforeCalculateLabelRotation, [this]);
}
calculateLabelRotation() {
const me = this;
maxHeight = me.maxHeight - getTickMarkLength(options.gridLines)
- tickOpts.padding - getScaleLabelHeight(options.scaleLabel);
maxLabelDiagonal = Math.sqrt(maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight);
- labelRotation = helpers.math.toDegrees(Math.min(
+ labelRotation = toDegrees(Math.min(
Math.asin(Math.min((labelSizes.highest.height + 6) / tickWidth, 1)),
Math.asin(Math.min(maxHeight / maxLabelDiagonal, 1)) - Math.asin(maxLabelHeight / maxLabelDiagonal)
));
me.labelRotation = labelRotation;
}
afterCalculateLabelRotation() {
- helpers.callback(this.options.afterCalculateLabelRotation, [this]);
+ call(this.options.afterCalculateLabelRotation, [this]);
}
//
beforeFit() {
- helpers.callback(this.options.beforeFit, [this]);
+ call(this.options.beforeFit, [this]);
}
fit() {
const me = this;
if (isHorizontal) {
// A horizontal axis is more constrained by the height.
const isRotated = me.labelRotation !== 0;
- const angleRadians = helpers.math.toRadians(me.labelRotation);
+ const angleRadians = toRadians(me.labelRotation);
const cosRotation = Math.cos(angleRadians);
const sinRotation = Math.sin(angleRadians);
}
afterFit() {
- helpers.callback(this.options.afterFit, [this]);
+ call(this.options.afterFit, [this]);
}
// Shared Methods
width = height = 0;
// Undefined labels and arrays should not be measured
if (!isNullOrUndef(label) && !isArray(label)) {
- width = helpers.measureText(ctx, cache.data, cache.gc, width, label);
+ width = _measureText(ctx, cache.data, cache.gc, width, label);
height = lineHeight;
} else if (isArray(label)) {
// if it is an array let's measure each element
nestedLabel = label[j];
// Undefined labels and arrays should not be measured
if (!isNullOrUndef(nestedLabel) && !isArray(nestedLabel)) {
- width = helpers.measureText(ctx, cache.data, cache.gc, width, nestedLabel);
+ width = _measureText(ctx, cache.data, cache.gc, width, nestedLabel);
height += lineHeight;
}
}
if (numMajorIndices > 0) {
let i, ilen;
const avgMajorSpacing = numMajorIndices > 1 ? Math.round((last - first) / (numMajorIndices - 1)) : null;
- skip(ticks, newTicks, spacing, helpers.isNullOrUndef(avgMajorSpacing) ? 0 : first - avgMajorSpacing, first);
+ skip(ticks, newTicks, spacing, isNullOrUndef(avgMajorSpacing) ? 0 : first - avgMajorSpacing, first);
for (i = 0, ilen = numMajorIndices - 1; i < ilen; i++) {
skip(ticks, newTicks, spacing, majorIndices[i], majorIndices[i + 1]);
}
- skip(ticks, newTicks, spacing, last, helpers.isNullOrUndef(avgMajorSpacing) ? ticks.length : last + avgMajorSpacing);
+ skip(ticks, newTicks, spacing, last, isNullOrUndef(avgMajorSpacing) ? ticks.length : last + avgMajorSpacing);
return newTicks;
}
skip(ticks, newTicks, spacing);
const optionTicks = me.options.ticks;
// Calculate space needed by label in axis direction.
- const rot = helpers.math.toRadians(me.labelRotation);
+ const rot = toRadians(me.labelRotation);
const cos = Math.abs(Math.cos(rot));
const sin = Math.abs(Math.sin(rot));
const axisWidth = gridLines.drawBorder ? resolve([gridLines.borderWidth, gridLines.lineWidth, 0], context, 0) : 0;
const axisHalfWidth = axisWidth / 2;
const alignBorderValue = function(pixel) {
- return alignPixel(chart, pixel, axisWidth);
+ return _alignPixel(chart, pixel, axisWidth);
};
let borderValue, i, tick, lineValue, alignedLineValue;
let tx1, ty1, tx2, ty2, x1, y1, x2, y2;
} else if (axis === 'x') {
if (position === 'center') {
borderValue = alignBorderValue((chartArea.top + chartArea.bottom) / 2);
- } else if (helpers.isObject(position)) {
+ } else if (isObject(position)) {
const positionAxisID = Object.keys(position)[0];
const value = position[positionAxisID];
borderValue = alignBorderValue(me.chart.scales[positionAxisID].getPixelForValue(value));
} else if (axis === 'y') {
if (position === 'center') {
borderValue = alignBorderValue((chartArea.left + chartArea.right) / 2);
- } else if (helpers.isObject(position)) {
+ } else if (isObject(position)) {
const positionAxisID = Object.keys(position)[0];
const value = position[positionAxisID];
borderValue = alignBorderValue(me.chart.scales[positionAxisID].getPixelForValue(value));
continue;
}
- alignedLineValue = alignPixel(chart, lineValue, lineWidth);
+ alignedLineValue = _alignPixel(chart, lineValue, lineWidth);
if (isHorizontal) {
tx1 = tx2 = x1 = x2 = alignedLineValue;
const ticks = me.ticks;
const tickPadding = optionTicks.padding;
const tl = getTickMarkLength(options.gridLines);
- const rotation = -helpers.math.toRadians(me.labelRotation);
+ const rotation = -toRadians(me.labelRotation);
const items = [];
let i, ilen, tick, label, x, y, textAlign, pixel, font, lineHeight, lineCount, textOffset;
} else if (axis === 'x') {
if (position === 'center') {
y = ((chartArea.top + chartArea.bottom) / 2) + tl + tickPadding;
- } else if (helpers.isObject(position)) {
+ } else if (isObject(position)) {
const positionAxisID = Object.keys(position)[0];
const value = position[positionAxisID];
y = me.chart.scales[positionAxisID].getPixelForValue(value) + tl + tickPadding;
} else if (axis === 'y') {
if (position === 'center') {
x = ((chartArea.left + chartArea.right) / 2) - tl - tickPadding;
- } else if (helpers.isObject(position)) {
+ } else if (isObject(position)) {
const positionAxisID = Object.keys(position)[0];
const value = position[positionAxisID];
x = me.chart.scales[positionAxisID].getPixelForValue(value);
let x1, x2, y1, y2;
if (me.isHorizontal()) {
- x1 = alignPixel(chart, me.left, firstLineWidth) - firstLineWidth / 2;
- x2 = alignPixel(chart, me.right, lastLineWidth) + lastLineWidth / 2;
+ x1 = _alignPixel(chart, me.left, firstLineWidth) - firstLineWidth / 2;
+ x2 = _alignPixel(chart, me.right, lastLineWidth) + lastLineWidth / 2;
y1 = y2 = borderValue;
} else {
- y1 = alignPixel(chart, me.top, firstLineWidth) - firstLineWidth / 2;
- y2 = alignPixel(chart, me.bottom, lastLineWidth) + lastLineWidth / 2;
+ y1 = _alignPixel(chart, me.top, firstLineWidth) - firstLineWidth / 2;
+ y2 = _alignPixel(chart, me.bottom, lastLineWidth) + lastLineWidth / 2;
x1 = x2 = borderValue;
}
}
const scaleLabelFontColor = valueOrDefault(scaleLabel.fontColor, defaults.fontColor);
- const scaleLabelFont = helpers.options._parseFont(scaleLabel);
- const scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
+ const scaleLabelFont = _parseFont(scaleLabel);
+ const scaleLabelPadding = toPadding(scaleLabel.padding);
const halfLineHeight = scaleLabelFont.lineHeight / 2;
const scaleLabelAlign = scaleLabel.align;
const position = options.position;
tick: me.ticks[index],
index: index
};
- return helpers.extend(helpers.options._parseFont({
+ return extend(_parseFont({
fontFamily: resolve([options.fontFamily], context),
fontSize: resolve([options.fontSize], context),
fontStyle: resolve([options.fontStyle], context),