Skip to content

Commit

Permalink
[fix] 排名条形图,超过100的排名显示不对 review by luoxiao
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Sep 7, 2023
1 parent 5a30369 commit 21c8599
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/common/chart/ChartMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ export default {
}
const sortSeriesIndex = this.datasetOptions.findIndex(item => item.sort !== 'unsort' && item.rankLabel);
if (sortSeriesIndex > -1 && axisLabel && data) {
const orderNumLength = data.length.toString().length;
for (let index = 0, len = data.length, rankIndex = len - 1; index < len; index++, rankIndex--) {
data[index] = rankIndex < 10 ? `0${rankIndex}${data[index]}` : `${rankIndex}${data[index]}`;
const paddedNumber = rankIndex.toString().padStart(orderNumLength, '0');
data[index] = `${paddedNumber}${data[index]}`;
}
const firstVisualMap = visualMap && visualMap.find(item => item.seriesIndex === sortSeriesIndex);
axisLabel.rich = axisLabel.rich || {};
Expand All @@ -430,8 +432,8 @@ export default {
});
const serieData = series && series[sortSeriesIndex].data;
axisLabel.formatter = function (label, index) {
const orderNum = parseInt(label.slice(0, 2)) + 1;
const leftLabel = label.slice(2);
const orderNum = parseInt(label.slice(0, orderNumLength)) + 1;
const leftLabel = label.slice(orderNumLength);
const labelValue = serieData && +serieData[index];
if (firstVisualMap) {
const matchItem = firstVisualMap.pieces.find(item => labelValue >= item.min && labelValue <= item.max);
Expand Down
79 changes: 78 additions & 1 deletion src/mapboxgl/chart/__tests__/Chart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,21 @@ describe('Chart', () => {
xField: '机场',
yField: '2017起降架次(架次)'
}
]
],
options: {
xAxis:{
axisLabel:{},
show: true,
type: "category",
name: ""
},
yAxis:{
axisLabel:{},
show: true,
type: "category",
name: ""
}
}
}
});
await mapSubComponentLoaded(wrapper);
Expand Down Expand Up @@ -1316,4 +1330,67 @@ describe('Chart', () => {
expect(wrapper.vm.dataset.type).toBe('iPortal');
done();
});

it('init rankbar AxisLabel', async done => {
const fetchResource = {
'https://fakeiportal.supermap.io/iportal/web/datas/123': chart_restData,
'https://fakeiportal.supermap.io/iportal/web/datas/123/content.json?pageSize=9999999&currentPage=1': layerData
};
mockFetch(fetchResource);
wrapper = mount(SmChart, {
propsData: {
mapTarget: 'map',
dataset: iportalDataSet,
echartOptions: {
legend: {
data: ['2016起降架次(架次)', '2017起降架次(架次)']
},
tooltip: {
formatter: '{b0}: {c0}'
},
grid: {
top: 30,
bottom: 60,
left: 60,
right: 30
}
},
chartStyle: {
position: 'absolute',
bottom: '10px',
right: '10px'
},
datasetOptions: [
{
"seriesType": "bar",
"xField": "date",
"yField": "sale",
"sort": "descending",
"rankLabel": true
}
],
colorGroup: ['#f00'],
options: {
xAxis:{
axisLabel:{},
show: true,
type: "category",
name: ""
},
yAxis:{
axisLabel:{},
show: true,
type: "category",
name: ""
}
}
}
});
await mapSubComponentLoaded(wrapper);
let data=["四川","江苏","云南","江西","海南","台湾","上海","广东","福建","北京"]
wrapper.vm._initAxisLabel({}, data)
await flushPromises();
expect(data[0]).toBe('09四川')
done();
});
});

0 comments on commit 21c8599

Please sign in to comment.