MCPcopy Index your code
hub / github.com/plotly/plotly.py / axis_spanning_shape_annotation

Function axis_spanning_shape_annotation

plotly/shapeannotation.py:211–272  ·  view source on GitHub ↗

annotation: a go.layout.Annotation object, a dict describing an annotation, or None shape_type: one of 'vline', 'hline', 'vrect', 'hrect' and determines how the x, y, xanchor, and yanchor values are set. shape_args: the parameters used to draw the shape, which are used t

(annotation, shape_type, shape_args, kwargs)

Source from the content-addressed store, hash-verified

209
210
211def axis_spanning_shape_annotation(annotation, shape_type, shape_args, kwargs):
212 """
213 annotation: a go.layout.Annotation object, a dict describing an annotation, or None
214 shape_type: one of 'vline', 'hline', 'vrect', 'hrect' and determines how the
215 x, y, xanchor, and yanchor values are set.
216 shape_args: the parameters used to draw the shape, which are used to place the annotation
217 kwargs: a dictionary that was the kwargs of a
218 _process_multiple_axis_spanning_shapes spanning shapes call. Items in this
219 dict whose keys start with 'annotation_' will be extracted and the keys with
220 the 'annotation_' part stripped off will be used to assign properties of the
221 new annotation.
222
223 Property precedence:
224 The annotation's x, y, xanchor, and yanchor properties are set based on the
225 shape_type argument. Each property already specified in the annotation or
226 through kwargs will be left as is (not replaced by the value computed using
227 shape_type). Note that the xref and yref properties will in general get
228 overwritten if the result of this function is passed to an add_annotation
229 called with the row and col parameters specified.
230
231 Returns an annotation populated with fields based on the
232 annotation_position, annotation_ prefixed kwargs or the original annotation
233 passed in to this function.
234 """
235 # set properties based on annotation_ prefixed kwargs
236 prefix = "annotation_"
237 len_prefix = len(prefix)
238 annotation_keys = list(filter(lambda k: k.startswith(prefix), kwargs.keys()))
239 # If no annotation or annotation-key is specified, return None as we don't
240 # want an annotation in this case
241 if annotation is None and len(annotation_keys) == 0:
242 return None
243 # TODO: Would it be better if annotation were initialized to an instance of
244 # go.layout.Annotation ?
245 if annotation is None:
246 annotation = dict()
247 for k in annotation_keys:
248 if k == "annotation_position":
249 # don't set so that Annotation constructor doesn't complain
250 continue
251 subk = k[len_prefix:]
252 annotation[subk] = kwargs[k]
253 # set x, y, xanchor, yanchor based on shape_type and position
254 annotation_position = None
255 if "annotation_position" in kwargs.keys():
256 annotation_position = kwargs["annotation_position"]
257 if shape_type.endswith("line"):
258 shape_dict = annotation_params_for_line(
259 shape_type, shape_args, annotation_position
260 )
261 elif shape_type.endswith("rect"):
262 shape_dict = annotation_params_for_rect(
263 shape_type, shape_args, annotation_position
264 )
265 for k in shape_dict.keys():
266 # only set property derived from annotation_position if it hasn't already been set
267 # see above: this would be better as a go.layout.Annotation then the key
268 # would be checked for validity here (otherwise it is checked later,

Callers

nothing calls this directly

Calls 3

keysMethod · 0.45

Tested by

no test coverage detected