Tabulation Script
Contents
Tabulation Script
Tabulation Script is a CGScript library allowing user to create diagram/report. It's also capable of setting stylesheet (both external and internal).
Some classes
- CGScript_System_Report: CGScript library implementation, contains all entry points to diagram/report generation process
- TabulationModuleUtilities: contains utility methods
- DiagramUtilities: also contains utility methods
- TabulationDiagram: wrapper class for the REAL report diagram
- TabulationConfiguration: contains all result of tabulation diagram (the name ??!!!!)
Understanding tabulation script processing
The processing of tabulation script can be understand as below:
- Create new Interpreter (which create also an instance of TabulationConfiguration as properties named TabulationConfig )
- Run the tabulation script => the result diagrams (if any) is stored inside DiagramCharts variable of TabulationConfiguration
- If has to show result, get the result diagram objects from DiagramCharts and set to session
- Show a SPECIFIC viewer that takes diagram objects from session and draw on screen (why do we need a SPECIFIC viewer?)
Injecting new processing with least impact
Moving script location
Due to the fact that tabulation script belongs to REPORT DOMAIN rather RUNTIME DOMAIN, it MUST be in the same assembly with REPORT. And to not change so much at the same time, the file CGScript_System_Report is 'copied' to CatGlobe.Report assembly under folder Script. The namespace was also changed to TODO.
Now, we have a class diagram:
CGScript_System_Report = TabulationDiagram, TabulationConfiguration
Custom static Instance
- HashTable
- static string
Point of injections
TabulationDiagram
As shown in processing of tabulation script section above, we need to HACK the TabulationDiagram o create the REAL report diagram because it wraps the REAL report inside. The original code looks as below:
private void CreateInternalDiagram()
{
...
// Provide outside
InternalDiagram = DiagramUtilities.CreateDiagram(this.ReportTemplate
, this.CrossStruct
, this.Parameter.InternalStyle
, this.ChartName
, this.Generator.Header
, this.Generator.Title
, this.Generator.Parameter.ChartType
, DiagramType.CrossDiagram
, subtitle1, string.Empty, string.Empty);
, subtitle1, string.Empty, string.Empty);
...
}
To inject our processing
After checking the current code, I come to the final place that all the processing of tabulation script must go through to create a diagram. And that is the perfect candidate for injecting new report processing. It is method CreateDiagram of CGScript_System_Report, the code is as below:
private static int CreateDiagram(List<Axis> columns, List<Axis> rows, FunctionIdentifier function)
{
if (columns.Count > 2 || rows.Count > 2)
throw new RuntimeException(string.Format("Crossing too many rows and columns may crash the server. A limit of 2 rows and 2 columns is set at the moment. Function '{0}' failed.", function.Name));
Interpreter interpreter = function.Interpreter;
TabulationConfiguration config = interpreter.TabulationConfig;
Parameter p = config.DiagramParameter;
p.Weight = interpreter.WeightColumnName;
p.Filters = interpreter.FilterExpressionList.ToArray();
p.DataCache = interpreter.DataCacheSpecification;
p.ColumnList = columns;
p.RowList = rows;
p.SourceTable = function.Interpreter.SourceTable;
ValidateConfiguration(function);
config.DiagramGenerator = new CrossDiagramGenerater { Parameter = p };
//generate the expression table and result table
CrossDiagramGenerater.CrossStructure crossStruct = config.DiagramGenerator.BuildCrossEx();
DataTableFunctions.FormatDataTableValue(crossStruct.DataTable, TabulationModuleConstants.DEFAULT_DECIMAL_POSITION, TabulationModuleConstants.DEFAULT_CULTURE, config.ShowErrorInResult);
//generate the xml string based on the configuration
TabulationDiagram diagram = TabulationModuleUtilities.CreateDiagramObject(crossStruct, config);
if (diagram == null)
throw new RuntimeException(string.Format("Cannot generate this type of chart: '{0}'. Function '{1}' failed.", config.DiagramParameter.ChartType, function.Name));
config.DiagramCharts.Add(diagram);
return config.DiagramCharts.Count;
}