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

fix: 多个图表展示

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