Debian Codegraph @

bqplot/js/src/PanZoomModel.ts

raw
1 /* Copyright 2015 Bloomberg Finance L.P.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 import * as widgets from '@jupyter-widgets/base';
17 import { semver_range } from './version';
18 import * as _ from 'underscore';
19
20 export class PanZoomModel extends widgets.WidgetModel {
21 defaults() {
22 return {
23 ...widgets.WidgetModel.prototype.defaults(),
24 _model_name: 'PanZoomModel',
25 _view_name: 'PanZoom',
26 _model_module: 'bqplot',
27 _view_module: 'bqplot',
28 _model_module_version: semver_range,
29 _view_module_version: semver_range,
30 scales: {},
31 allow_pan: true,
32 allow_zoom: true,
33 };
34 }
35
36 initialize(attributes, options) {
37 super.initialize(attributes, options);
38 this.on('change:scales', this.snapshot_scales, this);
39 this.snapshot_scales();
40 }
41
42 reset_scales() {
43 widgets.resolvePromisesDict(this.get('scales')).then((scales: any) => {
44 _.each(
45 Object.keys(scales),
46 (k) => {
47 _.each(
48 scales[k],
49 (s: any, i) => {
50 s.set_state(this.scales_states[k][i]);
51 },
52 this
53 );
54 },
55 this
56 );
57 });
58 }
59
60 snapshot_scales() {
61 // Save the state of the scales.
62 widgets.resolvePromisesDict(this.get('scales')).then((scales: any) => {
63 this.scales_states = Object.keys(scales).reduce((obj, key) => {
64 obj[key] = scales[key].map((s) => {
65 return s.get_state();
66 });
67 return obj;
68 }, {});
69 });
70 }
71
72 static serializers = {
73 ...widgets.WidgetModel.serializers,
74 scales: { deserialize: widgets.unpack_models },
75 };
76
77 scales_states: { [key: string]: any[] };
78 }