提交 6bcd80d0 编写于 作者: D DebugIsFalse

fix: 多个图表展示

上级 e6464ca7
......@@ -12,9 +12,9 @@
<UCard :ui="cardUI">
<ProseChart
type="line"
:labels="item.labels"
:data="item.data"
:info="item.info"
:labels="chart.labels"
:data="chart.data"
:info="chart.info"
simple
/>
</UCard>
......
......@@ -102,10 +102,10 @@ async function initSearchRecordsChart (repos) {
let {output, index} = repo
const {gits, urls} = handleFormatInfoData(output)
fetchRepoStarsData(urls).then((result) => {
const card = handleFormatRepoStars(result)
const card = handleFormatRepoStars(result, gits)
const cardItem = data.value[index].extra.find(item => item.type === card.type)
if (!cardItem) return
Object.assign(cardItem, card, { info : gits })
Object.assign(cardItem, card)
})
})
}
......@@ -220,9 +220,8 @@ async function getRepoStarsData (output) {
askingSidebarCards.value.push({ ready: false, type: 'search_relate_repo' })
const { gits, urls } = handleFormatInfoData(output)
const data = await fetchRepoStarsData(urls)
const cardItem = handleFormatRepoStars(data)
const cardItem = handleFormatRepoStars(data, gits)
const hasRepoStarItem = askingSidebarCards.value.find(item => item.type === cardItem.type)
cardItem.info = gits
if (hasRepoStarItem) {
Object.assign(hasRepoStarItem, cardItem)
} else {
......
......@@ -62,23 +62,26 @@ export function gitToLabel(url) {
// 返回匹配到的项目名称
return match[1];
}
export function handleFormatRepoStars (repoObj) {
export function handleFormatRepoStars (repoObj, gits) {
const card = {
type: 'search_relate_repo',
title: 'Star对比',
labels: [],
ready: true,
data: []
}
const gitsMap = {}
gits.forEach(item => {
gitsMap[item.url] = item
})
Object.keys(repoObj).forEach(child => {
const data = repoObj[child]
const cardDataItem = { label: gitToLabel(child), data: [] }
const cardDataItem = { data: [{ data: [], label: 'Star数量' }], labels: [], info: gitsMap[child] }
data.forEach(dataItem => {
const { date, stargazers } = dataItem
card.labels = [...new Set([...card.labels, date])]
cardDataItem.data.push(stargazers)
cardDataItem.labels.push(date)
cardDataItem.data[0].data.push(stargazers)
})
if (cardDataItem.data.length > 0) {
if (cardDataItem.data[0].data.length > 0) {
card.data.push(cardDataItem)
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册