Debian Codegraph @

js/src/DateColorScaleModel.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 { ColorScaleModel } from './ColorScaleModel';
17 import { getDate } from './utils';
18
19 export class DateColorScaleModel extends ColorScaleModel {
20 defaults() {
21 return {
22 ...ColorScaleModel.prototype.defaults(),
23 _model_name: 'DateColorScaleModel',
24 _view_name: 'DateColorScale',
25 min: null,
26 max: null,
27 mid: null,
28 };
29 }
30
31 set_init_state() {
32 this.type = 'date_color_linear';
33 this.color_range = [];
34 this.mid = null;
35 this.global_min = new Date().setTime(0);
36 this.global_max = new Date();
37 }
38
39 min_max_changed() {
40 this.min = getDate(this.get('min'));
41 this.max = getDate(this.get('max'));
42 this.min_from_data = this.min === null;
43 this.max_from_data = this.max === null;
44 this.update_domain();
45 }
46
47 protected toDomainType(value: number): Date {
48 return new Date(value);
49 }
50 }