Metadata-Version: 2.4
Name: vizagent-dashboard
Version: 0.1.7
Summary: Compile CSV/XLSX data and DashboardSpec into validated offline HTML dashboards.
Project-URL: Homepage, https://github.com/Carloslee96/vizagent-dashboard
Project-URL: Source, https://github.com/Carloslee96/vizagent-dashboard
Author: VizAgent Team
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor has
              been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
License-File: NOTICE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.10
Requires-Dist: click>=8.0.0
Requires-Dist: openpyxl>=3.1.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: all
Requires-Dist: playwright>=1.45.0; extra == 'all'
Provides-Extra: browser
Requires-Dist: playwright>=1.45.0; extra == 'browser'
Provides-Extra: dev
Requires-Dist: build>=1.2.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Description-Content-Type: text/markdown

<div align="center">

# ⭐ vizagent-dashboard

**给数据，自动出大屏——一行命令，CSV/Excel 变成可离线打开的 HTML 数据大屏**

[![CI](https://github.com/Carloslee96/vizagent-dashboard/actions/workflows/ci.yml/badge.svg)](https://github.com/Carloslee96/vizagent-dashboard/actions/workflows/ci.yml)
[![Release](https://github.com/Carloslee96/vizagent-dashboard/actions/workflows/release.yml/badge.svg)](https://github.com/Carloslee96/vizagent-dashboard/releases)
[![PyPI](https://img.shields.io/pypi/v/vizagent-dashboard)](https://pypi.org/project/vizagent-dashboard/)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)

**中文** · [English](README.en.md)

</div>

<br>

你有一份销售 Excel，老板说「下班前给我个大屏看下趋势」。

```bash
vizagent build --data 销售明细.xlsx
```

30 秒后，一个能直接双击打开的 HTML 大屏躺在 `output/` 里——折线趋势、品类构成、地区地图，全自动生成。不用装数据库，不用配 API Key，不用写代码。

<div align="center">
  <img src="docs/assets/demo.png" alt="vizagent-dashboard 自动生成的大屏" width="760">
  <br>
  <sub>上图由 <code>vizagent build --data 销售明细.xlsx</code> 自动分析生成，未写任何需求或代码。<br>
  4 个 KPI + 世界地图站点分布 + 8 张图表，全部来自 10 个 Sheet 的自动识别。</sub>
</div>

> 没有数据？仓库自带这份示例，克隆后直接跑：<br>
> `vizagent build --data examples/销售明细.xlsx`

---

## ✨ 它能做什么

- **🧠 自动分析数据**：检测到日期字段出折线趋势、地理字段出地图、占比字段出饼图、分类字段出柱状图。给数据就行，不用写需求。
- **📦 单文件 HTML**：一个自包含文件，ECharts 已内嵌。双击就能看，丢任意静态服务器或发给同事都行，断网也照常渲染。
- **📊 丰富图表**：折线、柱状、饼图、散点、KPI 卡片、中国地图、世界地图。
- **🎨 25 个主题**：5 原创（`midnight-ops` 默认 / `paper-light` / `warm-editorial` / `clinical-light` / `signal-dark`）+ 20 去品牌引入（见 `docs/THEME_AUDIT.md`），一键切换；还支持 `--theme-dir` 自定义主题。
- **📁 CSV / Excel 多表**：自动读多个 Sheet，逐表、逐行追踪数据覆盖。
- **✅ 内置质量门禁**：自动查截断、空数据、零尺寸图表、地图未绑定、字段缺失；可选 Playwright 浏览器门禁。
- **🔒 安全默认**：HTML 转义 + Content Security Policy + 路径穿越防护。
- **🤖 可当 Agent Skill**：加载为 Claude Code / Cursor / Codex 的 Skill（`vizagent skill install --target all`），让你自己的 AI 来分析数据、编写更聪明的大屏方案。

---

## 💡 关于「需求」参数——它不是必填

很多人第一反应：「我都给你数据表了，怎么不能自动分析？」

**能。默认就是自动分析。** `--requirement` 是可选的微调，不是必填：

```bash
# ① 自动模式（推荐，最省事）：只给数据，自动分析字段、选图表、配主题
vizagent build --data 销售明细.xlsx

# ② 微调模式：加一句需求，影响图表选择/主题/分页（仍不调 LLM）
vizagent build --data 销售明细.xlsx --requirement "只要饼图，浅色主题，分页展示"

# ③ Spec 模式：完全手动控制，写一份 DashboardSpec JSON，零意外
vizagent build --data 销售明细.xlsx --spec my-spec.json
```

`--requirement` 里写什么会影响结果：

| 写了什么 | 会怎样 |
|---|---|
| `尽可能多类型` / `丰富` / `各种图表` | 自动分发多种图表类型（按各 sheet 字段形态分配） |
| `用雷达图` / `漏斗图` / `仪表盘` / `南丁格尔` / `树图` / `面积` / `热力` | 点名具体类型（字段不兼容自动回退） |
| `只要饼图` / `仅展示柱状` | 全局强制单一图表类型 |
| `浅色` / `明亮` / `纸张` | 切到 paper-light 主题 |
| `暖色` / `珊瑚` | 切到 coral-warm 主题 |
| `分页` / `多页签` | 用 tabs 多页签布局 |
| `地图` | 优先出地图 |
| **不写** | 自动分析，按字段类型选最合适的图表 |

> 想要更智能的分析（比如「对比去年同期」「找出异常点」）？用下面的 **Agent Skill 模式**，让你自己的 AI 来理解需求。

---

## 🚀 30 秒上手

### 1. 安装

```bash
pip install vizagent-dashboard
vizagent skill install --target all   # 注册 Claude Code / Cursor / Codex 的 Skill
```

> 两步缺一不可：第一步装 CLI（`vizagent build`），第二步把 Skill 规则文件写到 `~/.claude/skills/`、`~/.cursor/rules/`、`~/.codex/prompts/`。装完重启对应工具，`/vizagent-dashboard` 即可用。只想用命令行不接 AI 工具，可跳过第二步。

### 2. 准备数据

存成 CSV 或 Excel。多个 Sheet 也行：

```
销售明细.xlsx
├─ 销售趋势   （月份、销售额）        → 自动出折线
├─ 品类构成   （品类、占比）          → 自动出饼图
└─ 地区销售   （省份、销售额）        → 自动出中国地图
```

### 3. 一行命令出大屏

```bash
vizagent build --data 销售明细.xlsx
```

### 4. 打开 `output/output.html`

完事。

---

## 🖼️ 同一份数据，5 个主题

```bash
vizagent build --data 销售明细.xlsx --theme paper-light
```

<div align="center">
  <table>
    <tr>
      <td align="center" width="50%">
        <a href="examples/ecommerce/">
          <img src="docs/assets/ecommerce-thumb.png" width="100%">
          <br><b>midnight-ops</b>（默认）
        </a>
        <br>深靛灰背景、蓝绿数据色
      </td>
      <td align="center" width="50%">
        <a href="examples/ecommerce/">
          <img src="docs/assets/theme-paper-light.png" width="100%">
          <br><b>paper-light</b>
        </a>
        <br>暖白纸张、墨色文字
      </td>
    </tr>
    <tr>
      <td align="center" width="50%">
        <a href="examples/ecommerce/">
          <img src="docs/assets/theme-warm-editorial.png" width="100%">
          <br><b>warm-editorial</b>
        </a>
        <br>浅米色、暗红重点
      </td>
      <td align="center" width="50%">
        <a href="examples/ecommerce/">
          <img src="docs/assets/theme-signal-dark.png" width="100%">
          <br><b>signal-dark</b>
        </a>
        <br>炭黑、琥珀青信号
      </td>
    </tr>
  </table>
</div>

> 第五个主题 `clinical-light` 用 `--theme clinical-light` 自行构建查看。

---

## 📖 命令参数

```bash
vizagent build --data <数据文件> [选项]
```

| 参数 | 默认 | 说明 |
|---|---|---|
| `--data` | 必填 | CSV 或 Excel 文件路径 |
| `--requirement` | 空（自动分析） | 可选微调；写关键词影响图表/主题/分页，不调 LLM |
| `--spec` | 无 | 指定 DashboardSpec JSON，进入完全手动模式 |
| `--theme` | 自动或 `midnight-ops` | 主题 ID，见上表 |
| `--page-mode` | `single_page` | `single_page` 或 `tabs` |
| `--deployment` | `embedded` | `embedded`（离线）或 `cdn` |
| `--output` | `./output` | 输出目录 |
| `--browser` | 关 | 开启 Playwright 浏览器门禁 |
| `--open` | 关 | 成功后自动打开 HTML |

---

## 🤖 Agent Skill 模式（让 AI 帮你分析）

确定性规划器是关键词级别的，懂「日期→折线」但不懂数据背后的业务含义。要更智能的分析，把本项目加载为 **Claude Code / Codex 的 Skill**，让你自己的 AI 来：

1. 读取数据盘点（`vizagent inventory`）
2. 理解你的业务、编写 DashboardSpec
3. 调用 `vizagent compile` 编译、`vizagent validate` 验证

用的是你已有 AI 订阅的推理能力，**不需要额外 API Key**。

```bash
vizagent inventory --data <文件> --output data.inventory.json
vizagent compile  --data <文件> --spec <spec.json> --output dashboard/
vizagent validate --data <文件> --spec <spec.json> --html dashboard/output.html
```

### 作为 AI 编程工具的 Skill 使用

pip 安装后，一行命令把规则文件装到用户级目录，重启对应工具即可触发。支持 Claude Code、Cursor、Codex CLI：

```bash
vizagent skill install --target all   # 一次装齐 Claude + Cursor + Codex（推荐）
# 也可单独：--target claude / --target cursor / --target codex
```

各工具触发方式：

| 工具 | 安装位置 | 触发方式 |
|---|---|---|
| Claude Code | `~/.claude/skills/vizagent-dashboard/` | `/vizagent-dashboard`，或说「用 xx.xlsx 做个大屏」 |
| Cursor | `~/.cursor/rules/vizagent-dashboard.mdc` | 编辑 .xlsx/.csv 时自动注入，或对话中 @ 引用 |
| Codex CLI | `~/.codex/prompts/vizagent-dashboard.md` | `/vizagent-dashboard` |

查看打包的规则文件位置：`vizagent skill path [--target all]`。

> clone 本仓库并用对应工具打开，会自动加载项目级规则（仓库根 `.claude/skills/`、`.cursor/rules/`、`.codex/prompts/`），无需手动安装。
>
> Codex 旧版 `skills/build-data-dashboard/`（带 `agents/openai.yaml`）仍保留，供其他 Agent 框架使用。

---

## 🏗️ 架构

```
┌──────────────┐    ┌──────────────┐    ┌──────────────┐
│  CSV / XLSX  │───▶│   自动分析   │───▶│    编译器     │───▶ output.html
│  （你的数据） │    │ （选图表）   │    │  （生成 HTML）│
└──────────────┘    └──────────────┘    └──────────────┘
                           │                    │
            --requirement  │                    │
            （可选微调）    ▼                    ▼
                    ┌──────────────┐    ┌──────────────┐
                    │   规划器      │    │   质量门禁    │
                    │ （关键词级）  │    │  （截断/空数据）│
                    └──────────────┘    └──────────────┘
```

**核心设计**：编译器完全确定性，无 LLM、无网络、无 API 调用，输出可复现。`--requirement` 规划器是关键词级的，不是大模型。需要真正的业务理解时，用 Agent Skill 模式让宿主 AI 接管分析。

---

## 🧪 开发

```bash
git clone https://github.com/Carloslee96/vizagent-dashboard.git
cd vizagent-dashboard
pip install -e ".[dev]"
python -m pytest tests/ -v
ruff check src/ tests/
```

---

## 📄 许可证

Apache 2.0 © VizAgent Team。详见 [LICENSE](LICENSE)。

---

<div align="center">
  <b>不用数据库。不用服务器。就一个 HTML 文件。<br>给数据，出大屏。</b>
  <br><br>
  <a href="https://github.com/Carloslee96/vizagent-dashboard/stargazers">
    <img src="https://img.shields.io/github/stars/Carloslee96/vizagent-dashboard?style=social" alt="stars">
  </a>
</div>
