| 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 { ScaleModel } from './ScaleModel'; |
| 18 |
|
| 19 |
export class Scale extends widgets.WidgetView { |
| 20 |
render() { |
| 21 |
this.offset = 0; |
| 22 |
} |
| 23 |
|
| 24 |
create_event_listeners() { |
| 25 |
this.listenTo(this.model, 'domain_changed', this.model_domain_changed); |
| 26 |
this.listenTo(this.model, 'highlight_axis', this.highlight_axis); |
| 27 |
this.listenTo(this.model, 'unhighlight_axis', this.unhighlight_axis); |
| 28 |
} |
| 29 |
|
| 30 |
set_range(range, padding?) { |
| 31 |
this.scale.range(range); |
| 32 |
} |
| 33 |
|
| 34 |
compute_and_set_domain(array, id) { |
| 35 |
this.model.compute_and_set_domain(array, id); |
| 36 |
} |
| 37 |
|
| 38 |
set_domain(array, id) { |
| 39 |
this.model.set_domain(array, id); |
| 40 |
} |
| 41 |
|
| 42 |
model_domain_changed() { |
| 43 |
this.scale.domain(this.model.domain); |
| 44 |
this.trigger('domain_changed'); |
| 45 |
} |
| 46 |
|
| 47 |
highlight_axis() { |
| 48 |
this.trigger('highlight_axis'); |
| 49 |
} |
| 50 |
|
| 51 |
unhighlight_axis() { |
| 52 |
this.trigger('unhighlight_axis'); |
| 53 |
} |
| 54 |
|
| 55 |
expand_domain(old_range, new_range) { |
| 56 |
// Base class function. No implementation. |
| 57 |
// Implementation is particular to the child class |
| 58 |
// if you have a current range and then a new range and want to |
| 59 |
// expand the domain to expand to the new range but keep it |
| 60 |
// consistent with the previous one, this is the function you use. |
| 61 |
} |
| 62 |
|
| 63 |
offset: number; |
| 64 |
scale: |
| 65 |
| d3.ScaleTime<Date, number> |
| 66 |
| d3.ScaleOrdinal<string, number> |
| 67 |
| d3.ScaleBand<string> |
| 68 |
| d3.ScaleLinear<number, number> |
| 69 |
| d3.ScaleLogarithmic<number, number>; |
| 70 |
|
| 71 |
// Overriding super class |
| 72 |
model: widgets.WidgetModel & ScaleModel; |
| 73 |
} |