• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chartjs / chartjs-plugin-zoom / 11881672105

17 Nov 2024 07:38PM UTC coverage: 83.498%. Remained the same
11881672105

push

github

web-flow
Bump karma-spec-reporter from 0.0.32 to 0.0.36 (#881)

Bumps [karma-spec-reporter](https://github.com/tmcgee123/karma-spec-reporter) from 0.0.32 to 0.0.36.
- [Commits](https://github.com/tmcgee123/karma-spec-reporter/compare/v0.0.32...v0.0.36)

---
updated-dependencies:
- dependency-name: karma-spec-reporter
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

217 of 275 branches covered (78.91%)

Branch coverage included in aggregate %.

461 of 537 relevant lines covered (85.85%)

1426.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.14
/src/utils.js
1
import {each} from 'chart.js/helpers';
2

3
export const getModifierKey = opts => opts && opts.enabled && opts.modifierKey;
332✔
4
export const keyPressed = (key, event) => key && event[key + 'Key'];
100✔
5
export const keyNotPressed = (key, event) => key && !event[key + 'Key'];
232✔
6

7
/**
8
 * @param {string|function} mode can be 'x', 'y' or 'xy'
9
 * @param {string} dir can be 'x' or 'y'
10
 * @param {import('chart.js').Chart} chart instance of the chart in question
11
 * @returns {boolean}
12
 */
13
export function directionEnabled(mode, dir, chart) {
14
  if (mode === undefined) {
424!
15
    return true;
×
16
  } else if (typeof mode === 'string') {
424✔
17
    return mode.indexOf(dir) !== -1;
376✔
18
  } else if (typeof mode === 'function') {
48✔
19
    return mode({chart}).indexOf(dir) !== -1;
48✔
20
  }
21

22
  return false;
×
23
}
24

25
function directionsEnabled(mode, chart) {
26
  if (typeof mode === 'function') {
632!
27
    mode = mode({chart});
×
28
  }
29
  if (typeof mode === 'string') {
632✔
30
    return {x: mode.indexOf('x') !== -1, y: mode.indexOf('y') !== -1};
328✔
31
  }
32

33
  return {x: false, y: false};
304✔
34
}
35

36
/**
37
 * Debounces calling `fn` for `delay` ms
38
 * @param {function} fn - Function to call. No arguments are passed.
39
 * @param {number} delay - Delay in ms. 0 = immediate invocation.
40
 * @returns {function}
41
 */
42
export function debounce(fn, delay) {
43
  let timeout;
44
  return function() {
8✔
45
    clearTimeout(timeout);
4✔
46
    timeout = setTimeout(fn, delay);
4✔
47
    return delay;
4✔
48
  };
49
}
50

51
/**
52
 * Checks which axis is under the mouse cursor.
53
 * @param {{x: number, y: number}} point - the mouse location
54
 * @param {import('chart.js').Chart} [chart] instance of the chart in question
55
 * @return {import('chart.js').Scale}
56
 */
57
function getScaleUnderPoint({x, y}, chart) {
58
  const scales = chart.scales;
312✔
59
  const scaleIds = Object.keys(scales);
312✔
60
  for (let i = 0; i < scaleIds.length; i++) {
312✔
61
    const scale = scales[scaleIds[i]];
612✔
62
    if (y >= scale.top && y <= scale.bottom && x >= scale.left && x <= scale.right) {
612✔
63
      return scale;
20✔
64
    }
65
  }
66
  return null;
292✔
67
}
68

69
/**
70
 * Evaluate the chart's mode, scaleMode, and overScaleMode properties to
71
 * determine which axes are eligible for scaling.
72
 * options.overScaleMode can be a function if user want zoom only one scale of many for example.
73
 * @param options - Zoom or pan options
74
 * @param {{x: number, y: number}} point - the mouse location
75
 * @param {import('chart.js').Chart} [chart] instance of the chart in question
76
 * @return {import('chart.js').Scale[]}
77
 */
78
export function getEnabledScalesByPoint(options, point, chart) {
79
  const {mode = 'xy', scaleMode, overScaleMode} = options || {};
312!
80
  const scale = getScaleUnderPoint(point, chart);
312✔
81

82
  const enabled = directionsEnabled(mode, chart);
312✔
83
  const scaleEnabled = directionsEnabled(scaleMode, chart);
312✔
84

85
  // Convert deprecated overScaleEnabled to new scaleEnabled.
86
  if (overScaleMode) {
312✔
87
    const overScaleEnabled = directionsEnabled(overScaleMode, chart);
8✔
88
    for (const axis of ['x', 'y']) {
8✔
89
      if (overScaleEnabled[axis]) {
16✔
90
        scaleEnabled[axis] = enabled[axis];
8✔
91
        enabled[axis] = false;
8✔
92
      }
93
    }
94
  }
95

96
  if (scale && scaleEnabled[scale.axis]) {
312✔
97
    return [scale];
8✔
98
  }
99

100
  const enabledScales = [];
304✔
101
  each(chart.scales, function(scaleItem) {
304✔
102
    if (enabled[scaleItem.axis]) {
608✔
103
      enabledScales.push(scaleItem);
424✔
104
    }
105
  });
106
  return enabledScales;
304✔
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc