MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / position_cursor

Method position_cursor

site-packages/matplotlib/widgets.py:852–876  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

850 self._notify_submit_observers()
851
852 def position_cursor(self, x):
853 # now, we have to figure out where the cursor goes.
854 # approximate it based on assuming all characters the same length
855 if len(self.text) == 0:
856 self.cursor_index = 0
857 else:
858 bb = self.text_disp.get_window_extent()
859
860 trans = self.ax.transData
861 inv = self.ax.transData.inverted()
862 bb = trans.transform(inv.transform(bb))
863
864 text_start = bb[0, 0]
865 text_end = bb[1, 0]
866
867 ratio = (x - text_start) / (text_end - text_start)
868
869 if ratio < 0:
870 ratio = 0
871 if ratio > 1:
872 ratio = 1
873
874 self.cursor_index = int(len(self.text) * ratio)
875
876 self._rendercursor()
877
878 def _click(self, event):
879 if self.ignore(event):

Callers 1

_clickMethod · 0.95

Calls 4

_rendercursorMethod · 0.95
get_window_extentMethod · 0.45
invertedMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected