How to use transform_xy method in Airtest

Best Python code snippet using Airtest

grid_helper_curvelinear.py

Source:grid_helper_curvelinear.py Github

copy

Full Screen

...107 #e1, e2 = self._extremes # ranges of other coordinates108 if self.nth_coord == 0:109 xx0 = np.linspace(self.value, self.value, self._line_num_points)110 yy0 = np.linspace(extremes[2], extremes[3], self._line_num_points)111 xx, yy = grid_finder.transform_xy(xx0, yy0)112 elif self.nth_coord == 1:113 xx0 = np.linspace(extremes[0], extremes[1], self._line_num_points)114 yy0 = np.linspace(self.value, self.value, self._line_num_points)115 xx, yy = grid_finder.transform_xy(xx0, yy0)116 grid_info["line_xy"] = xx, yy117 self.grid_info = grid_info118 def get_axislabel_transform(self, axes):119 return Affine2D() #axes.transData120 def get_axislabel_pos_angle(self, axes):121 extremes = self.grid_info["extremes"]122 if self.nth_coord == 0:123 xx0 = self.value124 yy0 = (extremes[2]+extremes[3])/2.125 dxx, dyy = 0., abs(extremes[2]-extremes[3])/1000.126 elif self.nth_coord == 1:127 xx0 = (extremes[0]+extremes[1])/2.128 yy0 = self.value129 dxx, dyy = abs(extremes[0]-extremes[1])/1000., 0.130 grid_finder = self.grid_helper.grid_finder131 xx1, yy1 = grid_finder.transform_xy([xx0], [yy0])132 trans_passingthrough_point = axes.transData + axes.transAxes.inverted()133 p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]])134 if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:135 xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]])136 xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy])137 xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]])138 return (xx1c, yy1c), np.arctan2(yy2c-yy1c, xx2c-xx1c)/np.pi*180.139 else:140 return None, None141 def get_tick_transform(self, axes):142 return IdentityTransform() #axes.transData143 def get_tick_iterators(self, axes):144 """tick_loc, tick_angle, tick_label, (optionally) tick_label"""145 grid_finder = self.grid_helper.grid_finder146 lat_levs, lat_n, lat_factor = self.grid_info["lat_info"]147 lat_levs = np.asarray(lat_levs)148 if lat_factor is not None:149 yy0 = lat_levs / lat_factor150 dy = 0.01 / lat_factor151 else:152 yy0 = lat_levs153 dy = 0.01154 lon_levs, lon_n, lon_factor = self.grid_info["lon_info"]155 lon_levs = np.asarray(lon_levs)156 if lon_factor is not None:157 xx0 = lon_levs / lon_factor158 dx = 0.01 / lon_factor159 else:160 xx0 = lon_levs161 dx = 0.01162 if None in self._extremes:163 e0, e1 = self._extremes164 else:165 e0, e1 = sorted(self._extremes)166 if e0 is None:167 e0 = -np.inf168 if e1 is None:169 e1 = np.inf170 if self.nth_coord == 0:171 mask = (e0 <= yy0) & (yy0 <= e1)172 #xx0, yy0 = xx0[mask], yy0[mask]173 yy0 = yy0[mask]174 elif self.nth_coord == 1:175 mask = (e0 <= xx0) & (xx0 <= e1)176 #xx0, yy0 = xx0[mask], yy0[mask]177 xx0 = xx0[mask]178 def transform_xy(x, y):179 x1, y1 = grid_finder.transform_xy(x, y)180 x2y2 = axes.transData.transform(np.array([x1, y1]).transpose())181 x2, y2 = x2y2.transpose()182 return x2, y2183 # find angles184 if self.nth_coord == 0:185 xx0 = np.empty_like(yy0)186 xx0.fill(self.value)187 xx1, yy1 = transform_xy(xx0, yy0)188 xx00 = xx0.copy()189 xx00[xx0+dx>e1] -= dx190 xx1a, yy1a = transform_xy(xx00, yy0)191 xx1b, yy1b = transform_xy(xx00+dx, yy0)192 xx2a, yy2a = transform_xy(xx0, yy0)193 xx2b, yy2b = transform_xy(xx0, yy0+dy)194 labels = self.grid_info["lat_labels"]195 labels = [l for l, m in zip(labels, mask) if m]196 elif self.nth_coord == 1:197 yy0 = np.empty_like(xx0)198 yy0.fill(self.value)199 xx1, yy1 = transform_xy(xx0, yy0)200 xx1a, yy1a = transform_xy(xx0, yy0)201 xx1b, yy1b = transform_xy(xx0, yy0+dy)202 xx00 = xx0.copy()203 xx00[xx0+dx>e1] -= dx204 xx2a, yy2a = transform_xy(xx00, yy0)205 xx2b, yy2b = transform_xy(xx00+dx, yy0)206 labels = self.grid_info["lon_labels"]207 labels = [l for l, m in zip(labels, mask) if m]208 def f1():209 dd = np.arctan2(yy1b-yy1a, xx1b-xx1a) # angle normal210 dd2 = np.arctan2(yy2b-yy2a, xx2b-xx2a) # angle tangent211 mm = ((yy1b-yy1a)==0.) & ((xx1b-xx1a)==0.) # mask where dd1 is not defined212 dd[mm] = dd2[mm] + np.pi / 2213 #dd = np.arctan2(yy2-yy1, xx2-xx1) # angle normal214 #dd2 = np.arctan2(yy3-yy1, xx3-xx1) # angle tangent215 #mm = ((yy2-yy1)==0.) & ((xx2-xx1)==0.) # mask where dd1 is not defined216 #dd[mm] = dd2[mm] + np.pi / 2217 #dd += np.pi218 #dd = np.arctan2(xx2-xx1, angle_tangent-yy1)219 trans_tick = self.get_tick_transform(axes)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful