| Quintiq file version 2.0 | 
| #parent: DataHolderPeriods | 
| Response OnDataChanged () id:Response_BaseFormCapacityPlanning_DataHolderPeriods_OnDataChanged | 
| { | 
|   #keys: '[136682.2.891024112]' | 
|   CanBindMultiple: false | 
|   DefinitionID: 'Responsedef_WebComponent_OnDataChanged' | 
|   QuillAction | 
|   { | 
|     Body: | 
|     [* | 
|       //Zoom based on selected granularity in navigation panel | 
|       data :=  ApplicationMacroPlanner.DataHolderPeriods().Data().Copy(); // refer to global dataholder as this.Data seems referring to old data  | 
|       totalfutureperiods := counter( data, Elements, period, true, not period.IsHistorical() );  | 
|       level :=1; | 
|       // when total period more than 10, zoomlevel will be 10% of the total future periods bucket  | 
|       if ( totalfutureperiods > 10 ) | 
|       { | 
|         level := floor( 0.1 * totalfutureperiods ) ;   | 
|       } | 
|       // sort by time unit level, 1-Hour, 2-Day, 3-Week, 4-Month, 5-Quarter, 6-Year | 
|       timeunits := selectuniquevalues( data, Elements, period, true, [String]period.TimeUnitLevel() + "-" + period.TimeUnit() );  | 
|       timeunits := selectsortedset( timeunits, Elements, e, true, e.Tokenize( "-" ).Element( 0 ) );// tokenized to sort by time unit level from Day->Week->Month->Quarter->Year   | 
|       customzoomrange := JSON::Array(); | 
|        | 
|       traverse( timeunits, Elements, element ) | 
|       { | 
|         timeunit := element.Tokenize( "-" ).Element( 1 ); | 
|            | 
|         isquarter := timeunit = Translations::MP_GlobalParameters_Quarter(); | 
|         size := counter( data, Elements, period, true, not period.IsHistorical() and period.TimeUnit() = timeunit ); | 
|         maxloop := size/ level; | 
|         unit := ifexpr( isquarter, Translations::MP_GlobalParameters_Month(), timeunit ) ; //Quarter is not supported, replace with month | 
|         //minimum keep 2 buckets - if zoom in | 
|         for ( i := 2; i <= maxloop; i++ ) | 
|         { | 
|           loop := i; | 
|            | 
|           if ( i > 2 ) | 
|           { | 
|              loop := loop * level; | 
|           } | 
|            | 
|           loop := loop * ifexpr( isquarter, 3, 1 ) // time 3 if is in quarter, default * 1; | 
|           // Core Tech granularity is plural thus we add "s" to it | 
|           zoomLevel := unit + "s"; | 
|           zoom1 := JSON::Object(); | 
|           zoom1.Add( 'unit', zoomLevel ); | 
|           zoom1.Add( 'count', loop ); | 
|           customzoomrange.Add( zoom1); | 
|         } | 
|       } | 
|        | 
|       GanttChartCapacityPlanning.NavigationRange( customzoomrange.Build() ); | 
|        | 
|       //Snap to gantt chart | 
|       Form.SnapToGanttChart(); | 
|     *] | 
|     GroupServerCalls: false | 
|   } | 
| } |