用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/veelenga/preview-skills --skill preview-d3命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Render and preview CSV files in browser with interactive sorting, filtering, and column statistics
Git diff preview tool with GitHub-style formatting and interactive features
Render and preview JSON files in browser with syntax highlighting, collapsible tree view, and search
基于 SOC 职业分类
正在显示 SKILL.md
| name | preview-d3 |
| description | Create interactive 2D data visualizations using D3.js with zoom, pan, and custom rendering |
| user-invocable | true |
| commands | ["preview-d3"] |
Interactive D3.js visualization viewer that renders custom data visualizations with built-in zoom, pan, and export capabilities.
When the user asks to create a D3 visualization, write the D3 code and pipe it to the script. Use the Bash tool to execute this skill's run.sh script:
# Pipe D3 code
cat visualization.js | ./run.sh
# Or from a file
./run.sh chart.d3
The script handles all HTML generation and automatically opens the result in the browser. Do NOT open the file manually to avoid duplicate tabs.
# Preview a D3 visualization file
/preview-d3 network-graph.d3
# Pipe D3 code (preferred for temporary content)
cat visualization.js | /preview-d3
echo "const svg = d3.select('#visualization').append('svg')..." | /preview-d3
Best Practice: For temporary or generated visualizations, prefer piping over creating temporary files. This avoids cluttering your filesystem and the content is automatically cleaned up.
The script works with sensible defaults but supports these flags for flexibility:
-o, --output PATH - Custom output path--no-browser - Skip browser, output file path onlyUse this skill when the user wants to:
Your D3 code should be self-contained JavaScript that:
// Get container dimensions
const container = document.querySelector('#visualization');
const rect = container.getBoundingClientRect();
const width = rect.width;
const height = rect.height;
const margin = { top: 60, right: 40, bottom: 60, left: 60 };
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
// Sample data
const data = [
{ category: 'A', value: 30 },
{ category: 'B', value: 80 },
{ category: 'C', value: 45 },
];
// Create SVG
const svg = d3.select('#visualization').append('svg').attr('width', width).attr('height', height);
const chart = svg.append().(, );
//Get container dimensions
const container = document.querySelector('#visualization');
const rect = container.getBoundingClientRect();
const width = rect.width;
const height = rect.height;
const margin = { top: 60, right: 40, bottom: 60, left: 60 };
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
// Sample data
const data = [
{ category: 'A', value: 30 },
{ category: 'B', value: 80 },
{ category: 'C', value: 45 },
{ category: 'D', value: 60 },
{ category: 'E', value: 20 },
];
// Create SVG
const svg = d3.select('#visualization').append().(, width).(, height);
chart = svg.().(, );
xScale = d3
.()
.(data.( d.))
.([, innerWidth])
.();
yScale = d3
.()
.([, d3.(data, d.)])
.()
.([innerHeight, ]);
chart.().(, ).(d3.(xScale));
chart.().(d3.(yScale));
tooltip = d3
.()
.()
.(, )
.(, )
.(, );
chart
.()
.(data)
.()
.(, (d.))
.(, (d.))
.(, xScale.())
.(, innerHeight - (d.))
.(, )
.(, {
tooltip.().().(, );
tooltip
.()
.(, event. + + )
.(, event. - + );
})
.(, {
tooltip.().().(, );
});
chart
.()
.(, innerWidth / )
.(, -)
.(, )
.(, )
.(, )
.();
const line = d3
.line()
.x((d) => xScale(d.date))
.y((d) => yScale(d.value));
svg
.append('path')
.datum(data)
.attr('fill', 'none')
.attr('stroke', '#3498db')
.attr('stroke-width', 2)
.attr('d', line);
svg
.selectAll('circle')
.data(data)
.join('circle')
.attr('cx', (d) => xScale(d.x))
.attr('cy', (d) => yScale(d.y))
.attr('r', 5)
.attr('fill', '#3498db');
const pie = d3.pie().value((d) => d.value);
const arc = d3.arc().innerRadius(0).outerRadius(radius);
svg
.selectAll('path')
.data(pie(data))
.join('path')
.attr('d', arc)
.attr('fill', (d, i) => d3.schemeCategory10[i]);
Your code runs with:
d3#visualization ready in the DOM#visualization)position: absolute CSSevent.pageX/pageY for positioning (not clientX/Y).d3The skill generates a standalone HTML file at:
.preview-skills/d3/{filename}.html
This skill is standalone and includes all dependencies:
lib/templates/To modify the skill:
config.sh for configurationtemplates/scripts/d3-renderer.js for behaviortemplates/styles/d3.css for stylingrun.sh to test changes