У меня есть фигура-заполнитель и несколько конечных фигур. Каждая end_shape представляет собой форму страны на карте. Фигуры стран являются частью групповой фигуры под названием «Карта».
Я хочу, чтобы конечная точка соединителя располагалась в центре страны. Соединитель начинается от края заполнителя таблицы до центра страны end_shape.
Моя проблема в том, что весь соединитель кажется слишком большим, и его конечная точка не совпадает с центром страны.
код:
Код: Выделить всё
def add_connector(slide, end_shape, placeholder_idx):
placeholder = slide.placeholders[placeholder_idx]
end_center_x = end_shape.left + (end_shape.width // 2)
end_center_y = end_shape.top + (end_shape.height // 2)
connector = slide.shapes.add_connector(
MSO_CONNECTOR.ELBOW,
placeholder.left,
placeholder.top,
end_center_x,
end_center_y,
)
connector.begin_connect(placeholder, 3)
line_elem = connector.line._get_or_add_ln()
line_elem.append(
parse_xml(
''
)
)
connector.line.width = Pt(0.5)
connector.line.color.rgb = RGBColor(32, 64, 140)
return connector
def find_country_shape(slide, country_name):
map_shape = next(shape for shape in slide.shapes if shape.name == "Map")
return next(
(
shape
for shape in map_shape.shapes
if shape.name.lower() == country_name.lower()
),
None,
)
Код: Выделить всё
def add_connector(slide, end_shape, placeholder_idx):
placeholder = slide.placeholders[placeholder_idx]
scale_factor = 0.63
end_center_x = int(
placeholder.left
+ scale_factor * (end_shape.left + (end_shape.width // 2) - placeholder.left)
)
end_center_y = int(
placeholder.top
+ scale_factor * (end_shape.top + (end_shape.height // 2) - placeholder.top)
)
Подробнее здесь: https://stackoverflow.com/questions/790 ... f-subshape