Debian Codegraph @

js/src/AxisModel.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 * as serialize from './serialize';
18 import { semver_range } from './version';
19
20 export class AxisModel extends widgets.WidgetModel {
21 defaults() {
22 return {
23 ...widgets.WidgetModel.prototype.defaults(),
24 _model_name: 'AxisModel',
25 _view_name: 'Axis',
26 _model_module: 'bqplot',
27 _view_module: 'bqplot',
28 _model_module_version: semver_range,
29 _view_module_version: semver_range,
30
31 orientation: 'horizontal',
32 side: null,
33 label: '',
34 grid_lines: 'solid',
35 tick_format: null,
36 scale: undefined,
37 num_ticks: null,
38 tick_values: [],
39 offset: {},
40 label_location: 'middle',
41 label_color: null,
42 grid_color: null,
43 color: null,
44 label_offset: null,
45 visible: true,
46 tick_style: {},
47 tick_rotate: 0,
48 };
49 }
50
51 initialize(attributes, options) {
52 super.initialize(attributes, options);
53 this.on('change:side', this.validate_orientation, this);
54 this.on('change:orientation', this.validate_side, this);
55 this.validate_orientation();
56 this.validate_side();
57 }
58
59 validate_side() {
60 const orientation = this.get('orientation');
61 const side = this.get('side');
62 if (orientation === 'vertical') {
63 if (side !== 'left' && side !== 'right') {
64 this.set('side', 'left');
65 }
66 } else {
67 if (side !== 'bottom' && side !== 'top') {
68 this.set('side', 'bottom');
69 }
70 }
71 this.save_changes();
72 }
73
74 validate_orientation() {
75 const side = this.get('side');
76 if (side) {
77 if (side === 'left' || side === 'right') {
78 this.set('orientation', 'vertical');
79 } else {
80 this.set('orientation', 'horizontal');
81 }
82 this.save_changes();
83 }
84 }
85
86 static serializers = {
87 ...widgets.WidgetModel.serializers,
88 scale: { deserialize: widgets.unpack_models },
89 offset: { deserialize: widgets.unpack_models },
90 tick_values: serialize.array_or_json_serializer,
91 };
92 }
93
94 export class ColorAxisModel extends AxisModel {
95 defaults() {
96 return {
97 ...AxisModel.prototype.defaults(),
98 _model_name: 'ColorAxisModel',
99 _view_name: 'ColorAxis',
100 };
101 }
102 }