OcttKB/Wiki-OcttKB/plugins/echarts-addons/$__addon_sevenday.js

10 lines
2.7 KiB
JavaScript

/*\
title: $:/addon/sevenday.js
module-type: echarts-component
type: application/javascript
description: 折线图
\*/
const e=(e,t="created")=>$tw.wiki.filterTiddlers(`[sameday:${t}[${e}]!is[system]!has[draft.of]]`).length,t=e=>new Date(`${e.substr(0,4)}-${e.substr(4,2)}-${e.substr(6,2)}`),a={title:"最近文章动态",opacity:.8,xLegend:"日期",yLegend:"文章数量",lineWidth:0,symbolSize:0},o={onUpdate(o,i,s){const{days:r,date:d,title:n=a.title,subtitle:l="",disableClick:c="no"}=s,f=function(e,a=7){const o=e?t(e):new Date,i=[];for(let e=0;e<a;e++){const e=o.getFullYear(),t=String(o.getMonth()+1).padStart(2,"0"),a=String(o.getDate()).padStart(2,"0");i.unshift(e+t+a),o.setDate(o.getDate()-1)}return i}(d,r),m=[],h=[];f.forEach((t=>m.push(e(t)))),f.forEach((t=>h.push(e(t,"modified"))));const y={title:{text:n,subtext:l,left:"center",top:"bottom"},legend:{data:["created","modified"]},toolbox:{feature:{restore:{}}},tooltip:{trigger:"item",
// type: 'cross',
formatter:function(e){const{name:a,value:o,seriesName:i}=e,s=t(a).toLocaleDateString();return"created"===i?o?`${s} 新增了 ${o} 篇文章`:`${s} 没有新增文章`:o?`${s} 更新了 ${o} 篇文章`:`${s} 没有文章更新`}},xAxis:{boundaryGap:!0,type:"category",data:f,name:a.xLegend},yAxis:{type:"value",name:a.yLegend},animationDuration:2e3,series:[{name:"created",data:m,type:"line",showSymbol:!1,symbolSize:a.symbolSize,stack:"Total",lineStyle:{width:a.lineWidth},endLabel:{show:!0,formatter:"{a}",distance:20},areaStyle:{opacity:a.opacity,color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:"rgb(55, 162, 255)"},{offset:1,color:"rgb(116, 21, 219)"}])},emphasis:{focus:"series",itemStyle:{scale:1.5,shadowOffsetX:0,shadowColor:"rgba(0, 0, 0, 0.5)"}},smooth:!0},{name:"modified",data:h,lineStyle:{width:a.lineWidth},symbolSize:a.symbolSize,stack:"Total",type:"line",showSymbol:!1,endLabel:{show:!0,formatter:"{a}",distance:20},areaStyle:{opacity:a.opacity,color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:"rgb(128, 255, 165)"},{offset:1,color:"rgb(1, 191, 236)"}])},emphasis:{focus:"series",itemStyle:{scale:1.25,shadowOffsetX:0,shadowColor:"rgba(0, 0, 0, 0.5)"}},smooth:!0}]};o.setOption(y),o.on("dblclick","series",(function(e){const{name:t,value:a,seriesName:o}=e,i=new $tw.Story,s=`[sameday:${o}[${t}]!is[system]!has[draft.of]]`;a&&($tw.rootWidget.invokeActionString('<$action-setfield $tiddler="$:/temp/advancedsearch" text="""'+s+'"""/><$action-setfield $tiddler="$:/temp/advancedsearch/input" text="""'+s+'"""/><$action-setfield $tiddler="$:/temp/advancedsearch/refresh" text="yes"/><$action-setfield $tiddler="$:/state/tab--1498284803" text="$:/core/ui/AdvancedSearch/Filter"/>'),i.navigateTiddler("$:/AdvancedSearch"))}))},shouldUpdate:()=>!1};module.exports=o;