MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / RRuleLocator

Class RRuleLocator

lib/matplotlib/dates.py:1140–1213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1138
1139
1140class RRuleLocator(DateLocator):
1141 # use the dateutil rrule instance
1142
1143 def __init__(self, o, tz=None):
1144 super().__init__(tz)
1145 self.rule = o
1146
1147 def __call__(self):
1148 # if no data have been set, this will tank with a ValueError
1149 try:
1150 dmin, dmax = self.viewlim_to_dt()
1151 except ValueError:
1152 return []
1153
1154 return self.tick_values(dmin, dmax)
1155
1156 def tick_values(self, vmin, vmax):
1157 start, stop = self._create_rrule(vmin, vmax)
1158 dates = self.rule.between(start, stop, True)
1159 if len(dates) == 0:
1160 return date2num([vmin, vmax])
1161 return self.raise_if_exceeds(date2num(dates))
1162
1163 def _create_rrule(self, vmin, vmax):
1164 # set appropriate rrule dtstart and until and return
1165 # start and end
1166 delta = relativedelta(vmax, vmin)
1167
1168 # We need to cap at the endpoints of valid datetime
1169 try:
1170 start = vmin - delta
1171 except (ValueError, OverflowError):
1172 # cap
1173 start = datetime.datetime(1, 1, 1, 0, 0, 0,
1174 tzinfo=datetime.timezone.utc)
1175
1176 try:
1177 stop = vmax + delta
1178 except (ValueError, OverflowError):
1179 # cap
1180 stop = datetime.datetime(9999, 12, 31, 23, 59, 59,
1181 tzinfo=datetime.timezone.utc)
1182
1183 self.rule.set(dtstart=start, until=stop)
1184
1185 return vmin, vmax
1186
1187 def _get_unit(self):
1188 # docstring inherited
1189 freq = self.rule._rrule._freq
1190 return self.get_unit_generic(freq)
1191
1192 @staticmethod
1193 def get_unit_generic(freq):
1194 if freq == YEARLY:
1195 return DAYS_PER_YEAR
1196 elif freq == MONTHLY:
1197 return DAYS_PER_MONTH

Callers 2

date_demo_rrule.pyFile · 0.90
get_locatorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…