-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] legends need to support align style inside the column. #1553
Comments
这个涉及到三点:
{
type: 'size',
slidable: true,
visible: true,
title: {
visible: true,
text: '销售额',
textStyle: {
fontSize: 12,
fill: '#6F6F6F'
},
space: 0,
padding: [0, 0, 0, 4] // 标题间距,调整左侧 padding 同滑轨对齐
},
align: 'left', // 配置滑轨的显示方向
handlerText: {
style: {
maxLineWidth: 50,
fontSize: 12,
fill: '#6F6F6F',
textAlign: 'start', // 配置对齐方式
dx: 30 // 配置便宜
}
},
} 效果: vchart.on('afterLayout', e => {
const elements = e.elements;
const legends = elements.filter(e => e.layoutType === 'normal-inline');
const region = elements.filter(e => e.type === 'region')[0];
legends.forEach(legend => {
console.log(legend.type);
if (legend.type === 'discreteLegend') {
legend.setLayoutStartPosition({
x: region.getLayoutStartPoint().x + region.getLayoutRect().width,
y: legend.getLayoutStartPoint().y
});
}
if (legend.type === 'sizeLegend') {
legend.setLayoutStartPosition({
x: region.getLayoutStartPoint().x + region.getLayoutRect().width,
y: region.getLayoutStartPoint().y + region.getLayoutRect().height - legend.getLayoutRect().height
});
}
});
}); |
监听 const CONTAINER_ID = 'chart';
const run = () => {
const spec = {
type: 'scatter',
xField: '231127202655022',
yField: '231128164638011',
invalidType: 'ignore',
region: [
{
clip: true
}
],
padding: 0,
labelLayout: 'region',
data: [data],
legends: [
{
type: 'discrete',
visible: true,
id: 'legend-discrete',
orient: 'right',
position: 'start',
layoutType: 'normal-inline',
maxCol: 4,
title: {
textStyle: {
fontSize: 12,
fill: '#6F6F6F'
}
},
layoutLevel: 60,
item: {
focus: true,
focusIconStyle: {
size: 14
},
maxWidth: 445,
spaceRow: 0,
spaceCol: 0,
padding: {
top: 1,
bottom: 2,
left: 3,
right: 2
},
background: {
visible: false,
style: {
fillOpacity: 0.001
}
},
label: {
style: {
fontSize: 12,
fill: '#6F6F6F'
}
},
shape: {
style: {
lineWidth: 0,
symbolType: 'square'
}
}
},
pager: {
position: 'start',
layout: 'horizontal',
// padding: {
// left: -18
// },
textStyle: {},
space: 0,
handler: {
preShape: 'triangleLeft',
nextShape: 'triangleRight',
style: {},
state: {
disable: {}
}
}
},
padding: {
top: 0,
bottom: 12,
left: 16,
right: 0
},
height: '60%'
},
{
type: 'size',
slidable: true,
visible: true,
title: {
visible: true,
text: '销售额',
textStyle: {
fontSize: 12,
fill: '#6F6F6F'
},
space: 0,
padding: [0, 0, 0, 4] // 标题间距,调整左侧 padding 同滑轨对齐
},
align: 'left', // 配置滑轨的显示方向
handlerText: {
style: {
maxLineWidth: 50,
fontSize: 12,
fill: '#6F6F6F',
textAlign: 'start', // 配置对齐方式
dx: 30 // 配置便宜
}
},
id: 'legend-size',
orient: 'right',
position: 'start',
layoutType: 'normal-inline',
field: ['231128164638017'],
layoutLevel: 50,
track: {
style: {
fill: 'rgba(20,20,20,0.1)'
}
},
rail: {
height: 100
},
handler: {
style: {
symbolType: 'M-5,0L-2.5,-3.5\n h5\n v7\n h-5\n Z',
size: 8,
shadowBlur: 0,
shadowColor: false,
outerBorder: {
stroke: '#AEB8C6',
lineWidth: 1,
strokeOpacity: 0.5
}
}
},
startText: {
visible: false
},
endText: {
visible: false
},
padding: {
top: 0,
bottom: 12,
left: 23,
right: 0
}
}
],
seriesField: '231128164638035',
sizeField: '231128164638017',
size: {
type: 'linear',
range: [7.0898154036220635, 28.359261614488254]
}
};
const vchart = new VChart(spec, { dom: CONTAINER_ID });
vchart.renderAsync();
vchart.on('afterLayout', e => {
const elements = e.elements;
const legends = elements.filter(e => e.layoutType === 'normal-inline');
const region = elements.filter(e => e.type === 'region')[0];
legends.forEach(legend => {
console.log(legend.type);
if (legend.type === 'discreteLegend') {
legend.setLayoutStartPosition({
x: region.getLayoutStartPoint().x + region.getLayoutRect().width,
y: legend.getLayoutStartPoint().y
});
}
if (legend.type === 'sizeLegend') {
legend.setLayoutStartPosition({
x: region.getLayoutStartPoint().x + region.getLayoutRect().width,
y: region.getLayoutStartPoint().y + region.getLayoutRect().height - legend.getLayoutRect().height
});
}
});
});
// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;
};
run(); |
…ttribute assignment does not take effect, related #1553
…ttribute assignment does not take effect, related #1553
What problem does this feature solve?
size legend need to support align style inside the column, so it can be in the side close to the chart like 3.x:What does the proposed API look like?
legends:[
{
...
position: 'start',
align: left , right or middle
}]
The text was updated successfully, but these errors were encountered: