Skip to content

Commit ef4a569

Browse files
committed
Add dendrogram link-type toggle buttons
Inject a new JavaScript block that renders link-type controls for treegraph/dendrogram charts. The added injectLinkTypeButtonsJS creates three buttons (Orthogonal/default, Straight, Curved) using the chart renderer, applies inactive/active styling, updates series[0].link.type on click, and repositions controls on chart redraw. Wire this script into AAOptions via afterDrawChartJavaScriptSet and store references on chart.__aaDendrogramLinkTypeControls. Change made in AATreegraphChartComposer.m.
1 parent 62f172a commit ef4a569

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

AAChartKit-ProDemo/ChartsDemo/AAChartKit-Pro/Composer/AATreegraphChartComposer.m

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,122 @@ + (AAOptions *)evolutionDendrogramChart {
238238
].join(' ');
239239
document.head.appendChild(style);
240240
})());
241+
242+
NSString *injectLinkTypeButtonsJS =
243+
@AAJSFunc((function () {
244+
const chart = aaGlobalChart;
245+
if (!chart || chart.__aaDendrogramLinkTypeControls) {
246+
return;
247+
}
248+
249+
const items = [
250+
{ label: 'Orthogonal', type: 'default' },
251+
{ label: 'Straight', type: 'straight' },
252+
{ label: 'Curved', type: 'curved' }
253+
];
254+
255+
const group = chart.renderer.g('aa-dendrogram-link-type-group').add();
256+
const title = chart.renderer
257+
.text('Link type', 0, 0)
258+
.css({
259+
color: '#666666',
260+
fontSize: '12px'
261+
})
262+
.add(group);
263+
264+
const inactiveTheme = {
265+
fill: '#f2f2f2',
266+
stroke: '#d9d9d9',
267+
'stroke-width': 1,
268+
r: 4,
269+
padding: 6,
270+
style: {
271+
color: '#111111',
272+
fontSize: '12px'
273+
}
274+
};
275+
276+
const controls = items.map(item => {
277+
const button = chart.renderer
278+
.button(
279+
item.label,
280+
0,
281+
0,
282+
function () {
283+
chart.series[0].update({
284+
link: {
285+
type: item.type
286+
}
287+
});
288+
setActive(item.type);
289+
},
290+
inactiveTheme
291+
)
292+
.add(group);
293+
294+
return {
295+
type: item.type,
296+
button
297+
};
298+
});
299+
300+
function setActive(activeType) {
301+
controls.forEach(control => {
302+
const isActive = control.type === activeType;
303+
control.button.attr({
304+
fill: isActive ? '#e6e6e6' : '#f2f2f2',
305+
stroke: isActive ? '#c7c7c7' : '#d9d9d9'
306+
});
307+
308+
if (control.button.text) {
309+
control.button.text.css({
310+
fontWeight: isActive ? 'bold' : 'normal'
311+
});
312+
}
313+
});
314+
}
315+
316+
function layoutControls() {
317+
const titleBBox = title.getBBox();
318+
const buttonSpacing = 10;
319+
let totalButtonWidth = 0;
320+
321+
controls.forEach((control, index) => {
322+
totalButtonWidth += control.button.getBBox().width;
323+
if (index < controls.length - 1) {
324+
totalButtonWidth += buttonSpacing;
325+
}
326+
});
327+
328+
const baseX = chart.plotLeft + (chart.plotWidth - totalButtonWidth) / 2;
329+
const titleX = chart.plotLeft + (chart.plotWidth - titleBBox.width) / 2;
330+
const titleY = chart.plotTop + chart.plotHeight + 54;
331+
const buttonY = titleY + 14;
332+
333+
title.attr({
334+
x: titleX,
335+
y: titleY
336+
});
337+
338+
let currentX = baseX;
339+
controls.forEach(control => {
340+
control.button.attr({
341+
x: currentX,
342+
y: buttonY
343+
});
344+
currentX += control.button.getBBox().width + buttonSpacing;
345+
});
346+
}
347+
348+
Highcharts.addEvent(chart, 'redraw', layoutControls);
349+
layoutControls();
350+
setActive('default');
351+
352+
chart.__aaDendrogramLinkTypeControls = {
353+
group,
354+
controls
355+
};
356+
})());
241357

242358
NSDictionary *series = @{
243359
@"type": AAChartTypeTreegraph,
@@ -290,6 +406,7 @@ + (AAOptions *)evolutionDendrogramChart {
290406

291407
return AAOptions.new
292408
.beforeDrawChartJavaScriptSet(injectIconStyleJS)
409+
.afterDrawChartJavaScriptSet(injectLinkTypeButtonsJS)
293410
.chartSet(AAChart.new
294411
.invertedSet(true)
295412
.marginRightSet(@40)

0 commit comments

Comments
 (0)