-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathget_update_object.js
52 lines (39 loc) · 1.27 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
/**
* Copyright 2012-2021, 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('@plotly/d3');
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(axisLayout.r2l(currentRange[1]));
var step = buttonLayout.step;
var count = buttonLayout.count;
var range0;
switch(buttonLayout.stepmode) {
case 'backward':
range0 = axisLayout.l2r(+d3.time[step].utc.offset(base, -count));
break;
case 'todate':
var base2 = d3.time[step].utc.offset(base, -count);
range0 = axisLayout.l2r(+d3.time[step].utc.ceil(base2));
break;
}
var range1 = currentRange[1];
return [range0, range1];
}