Skip to content

Commit

Permalink
fix: axis label fontFamily
Browse files Browse the repository at this point in the history
  • Loading branch information
sima.zhang1990@gmail.com committed Apr 3, 2018
1 parent 1a9b6b2 commit e6620f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/chart/controller/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class AxisController {
}

_getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg) {
const self = this;
const axisCfg = this.axisCfg;
const ticks = scale.getTicks();

Expand Down Expand Up @@ -168,7 +169,8 @@ class AxisController {
attrs: Util.mix({
x: 0,
y: 0,
text: tick.text
text: tick.text,
fontFamily: self.chart.get('canvas').get('fontFamily') // 保持字体一致
}, labelCfg),
value: tick.value,
textStyle,
Expand Down
16 changes: 16 additions & 0 deletions test/unit/chart/chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ describe('chart test', () => {
chart.coord('polar', {
transposed: true
});
chart.axis(true);
chart.axis('a', {
label: {
fontFamily: 'Arial'
}
});
chart.changeData([
{ a: '1', b: 5 },
{ a: '1', b: 2 }
Expand All @@ -334,6 +340,16 @@ describe('chart test', () => {
expect(chart.get('scales').a.range).to.eql([ 0.5, 1 ]);
});

it('axis label fontFamily', function() {
const backPlot = chart.get('backPlot');
const axisGroup = backPlot.get('children')[0];
const xAxisLabel = axisGroup.get('children')[0];
const xAxisfont = xAxisLabel.attr('font');
const yAxisLabel = axisGroup.get('children')[3];
const yAxisfont = yAxisLabel.attr('font');
expect(xAxisfont).to.equal('normal normal normal 10px Arial'); // a 轴文本
expect(yAxisfont).to.equal('normal normal normal 10px "Helvetica Neue", "San Francisco", Helvetica, Tahoma, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", sans-serif'); // b 轴文本
});

it('destroy', function(done) {
setTimeout(function() {
Expand Down

0 comments on commit e6620f1

Please sign in to comment.