svg - 删除 svg 中 rect 内文本元素周围的空间
问题描述
我正在使用d3plus绘制线图,并且添加了三个注释,这些注释是<rect>
明显包含 '' 元素的形状。该库将它们放置在<g>
作为兄弟姐妹的单独元素中:
<g class="d3plus-rect-group">
<g class="d3plus-rect-shape">
<rect class="d3plus->...</rect>
</g>
<g class="d3plus-rect-text">
<g class="d3plus-text-box">
<text>
</g>
</g>
<g>
使用此代码:
return new LinePlot()
annotations: [
{ Line annotation data goes here },
{
shape: "Rect",
data: this.annotationRects,
opacity: this.annotationOpacity,
fill: '#fff',
rx: '.25rem',
ry: '.25rem',
label: function (d) {
let result = d.label;
let list = window.matchMedia('(max-width: 576px)');
if (list.matches) {
result = ''
}
return result;
},
labelConfig: {
textAnchor: function(d, i) {
return d.labelTextAnchor;
},
verticalAlign: function(d, i) {
return d.labelVerticalAlign;
},
fontColor: function (d) {
let result = d.color;
let list = window.matchMedia('(max-width: 576px)');
if (list.matches) {
result = ''
}
return result;
},
},
},
]
}
annotationLines() {
let items = [
// Draws vertical startDate date line
{
id: 'startDate',
x: this.startDate,
y: 0
},
{
id: 'startDate',
x: this.startDate,
y: this.ceilingValue * 1.11
},
// Draws vertical endDate date line
{
id: 'endDate',
x: this.endDate,
y: 0
},
{
id: 'endDate',
x: this.endDate,
y: this.ceilingValue * 1.11
},
];
if (!this.isGrant) {
items.push(
{
id: "ceilingValue",
x: this.bufferedStartDate,
y: this.ceilingValue
},
{
id: "ceilingValue",
x: this.bufferedEndDate,
y: this.ceilingValue
}
);
}
return items;
},
annotationRects() {
const items = [
{
id: 'startDate',
x: this.startDate,
y: this.ceilingValue * 1.11,
width: 90,
height: 25,
color: "#g",
label: 'Award Date',
labelTextAnchor: 'middle',
labelVerticalAlign: 'end'
},
{
id: 'endDate',
x: this.endDate,
y: this.ceilingValue * 1.11,
width: 150,
height: 25,
color: "#265d94",
label: 'Ultimate Completion Date',
labelTextAnchor: 'middle',
labelVerticalAlign: 'end'
}
];
if (!this.isGrant) {
items.push(
{
id: 'ceilingValue',
x: this.ceilingAnnotationDate,
y: this.ceilingValue,
width: 85,
height: 30,
color: "#33867e",
label: 'Ceiling Value',
labelTextAnchor: 'start',
labelVerticalAlign: 'middle'
}
);
}
return items;
},
<rect>
问题是形状
内的文本标签周围有很多空间,如下所示:
我想要做的是紧贴<text>
内容边缘周围的矩形(因为没有更好的术语)。它不像填充那么简单,我一直在搞乱诸如封闭<rect>
和元素的大小以及使用textAnchor和verticalAlign<text>
值放置文本框之类的事情,但那里总是有一些空间。有没有办法缩小矩形,使文本框周围没有空间?
解决方案
推荐阅读
- c - Pi 3 上的 perf_event.h 事件组是否有多重限制
- linux - 当 $EUID 与 $UID 不同时,我如何产生一种情况?
- html - 我尝试验证我的 css 文件,但找不到将网格布局调整为平板电脑大小的问题
- python - read_csv 不会打开 .csv 文件;而是必须使用 csv.reader+defaultdict 在框架中解析
- javascript - 无法获得 PERT 图形结果 - AnyChart JS
- node.js - buildpack 将 node.js 应用程序部署到 heroku 时出错 - 文件似乎处于正确的级别>?
- sharepoint - 有没有办法使用 Sharepoint 版本历史来计算列值?
- node.js - 为什么在我的 VS Code 终端中出现“无法加载 nodemon”?
- matplotlib - 按颜色绘制分类
- c++ - ExtTextOut 文本不断闪烁,并且在设定的时间后文本恢复为默认字体