NamesDefaultToHere(1); // Given a 'Value Colors' property, returns a list of two items: The first is a list of // values, the second a list of colours parseValueColourProperty = Function({vcp}, {Default Local}, v = {}; // Values c = {}; // Colours For(i=1, i<=NItems(vcp), i++, v[i] = Arg(vcp[i], 1); c[i] = Arg(vcp[i], 2); ); EvalList({v, c}) ); // Current table if(IsEmpty(Current Data Table()), dt = Open(), dt = Current Data Table()); dtn = dt << GetName; nr = NRow(dt); nc = NCol(dt); // ********************************************************************************* // Build custom dialog in a window // ********************************************************************************* lbWidth = 130; customDlg = NewWindow("Timelines using "||dtn, BorderBox(left(3),top(2), VListBox( HlistBox( PanelBox("Select Columns", colListData=ColListBox(All,width(lbWidth),nLines(min(nc,10))) ), PanelBox("Cast Selected Columns into Roles", LineUpBox(NCol(2), Spacing(3), ButtonBox("DateTime",DTscript), colListDT = ColListBox(width(lbWidth),nLines(1),MinItems(1),MaxItems(1),Numeric), ButtonBox("Process",PRscript), colListPR = ColListBox(width(lbWidth),nLines(10),MinItems(1)), VListBox( TextBox("'Process' columns must:", << FontColor("Blue")), TextBox(" - Be Ordinal or Nominal", << FontColor("Blue")), TextBox(" - Have a 'Value Color' property", << FontColor("Blue")), TextBox(" - Not have a 'Value Label' property", << FontColor("Blue")), ) ) ), PanelBox("Action", LineupBox(NCol(1), ButtonBox("OK", OKScript), ButtonBox("Cancel", customDlg << CloseWindow), SpacerBox(Size(10, 10)), ButtonBox("Remove", colListDT << RemoveSelected; colListPR << RemoveSelected) ) ) ) // End of HListBox ) // End of VListBox ) // End of BorderBox ); // End of NewWindow // Add a valid datTime column DTscript = Expr( sel = colListData<=1, c--, modType = Column(dt, sel[c]) << getModelingType; vc = Column(dt, sel[c]) << getProperty("Value Colors"); vl = Column(dt, sel[c]) << getProperty("Value Labels"); if(modType == "Continuous" | IsEmpty(vc) |!IsEmpty(vl), RemoveFrom(sel, c); Beep()); ); colListPR << Append(sel); ); // Do the work . . . OKscript = Expr( customDlg << CloseWindow; // Unload the dialog colDT = (colListDT << getItems)[1]; cList = colListPR << getItems; // Get the datetime values dtVals = Column(dt, colDT) << getValues; // Make a graph nw = NewWindow("Timelines from "||dtn, gb = GraphBox(Title("Timelines from "||dtn), FrameSize(800, 500), XScale(dtVals[1], dtVals[NRow(dtVals)]), YScale(0, 1)), PanelBox("Key", tb = TableBox()) ); // Obtain a list of all the Axis Boxes in the report gbAxis = nw << XPath( "//AxisBox" ); // Update the x axis (Modify 'by hand', copy the axis settings then 'Paste JSL') gbAxis[2] << Scale( "Linear" ) << Format( "ddMonyyyy h:m", 19 ) << Min( dtVals[1] ) << Max( dtVals[NRow(dtVals)] ) << Interval( "Day" ) << Inc( 1 ) << Minor Ticks( 1 ) << Label Row Nesting( 1 ) << Label Row( {Minor Grid Line Color( -15790320 ), Show Minor Labels( 0 ), Tick Offset( 0 ), Inside Ticks( 0 ), Label Orientation( "Angled" ), Show Minor Grid( 0 ), Show Major Labels( 1 ), Show Minor Ticks( 0 ), Major Grid Line Color( -14145495 ), Show Major Ticks( 1 ), Automatic Tick Marks( 0 ), Show Major Grid( 0 ), Automatic Font Size( 0 )} ); // Update the y axis (Modify 'by hand', copy the axis settings then 'Paste JSL') gbAxis[1] << Scale( "Linear" ) << Format( "Fixed Dec", 12, 1 ) << Min( 0 ) << Max( NItems(cList) ) << Interval( "Numeric" ) << Inc( 1 ) << Minor Ticks( 1 ) << Label Row Nesting( 1 ) << Label Row( {Minor Grid Line Color( -15790320 ), Show Minor Labels( 0 ), Tick Offset( 0 ), Inside Ticks( 0 ), Label Orientation( "Horizontal" ), Show Minor Grid( 0 ), Show Major Labels( 0 ), Show Minor Ticks( 0 ), Major Grid Line Color( -14145495 ), Show Major Ticks( 0 ), Automatic Tick Marks( 0 ), Show Major Grid( 0 ), Automatic Font Size( 0 )} ); // Loop over 'process' columns keyList = {}; For(cc=1, cc<=NItems(cList), cc++, colName = Column(dt, cList[cc]) << getName; colVals = Column(dt, cList[cc]) << getValues; // Get allowed colours from the 'Value Colors' column property vc = Column(dt, cList[cc]) << getProperty("Value Colors"); InsertInto(keyList, colName); // (1) Get the (unique) values and their colours {v, c} = parseValueColourProperty(vc); // (2) Reconstruct a vector of required fill colours to correspond to 'colVals' colValsColors = J(NRow(dtVals), 1, .); For(t=2, t<=NRow(dtVals), t++, colValsColors[t] = c[Loc(v, colVals[t-1])[1]] ); // (3) Define a template to add the graphics script for the current timeline ags = Expr( nw[FrameBox(1)] << addGraphicsScript ( 1, Description("Timeline for "||colName), dateTimeVecTBD; colorVecTBD; For(t=2, t<=tMaxTBD, t++, // (3) Get and set the required pen and fill colour PenColor(colorVecTBD[t]); FillColor(colorVecTBD[t]); // (4) Draw the filled rectangle Rect(dateTimeVecTBD[t-1], ccTBD, dateTimeVecTBD[t], ccTBD-1, 1); ) ) ); // (5) Add the graphics script SubstituteInto(ags, Expr(dateTimeVecTBD), Eval(dtVals), Expr(colorVecTBD), Eval(colValsColors), Expr(tMaxTBD), Eval(NRow(dtVals)), Expr(ccTBD), Eval(cc) ); ags; ); // Add the key tb << Append(StringColBox("Column", Reverse(keyList))); );