Ejemplo n.º 1
0
 /// <summary>
 /// 設定 Figure region 的位置 (4個座標值,依序為 xmin, xmax, ymin ymax)
 /// </summary>
 /// <param name="args"></param>
 public override void SetCoordinate(params object[] args)
 {
     if (args.Length != 4)
     {
         throw new ArgumentException("Figure 有不正確的參數個數,必須為 4 個!");
     }
     _coord = MtbTools.ConvertInputToDoubleArray(args);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 取得 Chart option 的指令碼 (GSave, WTitle)
        /// </summary>
        /// <returns></returns>
        public virtual string GetOptionCommand()
        {
            StringBuilder cmnd = new StringBuilder();

            if (GraphPath != null)
            {
                if (MtbTools.VerifyGraphPath(GraphPath))
                {
                    cmnd.AppendFormat(" GSave \"{0}\";\r\n", GraphPath);
                    System.Text.RegularExpressions.Regex regex =
                        new System.Text.RegularExpressions.Regex(@".*?\.(mgf|png|gif|bmp|tif|emf)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regex.IsMatch(GraphPath))
                    {
                        System.Text.RegularExpressions.Match m = regex.Match(GraphPath);
                        string f = m.Groups[1].ToString().ToUpper();
                        switch (f)
                        {
                        case "PNG":
                            f = "PNGH";
                            break;

                        case "BMP":
                            f = "BMPH";
                            break;

                        default:
                            break;
                        }
                        cmnd.AppendLine(string.Format("  {0};", f));
                    }
                    else
                    {
                        cmnd.AppendLine("  JPEG;");
                    }
                    cmnd.AppendLine("  Replace;");
                }
            }
            if (WTitle != null)
            {
                cmnd.AppendFormat(" Wtitle \"{0}\";\r\n", WTitle);
            }

            return(cmnd.ToString());
        }
Ejemplo n.º 3
0
 public override void SetLabels(dynamic labels)
 {
     _labels = MtbTools.ConvertInputToStringArray(labels);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 設定連續 Scale 的 tick 位置
 /// </summary>
 /// <param name="ticks">可輸入 string (e.g. 欄位名稱 or 已處理過的位置) 或是 string[]</param>
 public override void SetTicks(dynamic ticks = null)
 {
     _ticks = MtbTools.ConvertInputToStringArray(ticks);
 }
Ejemplo n.º 5
0
        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());
        }