Best JavaScript code snippet using wpt
tooltipServiceWrapper.ts
Source:tooltipServiceWrapper.ts
1//module powerbi.extensibility.visual {2import powerbi from "powerbi-visuals-api";3import VisualTooltipDataItem = powerbi.extensibility.VisualTooltipDataItem;4import ITooltipService = powerbi.extensibility.ITooltipService;5import ISelectionId = powerbi.extensibility.ISelectionId;6import * as d3 from "d3";7export interface TooltipEventArgs<TData> {8 data: TData;9 coordinates: number[];10 elementCoordinates: number[];11 context: HTMLElement;12 isTouchEvent: boolean;13}14export interface ITooltipServiceWrapper {15 addTooltip<T>(16 selection: d3.Selection<any, any, any, any>,17 getTooltipInfoDelegate: (args: TooltipEventArgs<T>) => VisualTooltipDataItem[],18 getDataPointIdentity: (args: TooltipEventArgs<T>) => ISelectionId,19 reloadTooltipDataOnMouseMove?: boolean): void;20 hide(): void;21}22const DefaultHandleTouchDelay = 1000;23export function createTooltipServiceWrapper(tooltipService: ITooltipService, rootElement: any, handleTouchDelay: number = DefaultHandleTouchDelay): ITooltipServiceWrapper {24 return new TooltipServiceWrapper(tooltipService, rootElement, handleTouchDelay);25}26class TooltipServiceWrapper implements ITooltipServiceWrapper {27 private handleTouchTimeoutId: number;28 private visualHostTooltipService: ITooltipService;29 private rootElement: any;30 private handleTouchDelay: number;31 constructor(tooltipService: ITooltipService, rootElement: any, handleTouchDelay: number) {32 this.visualHostTooltipService = tooltipService;33 this.handleTouchDelay = handleTouchDelay;34 this.rootElement = rootElement;35 }36 public addTooltip<T>(37 selection: d3.Selection<any, any, any, any>,38 getTooltipInfoDelegate: (args: TooltipEventArgs<T>) => VisualTooltipDataItem[],39 getDataPointIdentity: (args: TooltipEventArgs<T>) => ISelectionId,40 reloadTooltipDataOnMouseMove?: boolean): void {41 if (!selection || !this.visualHostTooltipService.enabled()) {42 return;43 }44 //mouse event45 this.mouseEvent(selection,getTooltipInfoDelegate, getDataPointIdentity, reloadTooltipDataOnMouseMove);46 //touch event47 this.touchEvent(selection,getTooltipInfoDelegate, getDataPointIdentity, reloadTooltipDataOnMouseMove);48 }49 private mouseEvent<T>(selection: d3.Selection<any, any, any, any>,50 getTooltipInfoDelegate: (args: TooltipEventArgs<T>) => VisualTooltipDataItem[],51 getDataPointIdentity: (args: TooltipEventArgs<T>) => ISelectionId,52 reloadTooltipDataOnMouseMove?: boolean) {53 let rootNode = this.rootElement;54 // Mouse events55 selection.on("mouseover.tooltip", () => {56 // Ignore mouseover while handling touch events57 if (!this.canDisplayTooltip(d3.event))58 return;59 let tooltipEventArgs = this.makeTooltipEventArgs<T>(rootNode, true, false);60 if (!tooltipEventArgs)61 return;62 let tooltipInfo = getTooltipInfoDelegate(tooltipEventArgs);63 if (tooltipInfo == null)64 return;65 let selectionId = getDataPointIdentity(tooltipEventArgs);66 this.visualHostTooltipService.show({67 coordinates: tooltipEventArgs.coordinates,68 isTouchEvent: false,69 dataItems: tooltipInfo,70 identities: selectionId ? [selectionId] : [],71 });72 });73 selection.on("mouseout.tooltip", () => {74 this.visualHostTooltipService.hide({75 isTouchEvent: false,76 immediately: false,77 });78 });79 selection.on("mousemove.tooltip", () => {80 // Ignore mousemove while handling touch events81 if (!this.canDisplayTooltip(d3.event))82 return;83 let tooltipEventArgs = this.makeTooltipEventArgs<T>(rootNode, true, false);84 if (!tooltipEventArgs)85 return;86 let tooltipInfo: VisualTooltipDataItem[];87 if (reloadTooltipDataOnMouseMove) {88 tooltipInfo = getTooltipInfoDelegate(tooltipEventArgs);89 if (tooltipInfo == null)90 return;91 }92 let selectionId = getDataPointIdentity(tooltipEventArgs);93 this.visualHostTooltipService.move({94 coordinates: tooltipEventArgs.coordinates,95 isTouchEvent: false,96 dataItems: tooltipInfo,97 identities: selectionId ? [selectionId] : [],98 });99 });100 }101 private touchEvent<T>(selection: d3.Selection<any, any, any, any>,102 getTooltipInfoDelegate: (args: TooltipEventArgs<T>) => VisualTooltipDataItem[],103 getDataPointIdentity: (args: TooltipEventArgs<T>) => ISelectionId,104 reloadTooltipDataOnMouseMove?: boolean) {105 let rootNode = this.rootElement;106 // --- Touch events ---107 let touchStartEventName: string = TooltipServiceWrapper.touchStartEventName();108 let touchEndEventName: string = TooltipServiceWrapper.touchEndEventName();109 let isPointerEvent: boolean = TooltipServiceWrapper.usePointerEvents();110 selection.on(touchStartEventName + '.tooltip', () => {111 this.visualHostTooltipService.hide({112 isTouchEvent: true,113 immediately: true,114 });115 let tooltipEventArgs = this.makeTooltipEventArgs<T>(rootNode, isPointerEvent, true);116 if (!tooltipEventArgs)117 return;118 let tooltipInfo = getTooltipInfoDelegate(tooltipEventArgs);119 let selectionId = getDataPointIdentity(tooltipEventArgs);120 this.visualHostTooltipService.show({121 coordinates: tooltipEventArgs.coordinates,122 isTouchEvent: true,123 dataItems: tooltipInfo,124 identities: selectionId ? [selectionId] : [],125 });126 });127 selection.on(touchEndEventName + '.tooltip', () => {128 this.visualHostTooltipService.hide({129 isTouchEvent: true,130 immediately: false,131 });132 if (this.handleTouchTimeoutId)133 clearTimeout(this.handleTouchTimeoutId);134 // At the end of touch action, set a timeout that will let us ignore the incoming mouse events for a small amount of time 135 this.handleTouchTimeoutId = window.setTimeout(() => {136 this.handleTouchTimeoutId = undefined;137 }, this.handleTouchDelay); 138 });139 }140 public hide(): void {141 this.visualHostTooltipService.hide({ immediately: true, isTouchEvent: false });142 }143 private makeTooltipEventArgs<T>(rootNode: any, isPointerEvent: boolean, isTouchEvent: boolean): TooltipEventArgs<T> {144 let target = <HTMLElement>(<Event>d3.event).target;145 let data: any = d3.select(target).datum();146 let mouseCoordinates = this.getCoordinates(rootNode, isPointerEvent);147 let elementCoordinates: number[] = this.getCoordinates(target, isPointerEvent);148 return {149 data: data,150 coordinates: mouseCoordinates,151 elementCoordinates: elementCoordinates,152 context: target,153 isTouchEvent: isTouchEvent154 };155 /*let tooltipEventArgs: TooltipEventArgs<T> = {156 data: data,157 coordinates: mouseCoordinates,158 elementCoordinates: elementCoordinates,159 context: target,160 isTouchEvent: isTouchEvent161 };*/162 //return tooltipEventArgs;163 }164 private canDisplayTooltip(d3Event: any): boolean {165 let canDisplay: boolean = true;166 let mouseEvent: MouseEvent = <MouseEvent>d3Event;167 if (mouseEvent.buttons !== undefined) {168 // Check mouse buttons state169 let hasMouseButtonPressed = mouseEvent.buttons !== 0;170 canDisplay = !hasMouseButtonPressed;171 }172 // Make sure we are not ignoring mouse events immediately after touch end.173 canDisplay = canDisplay && (this.handleTouchTimeoutId == null);174 return canDisplay;175 }176 private getCoordinates(rootNode: any, isPointerEvent: boolean): number[] {177 let coordinates: number[];178 if (isPointerEvent) {179 // copied from d3_eventSource (which is not exposed)180 let e = <any>d3.event, s;181 while (s = e.sourceEvent) e = s;182 let rect = rootNode.getBoundingClientRect();183 coordinates = [e.clientX - rect.left - rootNode.clientLeft, e.clientY - rect.top - rootNode.clientTop];184 }185 else {186 let touchCoordinates = d3.touches(rootNode);187 if (touchCoordinates && touchCoordinates.length > 0) {188 coordinates = touchCoordinates[0];189 }190 }191 return coordinates;192 }193 private static touchStartEventName(): string {194 let eventName: string = "touchstart";195 if (window["PointerEvent"]) {196 // IE11197 eventName = "pointerdown";198 }199 return eventName;200 }201 private static touchMoveEventName(): string {202 let eventName: string = "touchmove";203 if (window["PointerEvent"]) {204 // IE11205 eventName = "pointermove";206 }207 return eventName;208 }209 private static touchEndEventName(): string {210 let eventName: string = "touchend";211 if (window["PointerEvent"]) {212 // IE11213 eventName = "pointerup";214 }215 return eventName;216 }217 private static usePointerEvents(): boolean {218 let eventName = TooltipServiceWrapper.touchStartEventName();219 return eventName === "pointerdown" || eventName === "MSPointerDown";220 }221}...
utils.js
Source:utils.js
...42var isPointerEvent = function(e) {43 return "pointer" === eventSource(e)44};45var isMouseEvent = function(e) {46 return isNativeMouseEvent(e) || (isPointerEvent(e) || isDxEvent(e)) && "mouse" === e.pointerType47};48var isTouchEvent = function(e) {49 return isNativeTouchEvent(e) || (isPointerEvent(e) || isDxEvent(e)) && "touch" === e.pointerType50};51var isKeyboardEvent = function(e) {52 return "keyboard" === eventSource(e)53};54var isFakeClickEvent = function(e) {55 return 0 === e.screenX && !e.offsetX && 0 === e.pageX56};57var eventData = function(e) {58 return {59 x: e.pageX,60 y: e.pageY,61 time: e.timeStamp62 }63};...
Using AI Code Generation
1function isPointerEvent(event) {2 if (window.PointerEvent && event instanceof window.PointerEvent) {3 return true;4 }5 if (window.MSPointerEvent && event instanceof window.MSPointerEvent) {6 return true;7 }8 event.pointerType === "mouse";9}10function isMouseEvent(event) {11 if (window.MouseEvent && event instanceof window.MouseEvent) {12 return true;13 }14 return event.pointerType === "mouse";15}16function isTouchEvent(event) {17 if (window.TouchEvent && event instanceof window.TouchEvent) {18 return true;19 }20 return event.pointerType === "touch";21}22function isPenEvent(event) {23 if (window.PointerEvent && event instanceof window.PointerEvent) {24 return event.pointerType === "pen";25 }26 if (window.MSPointerEvent && event instanceof window.MSPointerEvent) {27 return event.pointerType === "pen";28 }29 return false;30}31function isKeyboardEvent(event) {32 if (window.KeyboardEvent && event instanceof window.KeyboardEvent) {33 return true;34 }35 return event.pointerType === "keyboard";36}37function isPointerEvent(event) {38 if (window.PointerEvent && event instanceof window.PointerEvent) {39 return true;40 }41 if (window.MSPointerEvent && event instanceof window.MSPointerEvent) {42 return true;43 }44 event.pointerType === "mouse";45}46function isMouseEvent(event) {47 if (window.MouseEvent && event instanceof window.MouseEvent) {48 return true;49 }50 return event.pointerType === "mouse";51}52function isTouchEvent(event) {53 if (window.TouchEvent && event instanceof window.TouchEvent) {54 return true;55 }56 return event.pointerType === "touch";57}
Using AI Code Generation
1var wptools = require('wptools');2wptools.isPointerEvent('pointerdown');3var wptools = require('wptools');4wptools.isPointerEvent('pointerUp');5var wptools = require('wptools');6wptools.isPointerEvent('pointermove');7var wptools = require('wptools');8wptools.isPointerEvent('pointerenter');9var wptools = require('wptools');10wptools.isPointerEvent('pointerleave');11var wptools = require('wptools');12wptools.isPointerEvent('pointercancel');13var wptools = require('wptools');14wptools.isPointerEvent('pointerout');15var wptools = require('wptools');16wptools.isPointerEvent('pointerover');17var wptools = require('wptools');18wptools.isPointerEvent('pointerup');19var wptools = require('wptools');20wptools.isPointerEvent('pointerDown');21var wptools = require('wptools');22wptools.isPointerEvent('pointerUp');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.isPointerEvent(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.runTest('www.google.com', {location: 'Dulles:Chrome', connectivity: 'Cable', pollResults: 5}, function(err, data) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) {23 console.log('Error: ' + err);24 } else {25 console.log(data);26 }27});
Using AI Code Generation
1function isPointerEvent(event) {2 return event.pointerType === 'touch' || event.pointerType === 'pen';3}4function isMouseEvent(event) {5 return event.pointerType === 'mouse';6}7function isTouchEvent(event) {8 return event.pointerType === 'touch';9}10function isPenEvent(event) {11 return event.pointerType === 'pen';12}13function isTouchOrPenEvent(event) {14 return event.pointerType === 'touch' || event.pointerType === 'pen';15}16function isMouseOrPenEvent(event) {17 return event.pointerType === 'mouse' || event.pointerType === 'pen';18}19function isMouseOrTouchEvent(event) {20 return event.pointerType === 'mouse' || event.pointerType === 'touch';21}22function isMouseOrTouchOrPenEvent(event) {23 return event.pointerType === 'mouse' || event.pointerType === 'touch' || event.pointerType === 'pen';24}25function isMouseEventOrPenEvent(event) {26 return event.pointerType === 'mouse' || event.pointerType === 'pen';27}28function isTouchEventOrPenEvent(event) {29 return event.pointerType === 'touch' || event.pointerType === 'pen';30}31function isMouseEventOrTouchEvent(event) {32 return event.pointerType === 'mouse' || event.pointerType === 'touch';33}34function isMouseEventOrTouchOrPenEvent(event) {35 return event.pointerType === 'mouse' || event.pointerType === 'touch' || event.pointerType === 'pen';36}37function isMouseOrTouchOrPenEvent(event) {
Using AI Code Generation
1var wptools = require("wptools");2var wp = new wptools();3wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {4 console.log("isPointerEvent: " + isPointerEvent);5});6var wptools = require("wptools");7var wp = new wptools();8wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {9 console.log("isPointerEvent: " + isPointerEvent);10});11var wptools = require("wptools");12var wp = new wptools();13wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {14 console.log("isPointerEvent: " + isPointerEvent);15});16var wptools = require("wptools");17var wp = new wptools();18wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {19 console.log("isPointerEvent: " + isPointerEvent);20});21var wptools = require("wptools");22var wp = new wptools();23wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {24 console.log("isPointerEvent: " + isPointerEvent);25});26var wptools = require("wptools");27var wp = new wptools();28wp.isPointerEvent("pointerdown", function(err, isPointerEvent) {29 console.log("isPointerEvent: " + isPointerEvent);30});31var wptools = require("wptools");32var wp = new wptools();
Using AI Code Generation
1function runTest() {2 var test = async_test("isPointerEvent method of wptCommon.js");3 test.step(function () {4 assert_true(wptCommon.isPointerEvent('pointerdown'));5 assert_true(wptCommon.isPointerEvent('pointerup'));6 assert_true(wptCommon.isPointerEvent('pointermove'));7 assert_true(wptCommon.isPointerEvent('pointercancel'));8 assert_true(wptCommon.isPointerEvent('pointerover'));9 assert_true(wptCommon.isPointerEvent('pointerout'));10 assert_true(wptCommon.isPointerEvent('pointerenter'));11 assert_true(wptCommon.isPointerEvent('pointerleave'));12 assert_true(wptCommon.isPointerEvent('gotpointercapture'));13 assert_true(wptCommon.isPointerEvent('lostpointercapture'));14 assert_false(wptCommon.isPointerEvent('pointerover'));15 assert_false(wptCommon.isPointerEvent('pointerout'));16 assert_false(wptCommon.isPointerEvent('pointerenter'));17 assert_false(wptCommon.isPointerEvent('pointerleave'));18 test.done();19 });20}
Using AI Code Generation
1var wptools = require('wp-tools');2var isPointerEventSupported = wptools.isPointerEventSupported();3console.log(isPointerEventSupported);4var wptools = require('wp-tools');5var isPointerEventSupported = wptools.isPointerEventSupported();6console.log(isPointerEventSupported);
Using AI Code Generation
1function isPointerEventSupported() {2 return window.navigator.msPointerEnabled;3}4if (isPointerEventSupported()) {5}6if (!isPointerEventSupported()) {7}8function isPointerEventSupported() {9 return window.navigator.msPointerEnabled;10}11if (isPointerEventSupported()) {12}13if (!isPointerEventSupported()) {14}15function isPointerEventSupported() {16 return window.navigator.msPointerEnabled;17}18if (isPointerEventSupported()) {19}20if (!isPointerEventSupported()) {21}22function isPointerEventSupported() {23 return window.navigator.msPointerEnabled;24}25if (isPointerEventSupported()) {26}27if (!isPointerEventSupported()) {28}29function isPointerEventSupported() {30 return window.navigator.msPointerEnabled;31}32if (isPointerEventSupported()) {33}34if (!isPointerEventSupported()) {35}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!