MCPcopy
hub / github.com/zxlie/FeHelper / initChartTypeGallery

Function initChartTypeGallery

apps/chart-maker/main.js:213–238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

211
212 // 初始化图表类型画廊
213 function initChartTypeGallery() {
214 // 获取所有图表类型预览项
215 const chartTypeItems = document.querySelectorAll('.chart-type-item');
216
217 // 为每个预览项添加点击事件
218 chartTypeItems.forEach(item => {
219 item.addEventListener('click', function() {
220 const chartType = this.getAttribute('data-chart-type');
221
222 // 更新活动状态
223 chartTypeItems.forEach(item => item.classList.remove('active'));
224 this.classList.add('active');
225
226 // 无论是否有图表实例都应该重新生成图表
227 // 删除之前的检查条件,始终调用generateChart
228 generateChart();
229 });
230 });
231
232 // 初始设置默认图表类型为活动状态
233 const defaultChartType = "bar"; // 默认为柱状图
234 const activeItem = document.querySelector(`.chart-type-item[data-chart-type="${defaultChartType}"]`);
235 if (activeItem) {
236 activeItem.classList.add('active');
237 }
238 }
239
240 // 加载样例数据
241 sampleDataBtn.addEventListener('click', function() {

Callers 1

main.jsFile · 0.70

Calls 4

generateChartFunction · 0.85
removeMethod · 0.80
addEventListenerMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected