private string DefaultCommand2() { if (Variables == null) { throw new Exception("建立 Bar chart 指令時,未給定 Variables"); } Mtb.Column[] vars = (Mtb.Column[])Variables; Mtb.Column[] gps = null; if (GroupingVariables != null) { gps = (Mtb.Column[])GroupingVariables; } switch (BarsRepresent)// 以一次畫一張圖為目的,過濾掉不合法的輸入數量 { case ChartRepresent.COUNT_OF_UNIQUE_VALUES: case ChartRepresent.A_FUNCTION_OF_A_VARIABLE: case ChartRepresent.ONE_WAY_TABLE: if (vars.Length > 1) { throw new ArgumentException( string.Format("BarsRepresent={0}時,不支援同時繪製多變數", BarsRepresent.ToString())); } break; } switch (BarsRepresent)// 判斷群組數是否合法 { case ChartRepresent.ONE_WAY_TABLE: case ChartRepresent.TWO_WAY_TABLE: if (gps == null) { throw new Exception("(Bar chart)使用 Summaried Data,至少給定一個分群欄位"); } break; } StringBuilder cmnd = new StringBuilder(); // local macro 內容 cmnd.AppendLine("macro"); cmnd.AppendLine("chart y.1-y.n;"); cmnd.AppendLine("group x.1-x.m;"); cmnd.AppendLine("pane p.1-p.k;"); //如果使用者有指定 panel cmnd.AppendLine("datlab dlab."); //如果使用者有自己指定 column for datlab cmnd.AppendLine("mcolumn y.1-y.n"); cmnd.AppendLine("mcolumn x.1-x.m"); cmnd.AppendLine("mcolumn p.1-p.k"); cmnd.AppendLine("mcolumn yy ylab stkdlab dlab xx.1-xx.m"); cmnd.AppendLine("mconstant nn"); //準備使用於圖中的額外資料 Datlab tmpDatlab = (Datlab)DataLabel.Clone(); if (StackType == ChartStackType.Stack && DataLabel.Visible && AdjDatlabAtStackBar) { #region 建立 Adjust stack bar chart 要的 datlab switch (BarsRepresent) { case ChartRepresent.COUNT_OF_UNIQUE_VALUES: cmnd.AppendLine("count y.1 nn"); cmnd.AppendLine("set yy"); cmnd.AppendLine("(1)nn"); cmnd.AppendLine("end"); cmnd.AppendLine("stat yy;"); cmnd.AppendLine("by y.1 x.1-x.m;"); cmnd.AppendLine("sums stkdlab."); break; case ChartRepresent.A_FUNCTION_OF_A_VARIABLE: cmnd.AppendLine("stat y.1;"); cmnd.AppendLine("by x.1-x.m;"); cmnd.AppendFormat("{0} stkdlab.\r\n", FuncType.ToString().ToLower() == "sum" ? "sums" : FuncType.ToString().ToLower()); break; case ChartRepresent.ONE_WAY_TABLE: cmnd.AppendLine("copy y.1 stkdlab"); break; case ChartRepresent.TWO_WAY_TABLE: cmnd.AppendLine("stack y.1-y.n yy."); cmnd.AppendLine("count y.1 nn"); cmnd.AppendLine("tset ylab"); cmnd.AppendFormat("1({0})nn\r\n", string.Join(" &\r\n", vars.Select(x => "\"" + x.Name + "\"").ToArray())); cmnd.AppendLine("end"); List <string[]> gpData = new List <string[]>(); for (int i = 0; i < gps.Length; i++) { Mtb.Column col = gps[i]; string[] data; switch (col.DataType) { case MtbDataTypes.DataUnassigned: throw new ArgumentNullException("輸入的欄位沒有資料"); default: case MtbDataTypes.DateTime: case MtbDataTypes.Numeric: data = ((double[])col.GetData()).Select(x => x.ToString()).ToArray(); break; case MtbDataTypes.Text: data = col.GetData(); break; } cmnd.AppendFormat("tset xx.{0}\r\n", i + 1); cmnd.AppendFormat("{1}({0})1\r\n", string.Join(" &\r\n", data.Select(x => "\"" + x + "\"").ToArray()), vars.Length); cmnd.AppendLine("end"); cmnd.AppendLine("vorder ylab xx.1-xx.m;"); cmnd.AppendLine("work."); cmnd.AppendLine("stat yy;"); cmnd.AppendLine("by ylab xx.1-xx.m;"); cmnd.AppendLine("sums stkdlab."); } break; default: break; } cmnd.AppendLine("text stkdlab stkdlab"); #endregion tmpDatlab.LabelColumn = "stkdlab"; tmpDatlab.Placement = new double[] { 0, -1 }; } else { if (DataLabel.LabelColumn != null) { tmpDatlab.LabelColumn = "dlab"; } } switch (BarsRepresent) { case ChartRepresent.COUNT_OF_UNIQUE_VALUES: cmnd.AppendLine("Chart y.1-y.n;"); if (gps != null) { cmnd.AppendLine("Group x.1-x.n;"); } break; case ChartRepresent.A_FUNCTION_OF_A_VARIABLE: cmnd.AppendFormat("Chart {0}(y.1-y.n) &\r\n", FuncType.ToString()); if (gps != null) { cmnd.AppendLine("*x.1;"); if (gps.Length >= 2) { cmnd.AppendLine(" Group x.2-x.m;"); } } else { cmnd.AppendLine(";"); } break; case ChartRepresent.ONE_WAY_TABLE: case ChartRepresent.TWO_WAY_TABLE: cmnd.AppendLine("Chart (y.1-y.n)*x.1;"); cmnd.AppendLine("Summarized;"); if (BarsRepresent == ChartRepresent.TWO_WAY_TABLE) { cmnd.AppendLine("Overlay;"); if (TableArrangement == ChartTableArrangementType.RowsOuterMost) { cmnd.AppendLine(" VLast;"); } else { cmnd.AppendLine(" VFirst;"); } } if (gps.Length >= 2) { cmnd.AppendLine(" Group x.2-x.m;"); } break; } if (Transponse) { cmnd.AppendLine("trans;"); } if (StackType == ChartStackType.Stack) { cmnd.AppendLine("stack;"); } cmnd.Append(GetOptionCommand()); cmnd.Append(YScale.GetCommand()); cmnd.Append(XScale.GetCommand()); cmnd.Append(tmpDatlab.GetCommand()); /* * 對每一個 DataView 建立 Command * 這些處理是為了將 GroupingBy 屬性由原欄位換成 macro coded name */ Component.DataView.DataView tmpDataview; string[] xStr = gps.Select((x, i) => "x." + (i + 1)).ToArray(); foreach (Component.DataView.DataView dview in new Component.DataView.DataView[] { Bar, Symbol, Connectline }) { tmpDataview = (Component.DataView.DataView)dview.Clone(); if (dview.GroupingBy != null) { string[] g = MtbTools.ConvertToMacroCodedName( (string[])tmpDataview.GroupingBy, gps, xStr, _ws); } //if (dview is Component.DataView.Bar) //{ // if(Bar.AssignAttributeByVariables) //} cmnd.Append(tmpDataview.GetCommand()); } Component.MultiGraph.MPanel tmpPane = (Component.MultiGraph.MPanel)Panel.Clone(); if (Panel.PaneledBy != null) { tmpPane.PaneledBy = "p.1-p.k"; } cmnd.Append(tmpPane.GetCommand()); cmnd.Append(Legend.GetCommand()); if (NoMissing) { cmnd.AppendLine("nomiss;"); } if (NoEmpty) { cmnd.AppendLine("noem;"); } cmnd.Append(GetAnnotationCommand()); cmnd.Append(GetRegionCommand()); cmnd.AppendLine("."); cmnd.AppendLine("endmacro"); return(cmnd.ToString()); }
public string TypeToString(FuncType type) => type.ToString().ToLower();
protected override string DefaultCommand() { if (Variables == null) { throw new Exception("建立 Bar chart 指令時,未給定 Variables"); } Mtb.Column[] vars = (Mtb.Column[])Variables; Mtb.Column[] gps = null; if (GroupingVariables != null) { gps = (Mtb.Column[])GroupingVariables; } if ((BarsRepresent == ChartRepresent.ONE_WAY_TABLE || BarsRepresent == ChartRepresent.TWO_WAY_TABLE) & (gps == null)) { throw new Exception("(Bar chart)使用 Summaried Data,至少給定一個分群欄位"); } StringBuilder cmnd = new StringBuilder(); // local macro 內容 /***************** * 一些注意事項: Chart 可以有多個 Variable 輸入,分成兩類 * 1. F(C...C)*Cg 這是各別F(C)以 Cg 做分群,不需搭配 Summarized * 2. Summarized data,使用 (C...C)*Cg 搭配 Summarized 子命令, * 如果是 Two-way table 則須再加上 VFirst 或 VLast 等指令 * */ switch (BarsRepresent) { case ChartRepresent.COUNT_OF_UNIQUE_VALUES: cmnd.AppendFormat("Chart {0};\r\n", string.Join(" &\r\n", vars.Select(x => x.SynthesizedName).ToArray())); if (gps != null) { cmnd.AppendFormat(" Group {0};\r\n", string.Join(" &\r\n", string.Join(" &\r\n", gps.Select(x => x.SynthesizedName).ToArray()))); } break; case ChartRepresent.A_FUNCTION_OF_A_VARIABLE: cmnd.AppendFormat("Chart {0}({1}) &\r\n", FuncType.ToString(), string.Join(" &\r\n", vars.Select(x => x.SynthesizedName).ToArray())); if (gps != null) { cmnd.AppendFormat("*{0};\r\n", gps[0].SynthesizedName); if (gps.Length >= 2) { cmnd.AppendFormat(" Group {0};\r\n", string.Join(" &\r\n", gps.Select((x, i) => new { colId = x.SynthesizedName, index = i }). Where(x => x.index > 0).Select(x => x.colId).ToArray())); } } else { cmnd.AppendLine(";"); } break; case ChartRepresent.ONE_WAY_TABLE: case ChartRepresent.TWO_WAY_TABLE: cmnd.AppendFormat("Chart ({0})*{1};\r\n", string.Join(" &\r\n", vars.Select(x => x.SynthesizedName).ToArray()), gps[0].SynthesizedName); cmnd.AppendLine("Summarized;"); if (BarsRepresent == ChartRepresent.TWO_WAY_TABLE) { cmnd.AppendLine("Overlay;"); if (TableArrangement == ChartTableArrangementType.RowsOuterMost) { cmnd.AppendLine(" VLast;"); } else { cmnd.AppendLine(" VFirst;"); } } if (gps.Length >= 2) { cmnd.AppendFormat(" Group {0};\r\n", string.Join(" &\r\n", gps.Select((x, i) => new { colId = x.SynthesizedName, index = i }). Where(x => x.index > 0).Select(x => x.colId).ToArray())); } break; } cmnd.Append(GetOptionCommand()); cmnd.Append(YScale.GetCommand()); cmnd.Append(XScale.GetCommand()); // if (StackType == ChartStackType.Stack && DataLabel.Visible && AdjDatlabAtStackBar) { } cmnd.Append(DataLabel.GetCommand()); cmnd.Append(Bar.GetCommand()); cmnd.Append(Symbol.GetCommand()); cmnd.Append(Connectline.GetCommand()); cmnd.Append(Panel.GetCommand()); cmnd.Append(Legend.GetCommand()); cmnd.Append(GetAnnotationCommand()); cmnd.Append(GetRegionCommand()); return(cmnd.ToString() + "."); }