统计整本 Document IR 中的 Chart.js 图表数量。 会遍历每章的 blocks,递归查找 widget 类型中以 `chart.js` 开头的组件,便于快速感知图表规模。 参数: document_ir: 完整的 Document IR 返回: int: 图表总数
(document_ir)
| 150 | |
| 151 | |
| 152 | def count_charts(document_ir): |
| 153 | """ |
| 154 | 统计整本 Document IR 中的 Chart.js 图表数量。 |
| 155 | |
| 156 | 会遍历每章的 blocks,递归查找 widget 类型中以 `chart.js` |
| 157 | 开头的组件,便于快速感知图表规模。 |
| 158 | |
| 159 | 参数: |
| 160 | document_ir: 完整的 Document IR |
| 161 | |
| 162 | 返回: |
| 163 | int: 图表总数 |
| 164 | """ |
| 165 | chart_count = 0 |
| 166 | for chapter in document_ir.get("chapters", []): |
| 167 | blocks = chapter.get("blocks", []) |
| 168 | chart_count += _count_chart_blocks(blocks) |
| 169 | return chart_count |
| 170 | |
| 171 | |
| 172 | def _count_chart_blocks(blocks): |
no test coverage detected