| 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 |
|
| 19 |
export class FigureModel extends widgets.DOMWidgetModel { |
| 20 |
defaults() { |
| 21 |
return { |
| 22 |
...widgets.DOMWidgetModel.prototype.defaults(), |
| 23 |
_model_name: 'FigureModel', |
| 24 |
_view_name: 'Figure', |
| 25 |
_model_module: 'bqplot', |
| 26 |
_view_module: 'bqplot', |
| 27 |
_model_module_version: semver_range, |
| 28 |
_view_module_version: semver_range, |
| 29 |
|
| 30 |
title: '', |
| 31 |
axes: [], |
| 32 |
marks: [], |
| 33 |
interaction: null, |
| 34 |
scale_x: undefined, |
| 35 |
scale_y: undefined, |
| 36 |
title_style: {}, |
| 37 |
background_style: {}, |
| 38 |
legend_style: {}, |
| 39 |
legend_text: {}, |
| 40 |
theme: 'classic', |
| 41 |
|
| 42 |
min_aspect_ratio: 0.01, |
| 43 |
max_aspect_ratio: 100, |
| 44 |
pixel_ratio: null, |
| 45 |
|
| 46 |
fig_margin: { |
| 47 |
top: 60, |
| 48 |
bottom: 60, |
| 49 |
left: 60, |
| 50 |
right: 60, |
| 51 |
}, |
| 52 |
|
| 53 |
padding_x: 0.0, |
| 54 |
padding_y: 0.025, |
| 55 |
legend_location: 'top-right', |
| 56 |
animation_duration: 0, |
| 57 |
}; |
| 58 |
} |
| 59 |
|
| 60 |
initialize(attributes, options) { |
| 61 |
super.initialize(attributes, options); |
| 62 |
this.on('msg:custom', this.handle_custom_messages, this); |
| 63 |
} |
| 64 |
|
| 65 |
handle_custom_messages(msg) { |
| 66 |
if (msg.type === 'save_png') { |
| 67 |
this.trigger('save_png', msg.filename, msg.scale); |
| 68 |
} else if (msg.type === 'save_svg') { |
| 69 |
this.trigger('save_svg', msg.filename); |
| 70 |
} else if (msg.type === 'upload_png') { |
| 71 |
this.trigger('upload_png', this, msg.scale); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
save_png() { |
| 76 |
// TODO: Any view of this Figure model will pick up this event |
| 77 |
// and render a png. Remove this eventually. |
| 78 |
this.trigger('save_png'); |
| 79 |
} |
| 80 |
|
| 81 |
static serializers = { |
| 82 |
...widgets.DOMWidgetModel.serializers, |
| 83 |
marks: { deserialize: widgets.unpack_models }, |
| 84 |
axes: { deserialize: widgets.unpack_models }, |
| 85 |
interaction: { deserialize: widgets.unpack_models }, |
| 86 |
scale_x: { deserialize: widgets.unpack_models }, |
| 87 |
scale_y: { deserialize: widgets.unpack_models }, |
| 88 |
layout: { deserialize: widgets.unpack_models }, |
| 89 |
}; |
| 90 |
} |