Skip to content

Commit

Permalink
feat(guide): support offset setting for Guide.Text.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Dec 27, 2017
1 parent b83b5e9 commit c0564ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions demos/bar-animate.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
data.forEach(function (obj, index) {
// 文字部分
const offsetY = obj.tem > 0 ? -16 : 14;
chart.guide().html([obj.month, obj.tem], `<div style='color: #999999;'><span>${obj.tem}</span></div>`, {
align: 'cc',
offset: [0, offsetY]
chart.guide().text([obj.month, obj.tem], obj.tem, {
offset: [0, offsetY],
textAlign: 'center',
fontSize: 14,
textBaseline: 'middle'
});
// 背景部分
const offset = 0.25;
Expand Down
6 changes: 6 additions & 0 deletions src/guide/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class Text extends Guide {
const point = self.parsePoint(coord, position);
const cfg = self.cfg;
const text = self.text;

if (cfg.offset) { // support offset
point.x += cfg.offset[0];
point.y += cfg.offset[1];
}

G.drawText(text, point, canvas, cfg);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const Theme = {
},
text: {
fill: '#000',
textAlign: 'center'
textAlign: 'center',
offset: [ 0, 0 ]
},
rect: {
fillStyle: '#fafafa'
Expand Down

0 comments on commit c0564ae

Please sign in to comment.