Skip to content

Commit

Permalink
reduce lines
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Dec 14, 2021
1 parent 9117df8 commit 8bd10e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/annotation.js
@@ -1,6 +1,7 @@
import {Animations, Chart} from 'chart.js';
import {clipArea, unclipArea, isFinite, valueOrDefault, isObject, isArray} from 'chart.js/helpers';
import {clipArea, unclipArea, isFinite, valueOrDefault, isObject, isArray, defined, isFunction} from 'chart.js/helpers';
import {handleEvent, hooks, updateListeners} from './events';
import {verifyScaleOptions} from './helpers';
import {annotationTypes} from './types';
import {version} from '../package.json';

Expand Down Expand Up @@ -245,19 +246,15 @@ function draw(chart, caller, clip) {
function adjustScaleRange(chart, scale, annotations) {
const range = getScaleLimits(scale, annotations);
let changed = false;
if (isFinite(range.min) &&
typeof scale.options.min === 'undefined' &&
typeof scale.options.suggestedMin === 'undefined') {
if (isFinite(range.min) && !defined(scale.options.min) && !defined(scale.options.suggestedMin)) {
changed = scale.min !== range.min;
scale.min = range.min;
}
if (isFinite(range.max) &&
typeof scale.options.max === 'undefined' &&
typeof scale.options.suggestedMax === 'undefined') {
if (isFinite(range.max) && !defined(scale.options.max) && !defined(scale.options.suggestedMax)) {
changed = scale.max !== range.max;
scale.max = range.max;
}
if (changed && typeof scale.handleTickRangeOptions === 'function') {
if (changed && isFunction(scale.handleTickRangeOptions)) {
scale.handleTickRangeOptions();
}
}
Expand Down Expand Up @@ -291,13 +288,3 @@ function getScaleLimits(scale, annotations) {
}
return {min, max};
}

function verifyScaleOptions(annotations, scales) {
for (const annotation of annotations) {
for (const key of ['scaleID', 'xScaleID', 'yScaleID']) {
if (annotation[key] && !scales[annotation[key]]) {
console.warn(`No scale found with id '${annotation[key]}' for annotation '${annotation.id}'`);
}
}
}
}
10 changes: 10 additions & 0 deletions src/helpers/helpers.options.js
Expand Up @@ -69,3 +69,13 @@ export function toPosition(value) {
export function isBoundToPoint(options) {
return options && (defined(options.xValue) || defined(options.yValue));
}

export function verifyScaleOptions(annotations, scales) {
for (const annotation of annotations) {
for (const key of ['scaleID', 'xScaleID', 'yScaleID']) {
if (annotation[key] && !scales[annotation[key]]) {
console.warn(`No scale found with id '${annotation[key]}' for annotation '${annotation.id}'`);
}
}
}
}

0 comments on commit 8bd10e6

Please sign in to comment.