| 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 |
tick_labels: null, |
| 37 |
scale: undefined, |
| 38 |
num_ticks: null, |
| 39 |
tick_values: [], |
| 40 |
offset: {}, |
| 41 |
label_location: 'middle', |
| 42 |
label_color: null, |
| 43 |
grid_color: null, |
| 44 |
color: null, |
| 45 |
label_offset: null, |
| 46 |
visible: true, |
| 47 |
tick_style: {}, |
| 48 |
tick_rotate: 0, |
| 49 |
}; |
| 50 |
} |
| 51 |
|
| 52 |
initialize(attributes, options) { |
| 53 |
super.initialize(attributes, options); |
| 54 |
this.on('change:side', this.validate_orientation, this); |
| 55 |
this.on('change:orientation', this.validate_side, this); |
| 56 |
this.validate_orientation(); |
| 57 |
this.validate_side(); |
| 58 |
} |
| 59 |
|
| 60 |
validate_side() { |
| 61 |
const orientation = this.get('orientation'); |
| 62 |
const side = this.get('side'); |
| 63 |
if (orientation === 'vertical') { |
| 64 |
if (side !== 'left' && side !== 'right') { |
| 65 |
this.set('side', 'left'); |
| 66 |
} |
| 67 |
} else { |
| 68 |
if (side !== 'bottom' && side !== 'top') { |
| 69 |
this.set('side', 'bottom'); |
| 70 |
} |
| 71 |
} |
| 72 |
this.save_changes(); |
| 73 |
} |
| 74 |
|
| 75 |
validate_orientation() { |
| 76 |
const side = this.get('side'); |
| 77 |
if (side) { |
| 78 |
if (side === 'left' || side === 'right') { |
| 79 |
this.set('orientation', 'vertical'); |
| 80 |
} else { |
| 81 |
this.set('orientation', 'horizontal'); |
| 82 |
} |
| 83 |
this.save_changes(); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
static serializers = { |
| 88 |
...widgets.WidgetModel.serializers, |
| 89 |
scale: { deserialize: widgets.unpack_models }, |
| 90 |
offset: { deserialize: widgets.unpack_models }, |
| 91 |
tick_values: serialize.array_or_json_serializer, |
| 92 |
}; |
| 93 |
} |
| 94 |
|
| 95 |
export class ColorAxisModel extends AxisModel { |
| 96 |
defaults() { |
| 97 |
return { |
| 98 |
...AxisModel.prototype.defaults(), |
| 99 |
_model_name: 'ColorAxisModel', |
| 100 |
_view_name: 'ColorAxis', |
| 101 |
}; |
| 102 |
} |
| 103 |
} |