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

chartjs / chartjs-plugin-zoom / 11843695559

14 Nov 2024 06:56PM UTC coverage: 83.292%. Remained the same
11843695559

Pull #848

github

web-flow
Merge 0aee1e87c into c1985b1d3
Pull Request #848: Bump express from 4.18.2 to 4.21.1

263 of 330 branches covered (79.7%)

Branch coverage included in aggregate %.

415 of 484 relevant lines covered (85.74%)

1503.32 hits per line

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

91.3
/src/plugin.js
1
import Hammer from 'hammerjs';
2
import {addListeners, computeDragRect, removeListeners} from './handlers';
3
import {startHammer, stopHammer} from './hammer';
4
import {pan, zoom, resetZoom, zoomScale, getZoomLevel, getInitialScaleBounds, isZoomedOrPanned, zoomRect} from './core';
5
import {panFunctions, zoomFunctions, zoomRectFunctions} from './scale.types';
6
import {getState, removeState} from './state';
7
import {version} from '../package.json';
8

9
function draw(chart, caller, options) {
10
  const dragOptions = options.zoom.drag;
5,968✔
11
  const {dragStart, dragEnd} = getState(chart);
5,968✔
12

13
  if (dragOptions.drawTime !== caller || !dragEnd) {
5,968✔
14
    return;
5,924✔
15
  }
16
  const {left, top, width, height} = computeDragRect(chart, options.zoom.mode, dragStart, dragEnd);
44✔
17
  const ctx = chart.ctx;
44✔
18

19
  ctx.save();
44✔
20
  ctx.beginPath();
44✔
21
  ctx.fillStyle = dragOptions.backgroundColor || 'rgba(225,225,225,0.3)';
44✔
22
  ctx.fillRect(left, top, width, height);
44✔
23

24
  if (dragOptions.borderWidth > 0) {
44✔
25
    ctx.lineWidth = dragOptions.borderWidth;
8✔
26
    ctx.strokeStyle = dragOptions.borderColor || 'rgba(225,225,225)';
8!
27
    ctx.strokeRect(left, top, width, height);
8✔
28
  }
29
  ctx.restore();
44✔
30
}
31

32
export default {
33
  id: 'zoom',
34

35
  version,
36

37
  defaults: {
38
    pan: {
39
      enabled: false,
40
      mode: 'xy',
41
      threshold: 10,
42
      modifierKey: null,
43
    },
44
    zoom: {
45
      wheel: {
46
        enabled: false,
47
        speed: 0.1,
48
        modifierKey: null
49
      },
50
      drag: {
51
        enabled: false,
52
        drawTime: 'beforeDatasetsDraw',
53
        modifierKey: null
54
      },
55
      pinch: {
56
        enabled: false
57
      },
58
      mode: 'xy',
59
    }
60
  },
61

62
  start: function(chart, _args, options) {
63
    const state = getState(chart);
284✔
64
    state.options = options;
284✔
65

66
    if (Object.prototype.hasOwnProperty.call(options.zoom, 'enabled')) {
284!
67
      console.warn('The option `zoom.enabled` is no longer supported. Please use `zoom.wheel.enabled`, `zoom.drag.enabled`, or `zoom.pinch.enabled`.');
×
68
    }
69
    if (Object.prototype.hasOwnProperty.call(options.zoom, 'overScaleMode')
284✔
70
      || Object.prototype.hasOwnProperty.call(options.pan, 'overScaleMode')) {
71
      console.warn('The option `overScaleMode` is deprecated. Please use `scaleMode` instead (and update `mode` as desired).');
8✔
72
    }
73

74
    if (Hammer) {
284!
75
      startHammer(chart, options);
284✔
76
    }
77

78
    chart.pan = (delta, panScales, transition) => pan(chart, delta, panScales, transition);
328✔
79
    chart.zoom = (args, transition) => zoom(chart, args, transition);
284✔
80
    chart.zoomRect = (p0, p1, transition) => zoomRect(chart, p0, p1, transition);
284✔
81
    chart.zoomScale = (id, range, transition) => zoomScale(chart, id, range, transition);
284✔
82
    chart.resetZoom = (transition) => resetZoom(chart, transition);
284✔
83
    chart.getZoomLevel = () => getZoomLevel(chart);
284✔
84
    chart.getInitialScaleBounds = () => getInitialScaleBounds(chart);
284✔
85
    chart.isZoomedOrPanned = () => isZoomedOrPanned(chart);
284✔
86
  },
87

88
  beforeEvent(chart) {
89
    const state = getState(chart);
6✔
90
    if (state.panning || state.dragging) {
6!
91
      // cancel any event handling while panning or dragging
92
      return false;
6✔
93
    }
94
  },
95

96
  beforeUpdate: function(chart, args, options) {
97
    const state = getState(chart);
1,488✔
98
    state.options = options;
1,488✔
99
    addListeners(chart, options);
1,488✔
100
  },
101

102
  beforeDatasetsDraw(chart, _args, options) {
103
    draw(chart, 'beforeDatasetsDraw', options);
1,492✔
104
  },
105

106
  afterDatasetsDraw(chart, _args, options) {
107
    draw(chart, 'afterDatasetsDraw', options);
1,492✔
108
  },
109

110
  beforeDraw(chart, _args, options) {
111
    draw(chart, 'beforeDraw', options);
1,492✔
112
  },
113

114
  afterDraw(chart, _args, options) {
115
    draw(chart, 'afterDraw', options);
1,492✔
116
  },
117

118
  stop: function(chart) {
119
    removeListeners(chart);
9,895✔
120

121
    if (Hammer) {
9,895!
122
      stopHammer(chart);
9,895✔
123
    }
124
    removeState(chart);
9,895✔
125
  },
126

127
  panFunctions,
128
  zoomFunctions,
129
  zoomRectFunctions,
130
};
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