我在小工具xml文件中看到,我在其中编写视图部分以创建每个小工具总是相同代码的图表,是否可以更清晰?比如创建要导入的外部Javascript文件?可能外部文件的问题是获取数据。
这是代码:
view: {
enableReload: true,
onResizeReload: true,
onResizeAdjustHeight: true,
template: function (args) {
var gadget = this;
gadget.getView().empty();
gadget.projectOrFilterName = args.chart.filterName;
var container = AJS.$("<div id='chart_div'/>");
gadget.getView().append(container);
if(args.chart.data && args.chart.data.length > 0) {
var data = new google.visualization.DataTable();
data.addColumn('string', this.getMsg("gadget.user.activity.time.label"));
data.addColumn('number', this.getMsg("gadget.user.activity.issues.solving.label"));
data.addColumn('number', this.getMsg("gadget.user.activity.sum.label"));
data.addRows(args.chart.data);
switch(gadget.getPref("chartType"))
{
case "ColumnChart":
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
break;
case "AreaChart":
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
break;
case "LineChart":
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
break;
}
var width = gadgets.window.getViewportDimensions().width;
var height = width * 3/4;
chart.draw(
data,
{width: width, height: height,
curveType: "function",
legend: 'bottom',
backgroundColor:{fill:'#DDE8FF'},
vAxis: { textStyle:{fontSize:10},
baseline:0,
baselineColor:'#9F0000'},
hAxis: {textStyle:{fontSize:10},
slantedText:'true',
slantedTextAngle:45},
colors:['#566D7E','orange'],
fontName:'Trebuchet MS',
pointSize: 2
});
}
else {
gadget.getView().append("<p>No Data available</p>");
}
gadget.resize();
},
答案 0 :(得分:1)
您应该在atlassian-plugin.xml中包含您自己的JS,如下所示:
<!-- GADGET WEB RESOURCES -->
<web-resource key="resources">
<resource type="download" name="javascript/common.js" location="javascript/MyCustomLibrary.js">
<property key="content-type" value="text/javascript"/>
</resource>
<!-- ... -->
</web-resource>
然后,将其添加到plugin.xml
中#requireResource("plugin-key:resources")
最后,从您的小工具对象视图部分调用您的JS函数:
CustomFunction(gadget, data);
希望能帮到你, 问候。