Esempio n. 1
0
        //Lineplot
        public DxChartBatch(DxLineplotSettings mysettings, DataTable dt, string title)
        {
            Initialize();

            _batchsettings = (DxChartSettings)mysettings;

            outputtype = DxOutputtype.Lineplot;
            layout     = mysettings.chartlayout;
            _vars      = mysettings.numvars;
            if (mysettings.agevars != null)
            {
                _vars.AddRange(mysettings.agevars);
            }

            if (mysettings.xaxisvar == "variable")             //This is just one plot
            {
                DxChart chart = new DxLineplot(mysettings, dt);
                chart.AddTitles(title);
                charts.Add(chart);
            }
            else
            {
                //Check to see if "variable" is used in color, if not then loop through all the numvars and create a plot for each
                if (mysettings.colorvar != "variable" & mysettings.panelvar != "variable")
                {
                    foreach (string v in _vars)
                    {
                        if (mysettings.xaxisvar != v)                         //If y is not the same as x, then continue
                        {
                            mysettings.yaxisvar = v;
                            mysettings.seriesby = "id";
                            DxChart chart = new DxLineplot(mysettings, dt);
                            chart.AddTitles(String.Format("{0} {1}", v, title));
                            charts.Add(chart);
                        }
                    }
                }
                // if variable is used as a color
                else
                {
                    DxChart chart = new DxLineplot(mysettings, dt);
                    chart.AddTitles(title);
                    charts.Add(chart);
                }
            }
        }
Esempio n. 2
0
        public DxLineplot(DxLineplotSettings settings, DataTable mydt)         //, string xvar, string yvar, string titleinput, string colorsby)
        {
            _settings = settings;
            Color col = _settings.color(0);

            _markers = new DxMarkerKinds();


            //Need to stack the data because variable is within the plot
            if ((_settings.xaxisvar == "variable" || _settings.colorvar == "variable") &
                _settings.xaxisvar != _settings.colorvar)
            {
                List <string> idvars = new List <string>()
                {
                    "id"
                };
                if (_settings.xaxisvar != "none" & _settings.xaxisvar != "variable" & !idvars.Contains(_settings.xaxisvar))
                {
                    idvars.Add(_settings.xaxisvar);
                }
                if (_settings.colorvar != "none" & _settings.colorvar != "variable" & !idvars.Contains(_settings.colorvar))
                {
                    idvars.Add(_settings.colorvar);
                }
                if (_settings.panelvar != "none" & _settings.panelvar != "variable" & !idvars.Contains(_settings.panelvar))
                {
                    idvars.Add(_settings.panelvar);
                }

                DataTable dt_stacked = DataTableExtensions.StackData(mydt, idvars, _settings.numvars);

                _settings.seriesby = "id";
                //_settings.xaxisvar = "variable";
                _settings.yaxisvar = "value";

                CreateLineplot(dt_stacked);
            }
            else
            {
                CreateLineplot(mydt);
            }
        }
Esempio n. 3
0
 public DxActogram(DxLineplotSettings settings, DataTable dt, Actigraph.ActogramStats mystats) : base((DxLineplotSettings)settings, dt)
 {
     _settings = (DxActogramSettings)settings;
     _stats    = mystats;
     _markers  = new DxMarkerKinds();
 }
Esempio n. 4
0
        public void ProcessOrder(DxChartOrder order)
        {
            if (order.isOrderFilled)             //Already have batches
            {
                order.batches.Clear();
            }

            //Skip the_dpdata stuff if _dt is already populated
            if (_dt == null)
            {
                bool hassameworksheet = order.HasSameWorksheet(_dpdata);

                if (!hassameworksheet)
                {
                    //Need new DPData
                    _dataproject.selectedsheet = order.worksheet;
                    _dpdata = new DPData(_dataproject, order.filter);
                }


                bool hassamefilter = order.HasSameFilter(_dpdata);

                if (!hassamefilter)
                {
                    _dpdata.filter = order.filter;
                }

                _dt = _dpdata.dt;
            }

            //Each order will result in a list of batches
            //List<DxBatchOcharts> batchlist = new List<DxBatchOcharts>();
            List <DxChartBatch> batchlist = new List <DxChartBatch>();

            if (order.list_settings != null)
            {
                foreach (DxChartSettings settings in order.list_settings)
                {
                    #region Histogram
                    if (settings.outputtype == DxOutputtype.Histogram)
                    {
                        DxHistogramSettings mysettings = (DxHistogramSettings)settings;
                        DxChartBatch        batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Barchart
                    else if (settings.outputtype == DxOutputtype.Barchart)
                    {
                        DxBarchartSettings mysettings = (DxBarchartSettings)settings;
                        DxChartBatch       batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Scatterplot
                    else if (settings.outputtype == DxOutputtype.Scatterplot)
                    {
                        DxScatterplotSettings mysettings = (DxScatterplotSettings)settings;

                        if (mysettings.repeatedmeasVarname == "none")
                        {
                            //DxChartBatch batch = new DxChartBatch(mysettings, dt);
                            //PrepareBatch(batch, settings);
                            //batchlist.Add(batch);

                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }
                            }
                        }
                        else if (mysettings.repeatedmeasVarname != "none")
                        {
                            List <string> repeatedmeas_levels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                            List <string> analysisvars = new List <string>();
                            analysisvars.AddRange(mysettings.numvars);
                            if (mysettings.agevars != null)
                            {
                                analysisvars.AddRange(mysettings.agevars);
                            }

                            int n_rptmeas      = repeatedmeas_levels.Count;
                            int n_analysisvars = analysisvars.Count;

                            int ncol1 = utilStats.TriangleNumber(n_rptmeas);


                            List <string> tmpvars  = mysettings.analysisvars();
                            List <string> tmpvarsX = mysettings.analysisvarsX();
                            List <string> tmpvarsY = mysettings.analysisvarsY();


                            #region Process By Mode
                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }

                                if (mode == XYpairType.SameVar_AcrossLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    mysettings.maxCol             = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout = DxLayout.Horizontal;

                                    //Loop over vars, make a batch for each one
                                    foreach (string v in tmpvars)
                                    {
                                        mysettings.manualXandYvars = true;
                                        mysettings.xvars           = new List <string> {
                                            v
                                        };
                                        mysettings.yvars = new List <string> {
                                            v
                                        };
                                        DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                        PrepareBatch(batch1, (DxChartSettings)mysettings);
                                        batch1.batchtitle = String.Format("{0} ACROSS levels of {1}", v, mysettings.repeatedmeasVarname);
                                        batch1.maxCol     = batch1.charts.Count;
                                        batchlist.Add(batch1);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_WithinLevelsOfRptMeas)
                                {
                                    //#2 - treat it as square
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars = null;
                                    mysettings.yvars = null;

                                    mysettings.chartlayout = DxLayout.Upper;
                                    mysettings.maxRow      = tmpvars.Count;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                                    List <string> tmpvars_with_id = new List <string>();
                                    tmpvars_with_id.AddRange(tmpvars);
                                    tmpvars_with_id.Add("id");

                                    DataSubsets dt_rptmeas = new DataSubsets(dt, tmpvars_with_id, mysettings.repeatedmeasVarname);

                                    //Loop across levels of the RptMeas
                                    foreach (DataSubset subset in dt_rptmeas.subsets)
                                    {
                                        DxChartBatch batch2 = new DxChartBatch(mysettings, subset.dt);
                                        PrepareBatch(batch2, (DxChartSettings)mysettings);
                                        batch2.batchtitle = String.Format("Variables WITHIN {0}: {1}", mysettings.repeatedmeasVarname, subset.Vals_ToString());
                                        batch2.maxCol     = batch2.charts.Count;
                                        batchlist.Add(batch2);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_AcrossLevelsOfRptMeas)
                                {
                                    //#2 - back to original
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars           = tmpvarsX;
                                    mysettings.yvars           = tmpvarsY;
                                    mysettings.manualXandYvars = true;
                                    mysettings.chartlayout     = DxLayout.Horizontal;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname))
                                                                  .Distinct().ToList();
                                    //HERE!!!!

                                    for (int i = 0; i < (rptmeasLevels.Count - 1); i++)
                                    {
                                        for (int j = i + 1; j < rptmeasLevels.Count; j++)
                                        {
                                            DataView dv = new DataView(dt);                                             // dt.AsDataView();
                                            dv.RowFilter = String.Format("{0} IN ('{1}','{2}')", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                            DataTable dt_sub = dv.ToTable();

                                            if (dt_sub.Rows.Count > 1)
                                            {
                                                DxChartBatch batch3 = new DxChartBatch(mysettings, dt_sub);
                                                PrepareBatch(batch3, (DxChartSettings)mysettings);
                                                batch3.batchtitle = String.Format("Variables ACROSS {0}:{1} & {2}", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                                batch3.maxCol     = batch3.charts.Count;
                                                batchlist.Add(batch3);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    #region Actogram
                    else if (settings.outputtype == DxOutputtype.Actogram)
                    {
                        DxActogramSettings mysettings = (DxActogramSettings)settings;
                        mysettings.outputtype = DxOutputtype.Actogram;

                        List <string> varnames = new List <string>()
                        {
                            "id"
                        };
                        varnames.AddRange(mysettings.numvars);
                        varnames.Add(mysettings.xaxisvar);
                        varnames.Add(mysettings.colorvar);
                        varnames.RemoveAll(item => item == "variable");
                        varnames.RemoveAll(item => item == "none");


                        DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                            mysettings.panelvar
                        });

                        DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Actogram, mysettings);

                        foreach (DataSubset subset in subsets.subsets)
                        {
                            mysettings.date_txt = subset.dt.AsEnumerable().Min(f => f.Field <string>("report_date"));

                            DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                            foreach (DxChart sub in subbatch.charts)
                            {
                                batch2.charts.Add(sub);
                            }
                        }
                        PrepareBatch(batch2, mysettings);
                        batchlist.Add(batch2);
                    }
                    #endregion

                    #region Lineplot
                    else if (settings.outputtype == DxOutputtype.Lineplot)
                    {
                        DxLineplotSettings mysettings = (DxLineplotSettings)settings;

                        //NO Panels
                        if (mysettings.panelvar == "none" | mysettings.panelvar == "variable")
                        {
                            DxChartBatch batch1 = new DxChartBatch(mysettings, dt, " ");
                            PrepareBatch(batch1, settings);
                            batchlist.Add(batch1);
                        }
                        else
                        {
                            List <string> varnames = new List <string>()
                            {
                                "id"
                            };
                            varnames.AddRange(mysettings.numvars);
                            varnames.Add(mysettings.xaxisvar);
                            varnames.Add(mysettings.colorvar);
                            varnames.RemoveAll(item => item == "variable");
                            varnames.RemoveAll(item => item == "none");


                            DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                                mysettings.panelvar
                            });

                            DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Lineplot, mysettings);
                            batch2.vars = mysettings.numvars;
                            foreach (DataSubset subset in subsets.subsets)
                            {
                                DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                                foreach (DxChart sub in subbatch.charts)
                                {
                                    batch2.charts.Add(sub);
                                }
                            }
                            PrepareBatch(batch2, mysettings);
                            batchlist.Add(batch2);
                        }
                    }
                    #endregion
                }
            }

            order.batches.AddRange(batchlist);

            //The invoice serves as a table of contents for what was actually created
            order.PrepareInvoice();
        }