function toggleMode(t){t.enabled=!t.enabled;if(t.enabled){t.innerHTML="恢复比例";saveConfig();zoomToFit()}else{t.innerHTML="适宜比例";restoreConfig();gantt.render()}}var cachedSettings={};function saveConfig(){var t=gantt.config;cachedSettings={};cachedSettings.scale_unit=t.scale_unit;cachedSettings.date_scale=t.date_scale;cachedSettings.step=t.step;cachedSettings.subscales=t.subscales;cachedSettings.template=gantt.templates.date_scale;cachedSettings.start_date=t.start_date;cachedSettings.end_date=t.end_date}function restoreConfig(){applyConfig(cachedSettings)}function applyConfig(t,e){gantt.config.scale_unit=t.scale_unit;if(t.date_scale){gantt.config.date_scale=t.date_scale;gantt.templates.date_scale=null}else{gantt.templates.date_scale=t.template}gantt.config.step=t.step;gantt.config.subscales=t.subscales;if(e){gantt.config.start_date=gantt.date.add(e.start_date,-1,t.unit);gantt.config.end_date=gantt.date.add(gantt.date[t.unit+"_start"](e.end_date),2,t.unit)}else{gantt.config.start_date=gantt.config.end_date=null}}function zoomToFit(){var t=gantt.getSubtaskDates(),e=gantt.$task.offsetWidth;for(var a=0;a<scaleConfigs.length;a++){var n=getUnitsBetween(t.start_date,t.end_date,scaleConfigs[a].unit,scaleConfigs[a].step);if((n+2)*gantt.config.min_column_width<=e){break}}if(a===scaleConfigs.length){a--}applyConfig(scaleConfigs[a],t);gantt.render()}function getUnitsBetween(t,e,a,n){var s=new Date(t),d=new Date(e);var i=0;while(s.valueOf()<d.valueOf()){i++;s=gantt.date.add(s,n,a)}return i}var scaleConfigs=[{unit:"minute",step:1,scale_unit:"hour",date_scale:"%H",subscales:[{unit:"minute",step:1,date:"%H:%i"}]},{unit:"hour",step:1,scale_unit:"day",date_scale:"%j %M",subscales:[{unit:"hour",step:1,date:"%H:%i"}]},{unit:"day",step:1,scale_unit:"month",date_scale:"%F",subscales:[{unit:"day",step:1,date:"%j"}]},{unit:"week",step:1,scale_unit:"month",date_scale:"%F",subscales:[{unit:"week",step:1,template:function(t){var e=gantt.date.date_to_str("%d %M");var a=gantt.date.add(gantt.date.add(t,1,"week"),-1,"day");return e(t)+" - "+e(a)}}]},{unit:"month",step:1,scale_unit:"year",date_scale:"%Y",subscales:[{unit:"month",step:1,date:"%M"}]},{unit:"month",step:3,scale_unit:"year",date_scale:"%Y",subscales:[{unit:"month",step:3,template:function(t){var e=gantt.date.date_to_str("%M");var a=gantt.date.add(gantt.date.add(t,3,"month"),-1,"day");return e(t)+" - "+e(a)}}]},{unit:"year",step:1,scale_unit:"year",date_scale:"%Y",subscales:[{unit:"year",step:5,template:function(t){var e=gantt.date.date_to_str("%Y");var a=gantt.date.add(gantt.date.add(t,5,"year"),-1,"day");return e(t)+" - "+e(a)}}]},{unit:"year",step:10,scale_unit:"year",template:function(t){var e=gantt.date.date_to_str("%Y");var a=gantt.date.add(gantt.date.add(t,10,"year"),-1,"day");return e(t)+" - "+e(a)},subscales:[{unit:"year",step:100,template:function(t){var e=gantt.date.date_to_str("%Y");var a=gantt.date.add(gantt.date.add(t,100,"year"),-1,"day");return e(t)+" - "+e(a)}}]}];