Skip to content

Commit

Permalink
溢出基金检测中的xkcd图表,消耗大量浏览器内存
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jul 16, 2021
1 parent 41de863 commit 60b5e74
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 78 deletions.
30 changes: 0 additions & 30 deletions routes/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,42 +216,13 @@ func FundCheck(c *gin.Context) {
return
}

// 构造图表数据
chartData := map[string]gin.H{}
for _, fund := range funds {
holdRatioLabels := []string{}
holdRatioData := []float64{}
adjustRatioData := []float64{}
for _, s := range fund.Stocks {
holdRatioLabels = append(holdRatioLabels, s.Name)
holdRatioData = append(holdRatioData, s.HoldRatio)
adjustRatioData = append(adjustRatioData, s.AdjustRatio)
}
industryLabels := []string{}
industryData := []string{}
for i, p := range fund.IndustryProportions {
if i != len(fund.IndustryProportions)-1 {
industryLabels = append(industryLabels, p.Industry)
industryData = append(industryData, p.Prop)
}
}
chartData[fund.Code] = gin.H{
"hold_ratio_labels": holdRatioLabels,
"hold_ratio_data": holdRatioData,
"adjust_ratio_data": adjustRatioData,
"industry_labels": industryLabels,
"industry_data": industryData,
}
}

if !p.CheckStocks {
data := gin.H{
"Env": viper.GetString("env"),
"Version": version.Version,
"PageTitle": "X-STOCK | 基金 | 基金检测",
"Funds": funds,
"Param": p,
"ChartData": chartData,
}
c.JSON(http.StatusOK, data)
return
Expand Down Expand Up @@ -297,7 +268,6 @@ func FundCheck(c *gin.Context) {
"Funds": funds,
"StockCheckResults": stockCheckResults,
"Param": p,
"ChartData": chartData,
}
c.JSON(http.StatusOK, data)
return
Expand Down
4 changes: 2 additions & 2 deletions statics/html/fund_similarity.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ <h4 class="center">基金<span onclick="$('#desc_similarity').tapTarget('open')"
<table class="striped centered">
<thead>
<tr>
<th width="35%">基金名称</th>
<th width="35%">重复持仓</th>
<th width="30%">基金名称</th>
<th width="40%">重复持仓</th>
<th width="30%">持仓相似度</th>
</tr>
</thead>
Expand Down
46 changes: 0 additions & 46 deletions statics/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,52 +659,6 @@ $(document).ready(function () {
"</td></tr></tbody></table>" +
"</div>"
);
$(`#${fund.code}`).append(
'<div class="row"><div class="col s12 m12 l12">' +
'<svg id="svg_hold_ratio_' +
fund.code +
'"></svg></div>' +
'<div class="col s12 m12 l6">' +
'<svg id="svg_industry_prop_' +
fund.code +
'"></svg></div></div>'
);
const svgHoldRatio = document.querySelector(
`#svg_hold_ratio_${fund.code}`
);
var chartData = data.ChartData[fund.code];
new chartXkcd.StackedBar(svgHoldRatio, {
title: "持仓股票",
xLabel: "",
yLabel: "%",
data: {
labels: chartData.hold_ratio_labels,
datasets: [
{
label: "持仓占比",
data: chartData.hold_ratio_data,
},
{
label: "最新调仓",
data: chartData.adjust_ratio_data,
},
],
},
});
const svgIndustry = document.querySelector(
`#svg_industry_prop_${fund.code}`
);
new chartXkcd.Pie(svgIndustry, {
title: "行业占比",
data: {
labels: chartData.industry_labels,
datasets: [
{
data: chartData.industry_data,
},
],
},
});
if (data.StockCheckResults) {
var stockCheckResult = data.StockCheckResults[fund.code];
$(`#${fund.code}`).append(
Expand Down

0 comments on commit 60b5e74

Please sign in to comment.