Debian Codegraph @

bqplot/js/src/ScaleModel.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 { WidgetModel } from '@jupyter-widgets/base';
17 import { semver_range } from './version';
18
19 export abstract class ScaleModel extends WidgetModel {
20 defaults() {
21 return {
22 ...WidgetModel.prototype.defaults(),
23 _model_name: 'ScaleModel',
24 _view_name: 'Scale',
25 _model_module: 'bqplot',
26 _view_module: 'bqplot',
27 _model_module_version: semver_range,
28 _view_module_version: semver_range,
29 reverse: false,
30 allow_padding: true,
31 };
32 }
33
34 initialize(attributes, options) {
35 super.initialize(attributes, options);
36 this.domains = {};
37 this.domain = [];
38 this.set_init_state();
39 this.set_listeners();
40 }
41
42 set_init_state() {
43 this.type = 'base';
44 }
45
46 set_listeners() {
47 // Function to be implemented by inherited classes.
48 }
49
50 set_domain(domain, id) {
51 // Call function only if you have computed the domain yourself. If
52 // you want the scale to compute the domain based on the data for
53 // your scale view, then call compute_and_set_domain
54 this.domains[id] = domain;
55 this.update_domain();
56 }
57
58 del_domain(domain, id) {
59 if (this.domains[id] !== undefined) {
60 delete this.domains[id];
61 this.update_domain();
62 }
63 }
64
65 get_domain_slice_in_order() {
66 if (this.reverse) {
67 return this.domain.slice().reverse();
68 } else {
69 return this.domain.slice();
70 }
71 }
72
73 abstract compute_and_set_domain(data_array, id);
74 abstract update_domain();
75
76 domains: any;
77 domain: any[];
78 reverse: boolean;
79 type: string;
80 }