Esempio n. 1
0
        public PlotModel(string xQuality, string yQuality)
        {
            _points = new List <Models.PointModel>();
            List <double?> xValues = Elements.GetValuesAsDouble(xQuality), yValues = Elements.GetValuesAsDouble(yQuality);

            List <ValuePair> values = Elements.GetValuesAsDouble(xQuality, yQuality, true);
            ValueCounter     vcx = new ValueCounter(), vcy = new ValueCounter();

            values.ForEach(vp =>
            {
                vcx.CountValue(vp.V1);
                vcy.CountValue(vp.V2);
            });
            foreach (ValuePair vp in values)
            {
                StringBuilder s = new StringBuilder();
                s.AppendLine($"{vp.Element.Name}:");
                s.AppendLine($"{xQuality}: {vp.V1}");
                s.Append($"{yQuality}: {vp.V2}");
                PointModel pm = new PointModel(vcx.RelativeValueOf(vp.V1), vcy.RelativeValueOf(vp.V2), s.ToString(),
                                               ElementModel.ColorForCategory(vp.Element.Qualities.ElementCategory));
                _points.Add(pm);
            }
            if (vcx.HasRange && vcy.HasRange)             // do we have plottable data?
            {
                _points.ForEach(p => p.SetValueExtent(vcx.Minimum, vcx.Range, vcy.Minimum, vcy.Range));
            }
            else
            {
                _points.Clear();
            }
            if (_points.Count == 0)
            {
                return;                                 // TODO: display "No Data" message?
            }
            Func <string, string> withUnits = (string q) =>
            {
                string u = Units.GetName(q);
                if (String.IsNullOrEmpty(u))
                {
                    return(q);
                }
                return($"{q}  ({u})");
            };

            _xAxis = new AxisModel(AxisDimension.X, withUnits(xQuality), vcx.Minimum, vcx.Maximum);
            _yAxis = new AxisModel(AxisDimension.Y, withUnits(yQuality), vcy.Minimum, vcy.Maximum);
        }