@cryptotaxi247 / netdata-1 / commits / 632558865

touch interface of dygraphs restored

Costa Tsaousis (ktsaou) committed Dec 21, 2015 at 23:45 UTC 632558865bfb5bcdd08f18cdaef64cb6dfa99649
1 file changed +39 -8
web/dashboard.js
+39 -8
@@ -3059,25 +3059,56 @@
3059 if(NETDATA.options.debug.dygraph === true || state.debug === true)
3060 state.log('interactionModel.touchstart()');
3061
3062 - state.globalSelectionSyncStop();
3063 - state.globalSelectionSyncDelay();
3064 - Dygraph.Interaction.startTouch(event, dygraph, context);
3065 - context.touchDirections = { x: true, y: false };
3062 state.setMode('zoom');
3063 + state.pauseChart();
3064 +
3065 + Dygraph.defaultInteractionModel.touchstart(event, dygraph, context);
3066 +
3067 + // we overwrite the touch directions at the end, to overwrite
3068 + // the internal default of dygraphs
3069 + context.touchDirections = { x: true, y: false };
3070 +
3071 + state.dygraph_last_touch_start = new Date().getTime();
3072 + state.dygraph_last_touch_move = 0;
3073 +
3074 + if(typeof event.touches[0].pageX === 'number')
3075 + state.dygraph_last_touch_page_x = event.touches[0].pageX;
3076 + else
3077 + state.dygraph_last_touch_page_x = 0;
3078 },
3079 touchmove: function(event, dygraph, context) {
3080 if(NETDATA.options.debug.dygraph === true || state.debug === true)
3081 state.log('interactionModel.touchmove()');
3082
3072 - //Dygraph.cancelEvent(event);
3073 - state.globalSelectionSyncStop();
3074 - Dygraph.Interaction.moveTouch(event, dygraph, context);
3083 + Dygraph.defaultInteractionModel.touchmove(event, dygraph, context);
3084 +
3085 + state.dygraph_last_touch_move = new Date().getTime();
3086 },
3087 touchend: function(event, dygraph, context) {
3088 if(NETDATA.options.debug.dygraph === true || state.debug === true)
3089 state.log('interactionModel.touchend()');
3090
3080 - Dygraph.Interaction.endTouch(event, dygraph, context);
3091 + Dygraph.defaultInteractionModel.touchend(event, dygraph, context);
3092 +
3093 + var now = new Date().getTime();
3094 + if(typeof state.dygraph_last_touch_end !== 'undefined') {
3095 + if(state.dygraph_last_touch_move === 0) {
3096 + var dt = now - state.dygraph_last_touch_end;
3097 + if(dt <= 250) {
3098 + state.globalSelectionSyncStop();
3099 + NETDATA.globalPanAndZoom.clearMaster();
3100 + state.resetChart();
3101 + }
3102 + else if(state.dygraph_last_touch_move === 0 && state.dygraph_last_touch_page_x !== 0) {
3103 + // internal api of dygraphs
3104 + var pct = (state.dygraph_last_touch_page_x - (dygraph.plotter_.area.x + state.element.getBoundingClientRect().left)) / dygraph.plotter_.area.w;
3105 + var t = Math.round(state.current.after_ms + (state.current.before_ms - state.current.after_ms) * pct);
3106 + if(NETDATA.dygraphSetSelection(state, t) === true)
3107 + state.globalSelectionSync(t);
3108 + }
3109 + }
3110 + }
3111 + state.dygraph_last_touch_end = now;
3112 }
3113 }
3114 };