Oh, I hate this issue. You will see the same thing in SimpleXML or JavaScript.
You can get around it by still using SimpleXML and a JavaScript extension.
The way to get around it is to use JavaScript extension to spy on the Reset button on the chart. That will tell you if the user as triggered the pan and zoom feature. You can download my app (Layer8Insight App for Splunk, https://splunkbase.splunk.com/app/3171/), and look at the JS file /appserver/static/dd-app-ux-session.js to see the whole code segment in context.
Here is one of the XML segments for one of my charts.
<selection>
<set token="time_dd_select_metrics.earliest">$start$</set>
<set token="time_dd_select_metrics.latest">$end$</set>
</selection>
Here is my code as it appears in that file. The gist is that you listen for changes to either one of those tokens, set a timer for a very short amount of time so that both values have time to update, and then check if the Reset button is present on the chart before changing the drilldown time token form.dd_time . Note, I have two charts that use the selection feature to change the drilldown time values, hence why you see another set of tokens time_dd_select_alerts.... . You can ignore that part and the passing of the chart id.
var pan_zoom_timer_is_on = 0;
// set timeout to evaluate pan-zoom time changes
function setPanZoomTimer(chart) {
if (!pan_zoom_timer_is_on) {
myVar = setTimeout(checkPanZoomBoundaries, 100, chart);
pan_zoom_timer_is_on = 1;
}
}
// see if pan-zoom feature is active in order to set the drilldown time
// based on the selected time range
function checkPanZoomBoundaries(chart) {
if (pan_zoom_timer_is_on) {
pan_zoom_timer_is_on = 0;
}
var ts_earliest, ts_latest;
if (chart === "chart_ux_plot") {
ts_earliest = appUtils.getToken("time_dd_select_metrics.earliest");
ts_latest = appUtils.getToken("time_dd_select_metrics.latest");
} else {
ts_earliest = appUtils.getToken("time_dd_select_alerts.earliest");
ts_latest = appUtils.getToken("time_dd_select_alerts.latest");
}
chart = "#" + chart;
// spy on the reset button on the charts to determine if the pan-zoom feature is active,
// which means the drilldown time should be adjusted
if ($(chart).find('[class*="btn-reset"]').length && ts_earliest > 0 && ts_latest > 0) {
appUtils.setToken("form.dd_time.earliest", ts_earliest);
appUtils.setToken("form.dd_time.latest", ts_latest);
setDrilldownButton("#btn_dd_enable", true);
appUtils.submitTokens();
}
}
// listen to changes in the pan-zoom values
defaultTokenModel.on("change:time_dd_select_metrics.earliest", function(model, value, options) {
setPanZoomTimer("chart_ux_plot");
});
defaultTokenModel.on("change:time_dd_select_metrics.latest", function(model, value, options) {
setPanZoomTimer("chart_ux_plot");
});
defaultTokenModel.on("change:time_dd_select_alerts.earliest", function(model, value, options) {
setPanZoomTimer("chart_ux_alerts_plot");
});
defaultTokenModel.on("change:time_dd_select_alerts.latest", function(model, value, options) {
setPanZoomTimer("chart_ux_alerts_plot");
});
I will be at .conf2017 presenting on this kind of thing. You can find my session here (http://conf.splunk.com/sessions/2017-sessions.html#tracks=Foundations&search=Ryan%20Thibodeaux&). I actually call out this example in my appendix. Would be happy to talk if you are going and can attend.
... View more