-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathget_update_object.js
58 lines (41 loc) · 1.29 KB
/
get_update_object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var d3 = require('d3');
var Lib = require('../../lib');
module.exports = function getUpdateObject(axisLayout, buttonLayout) {
var axName = axisLayout._name;
var update = {};
if(buttonLayout.step === 'all') {
update[axName + '.autorange'] = true;
}
else {
var xrange = getXRange(axisLayout, buttonLayout);
update[axName + '.range[0]'] = xrange[0];
update[axName + '.range[1]'] = xrange[1];
}
return update;
};
function getXRange(axisLayout, buttonLayout) {
var currentRange = axisLayout.range;
var base = new Date(Lib.dateTime2ms(currentRange[1]));
var step = buttonLayout.step,
count = buttonLayout.count;
var range0;
switch(buttonLayout.stepmode) {
case 'backward':
range0 = Lib.ms2DateTime(+d3.time[step].offset(base, -count));
break;
case 'todate':
var base2 = d3.time[step].offset(base, -count);
range0 = Lib.ms2DateTime(+d3.time[step].ceil(base2));
break;
}
var range1 = currentRange[1];
return [range0, range1];
}