Chart_wev8.js 4.75 KB
define("Chart_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}">\t<div class="wev-chart-container">\t\t$${loading.content}\t\t{@if advancedSearch && (advancedSearch == \'1\' || advancedSearch.enable)}\t\t<a href="javascript:void(0);"><i></i></a>\t\t{@/if}\t\t<div class="wev-chart" id="wev-chart_${id}_${pageid}" style="${style}"></div>\t\t<div class="wev-error" style="display:none;"></div>\t</div></div>'}),define(["mUtil","Component","wev-loading","chartHelper"],function(d,t,a,o){return t.init(function(e){var r,l,c={};t.super(this,e),this.type="Chart",this.tpl=this.type+"_html",this.css="chart_css",this.components={loading:new a({delay:300,animation:1})};var s=this.viewModel={data:[],chartType:"Column2D",height:300,linecolor:"blue",title:{name:"",color:"black",font:"Verdana",fontsize:14,fontweight:"normal"},labelFormat:"",advancedSearch:{},option:{},standalone:!0};this.beforeMount=function(){var e,t=s.height||300;e=d.toPixel(t,"height"),s.width&&(e+=d.toPixel(s.width,"width")),s.title.text=s.title.name,s.style=e,s.height=t,s.linecolor=s.linecolor||"blue",s.width=s.width||$(document).width(),s.pageid=this.pageid||"",delete s.title.name},this.mounted=function(){r=this.$el.find(".wev-error"),l=this.$el.find(".wev-chart"),this.refresh()},this.refresh=function(){var e=this.components.loading;e.setRefs(this.$comp,"wev-refreshing"),e.show();var t=e.hide.bind(e);s.standalone&&d.isArray(s.data)?c.preBuildChart(s.chartType,s.data,t):c.loadData(t)},this.cacheSearchLast=function(e){s.searchLast=e},c.loadData=function(t){var a=this,n=$(".wev-chart",this.$el),i=$(".wev-chart-container>a",this.$el),e=s.data,o=(new Date).valueOf();a.timestamp=o,s.standalone||(e=d.getActionUrl(a.type,{action:"getDatas",mec_id:a.id},a.pageid)),e&&d.getJSON(e,{},function(e){o==a.timestamp&&(n.show().html(""),c.preBuildChart(s.chartType,e.data,t),r.html("").hide(),s.advancedSearch.enable&&(i.css("left",.1*s.width+"px"),i.show(),i.on("click",function(){require(["mService"],function(e){e.show("customsearch",{id:a.id,pageid:a.pageid,searchLast:s.searchLast||{},conditions:s.advancedSearch.asFields,title:s.title.text||""})})})))},function(e){r.html(e).show(),l.hide(),d.isFunction(t)&&t.call(this)})},c.preBuildChart=function(e,t,a){require(["ichart"],function(){try{c.buildChart[e](t)}catch(e){console.error(e.message)}"function"==typeof a&&a.call(this)})};var i=function(e,t,a){var n=$.extend(!0,{},{render:"wev-chart_"+s.id+"_"+s.pageid,data:e,title:s.title,animation:!0,animation_duration:800,height:s.height,width:s.width,align:"center",border:!1,background_color:null,turn_off_touchmove:!0},t);return!1!==a&&(n.radius="90%"),n};c.buildChart={Column2D:function(e){new iChart.Column2D(i(e,{sub_option:{label:{color:"#111111"},listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}}},coordinate:{background_color:"#fefefe",scale:[{position:"left"}]}},!1)).draw()},Column3D:function(e){new iChart.Column3D(i(e,{sub_option:{label:{color:"#111111"},listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}}},coordinate:{scale:[{position:"left"}]}},!1)).draw()},Pie2D:function(e){new iChart.Pie2D(i(e,{sub_option:{listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}},label:{background_color:null,sign:!1,padding:"0 4",border:{enable:!1,color:"#666666"},fontsize:11,fontweight:600,color:"#4572a7"}}})).draw()},Pie3D:function(e){new iChart.Pie3D(i(e,{sub_option:{listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}},label:{background_color:null,sign:!1,padding:"0 4",border:{enable:!1,color:"#666666"},fontsize:11,fontweight:600,color:"#4572a7"}}})).draw()},Donut2D:function(e){new iChart.Donut2D(i(e,{sub_option:{listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}},label:{background_color:null,sign:!1,padding:"0 4",border:{enable:!1,color:"#666666"},fontsize:11,fontweight:600,color:"#4572a7"}}})).draw()},Line2D:function(e){var t=[],a=[];e.forEach(function(e){a.push(e.name),t.push(e.value)});var n=[{name:"line",value:t,color:s.linecolor,line_width:2}];new iChart.LineBasic2D(i(n,{labels:a,sub_option:{hollow_inside:!1,point_size:10,listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}},label:{background_color:null,sign:!1,padding:"0 4",border:{enable:!1,color:"#666666"},fontsize:11,fontweight:600,color:"#4572a7"}}})).draw()},Area2D:function(e){var t=[],a=[];e.forEach(function(e){a.push(e.name),t.push(e.value)});var n=[{name:"line",value:t,color:s.linecolor,line_width:2}];new iChart.Area2D(i(n,{labels:a,sub_option:{hollow_inside:!1,point_size:10,listeners:{parseText:function(e,t){return o.formatNumber(t,s.labelFormat)}},label:{background_color:null,sign:!1,padding:"0 4",border:{enable:!1,color:"#666666"},fontsize:11,fontweight:600,color:"#4572a7"}}})).draw()}},c.loadData=c.loadData.bind(this)})});