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

Function annotation_params_for_line

plotly/shapeannotation.py:81–143  ·  view source on GitHub ↗
(shape_type, shape_args, position)

Source from the content-addressed store, hash-verified

79
80
81def annotation_params_for_line(shape_type, shape_args, position):
82 # all x0, x1, y0, y1 are used to place the annotation, that way it could
83 # work with a slanted line
84 # even with a slanted line, there are the horizontal and vertical
85 # conventions of placing a shape
86 x0 = shape_args["x0"]
87 x1 = shape_args["x1"]
88 y0 = shape_args["y0"]
89 y1 = shape_args["y1"]
90 X = [x0, x1]
91 Y = [y0, y1]
92 R = "right"
93 T = "top"
94 L = "left"
95 C = "center"
96 B = "bottom"
97 M = "middle"
98 aY = max(Y)
99 iY = min(Y)
100 eY = _mean(Y)
101 aaY = _argmax(Y)
102 aiY = _argmin(Y)
103 aX = max(X)
104 iX = min(X)
105 eX = _mean(X)
106 aaX = _argmax(X)
107 aiX = _argmin(X)
108 position, pos_str = _prepare_position(position)
109 if shape_type == "vline":
110 if position == set(["top", "left"]):
111 return _df_anno(R, T, X[aaY], aY)
112 if position == set(["top", "right"]):
113 return _df_anno(L, T, X[aaY], aY)
114 if position == set(["top"]):
115 return _df_anno(C, B, X[aaY], aY)
116 if position == set(["bottom", "left"]):
117 return _df_anno(R, B, X[aiY], iY)
118 if position == set(["bottom", "right"]):
119 return _df_anno(L, B, X[aiY], iY)
120 if position == set(["bottom"]):
121 return _df_anno(C, T, X[aiY], iY)
122 if position == set(["left"]):
123 return _df_anno(R, M, eX, eY)
124 if position == set(["right"]):
125 return _df_anno(L, M, eX, eY)
126 elif shape_type == "hline":
127 if position == set(["top", "left"]):
128 return _df_anno(L, B, iX, Y[aiX])
129 if position == set(["top", "right"]):
130 return _df_anno(R, B, aX, Y[aaX])
131 if position == set(["top"]):
132 return _df_anno(C, B, eX, eY)
133 if position == set(["bottom", "left"]):
134 return _df_anno(L, T, iX, Y[aiX])
135 if position == set(["bottom", "right"]):
136 return _df_anno(R, T, aX, Y[aaX])
137 if position == set(["bottom"]):
138 return _df_anno(C, T, eX, eY)

Callers 1

Calls 5

_meanFunction · 0.85
_argmaxFunction · 0.85
_argminFunction · 0.85
_prepare_positionFunction · 0.85
_df_annoFunction · 0.85

Tested by

no test coverage detected