public DoubleList(object values) : this() { object v = values; if (values is PSObject psobj) { v = psobj.BaseObject; } if (v is ICollection <double> dc) { foreach (var e in dc) { Values.Add(e); } } else if (v is ICollection <object> oc) { foreach (var e in oc) { Values.Add(SmartConverter.ToDouble(e)); } } else { throw new ArgumentException("Can't convert into a sequence of type double"); } }
public static double ConvertFrom(string value) { try { return(SmartConverter.ToDouble(value)); } catch (Exception) { try { return(OxyPlot.Axes.DateTimeAxis.ToDouble(SmartConverter.ToDateTime(value))); } catch (Exception) { try { return(OxyPlot.Axes.TimeSpanAxis.ToDouble(TimeSpan.Parse(value))); } catch (Exception) { try { var m = UnitPattern.Match(value); if (m.Success) { value = m.Groups[1].Value; var unit = m.Groups[2].Value.ToLower(); var unitMultiply = 1.0; if (unit == "px") { unitMultiply = 1.0; } else if (unit == "in") { unitMultiply = DpiX; } else if (unit == "cm") { unitMultiply = DpiX / 2.54; } else if (unit == "pt") { unitMultiply = DpiX / 72.0; } return(SmartConverter.ToDouble(value) * unitMultiply); } throw new ArgumentException($"Can't convert to double, DateTime nor TimeSpan: {value}"); } catch (Exception) { throw new ArgumentException($"Can't convert to double, DateTime nor TimeSpan: {value}"); } } } } }
public Type InferValueType() { var t = _value.GetType(); if (t == typeof(double) || t == typeof(float) || t == typeof(long) || t == typeof(int) || t == typeof(short) || t == typeof(byte) || t == typeof(sbyte)) { return(typeof(double)); } if (t == typeof(DateTime) || t == typeof(DateTimeOffset)) { return(typeof(DateTime)); } if (t == typeof(TimeSpan)) { return(typeof(TimeSpan)); } try { var dummy = SmartConverter.ToDouble(_value); return(typeof(double)); } catch (Exception) { try { var dummy = DateTime.Parse(_value.ToString()); return(typeof(DateTime)); } catch (Exception) { try { var dummy = TimeSpan.Parse(_value.ToString()); return(typeof(TimeSpan)); } catch (Exception) { return(_value.GetType()); } } } }
public static OxyPlot.PlotLength ConvertFrom(string value) { var unitMultiply = 1.0; var plotLengthUnit = OxyPlot.PlotLengthUnit.Data; var m = UnitPattern.Match(value); if (m.Success) { value = m.Groups[1].Value; var unit = m.Groups[2].Value.ToLower(); switch (unit) { case "px": unitMultiply = 1.0; break; case "in": unitMultiply = DpiX; break; case "cm": unitMultiply = DpiX / 2.54; break; case "pt": unitMultiply = DpiX / 72.0; break; case "viewport": plotLengthUnit = OxyPlot.PlotLengthUnit.RelativeToViewport; break; case "plotarea": plotLengthUnit = OxyPlot.PlotLengthUnit.RelativeToPlotArea; break; default: throw new ArgumentException($"Unknown unit: {m.Groups[2].Value}"); } } return(new OxyPlot.PlotLength(SmartConverter.ToDouble(value) * unitMultiply, plotLengthUnit)); }
public static double[,] ConvertFrom(object[] values) { var first = values[0]; if (first is PSObject pso) { first = pso.BaseObject; } if (!(first is Array firstRow)) { throw new ArgumentException("Failed to convert to a two-dimensional array"); } var columnLength = firstRow.Length; var result = new double[columnLength, values.Length]; for (var i = 0; i < values.Length; ++i) { var v = values[i]; if (v is PSObject p) { v = p.BaseObject; } if (!(v is Array row)) { throw new ArgumentException("Failed to convert to a two-dimensional array"); } var j = 0; foreach (var e in row) { result[j, i] = SmartConverter.ToDouble(e); ++j; } } return(result); }
private Type InferAxisTypeBasedOnValueType(int axisIndex, object value) { // Use a default type except a linear axis. if (DefaultAxisTypes[axisIndex] != typeof(LinearAxis)) { return(DefaultAxisTypes[axisIndex]); } if (value == null) { return(null); } Type t; if (value is TypeAdaptors.Double d) { t = d.InferValueType(); } else { t = value.GetType(); } if (t == typeof(double) || t == typeof(float) || t == typeof(long) || t == typeof(int) || t == typeof(short) || t == typeof(byte) || t == typeof(sbyte)) { return(typeof(LinearAxis)); } if (t == typeof(DateTime) || t == typeof(DateTimeOffset)) { return(typeof(DateTimeAxis)); } if (t == typeof(TimeSpan)) { return(typeof(TimeSpanAxis)); } try { var dummy = SmartConverter.ToDouble(value); return(typeof(LinearAxis)); } catch (Exception) { try { var dummy = DateTime.Parse(value.ToString()); return(typeof(DateTimeAxis)); } catch (Exception) { try { var dummy = TimeSpan.Parse(value.ToString()); return(typeof(TimeSpanAxis)); } catch (Exception) { return(typeof(LinearAxis)); } } } }