| 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 _ from 'underscore'; |
| 17 |
|
| 18 |
import { LinearScaleModel } from './LinearScaleModel'; |
| 19 |
import { getDate } from './utils'; |
| 20 |
|
| 21 |
export class DateScaleModel extends LinearScaleModel { |
| 22 |
defaults() { |
| 23 |
return { |
| 24 |
...LinearScaleModel.prototype.defaults(), |
| 25 |
_model_name: 'DateScaleModel', |
| 26 |
_view_name: 'DateScale', |
| 27 |
min: null, |
| 28 |
max: null, |
| 29 |
}; |
| 30 |
} |
| 31 |
|
| 32 |
typedRange(values) { |
| 33 |
const ar: any = new Float64Array(values.map(Number)); |
| 34 |
ar.type = 'date'; |
| 35 |
return ar; |
| 36 |
} |
| 37 |
|
| 38 |
set_init_state() { |
| 39 |
this.type = 'date'; |
| 40 |
this.global_min = new Date().setTime(0); |
| 41 |
this.global_max = new Date(); |
| 42 |
} |
| 43 |
|
| 44 |
min_max_changed() { |
| 45 |
this.min = getDate(this.get('min')); |
| 46 |
this.max = getDate(this.get('max')); |
| 47 |
this.min_from_data = this.min === null; |
| 48 |
this.max_from_data = this.max === null; |
| 49 |
this.update_domain(); |
| 50 |
} |
| 51 |
} |