private static string CoordinateTransform(AxisDescription axis, string axis_name) { if (axis.Breaks == null && axis.DiscreteBreaks == null && axis.BreakLabels == null && axis.CoordinateTransform == AxisDescription.CoordTransform.None) { return(string.Empty); } var breakData = string.Empty; Func <string[], string[], string> FormatBreaks = (breaks, labels) => labels != null? string.Format("breaks = c({0}), labels = c({1})", string.Join(", ", breaks), string.Join(", ", labels)) : string.Format("breaks = c({0})", string.Join(", ", breaks)); if (axis.Breaks != null) { breakData = FormatBreaks(axis.Breaks.Select(x => x.ToString()).ToArray(), axis.BreakLabels); } else if (axis.DiscreteBreaks != null) { breakData = FormatBreaks(axis.DiscreteBreaks, axis.BreakLabels); } else if (axis.BreakLabels != null) { breakData = string.Format("breaks = c('{0}')", string.Join("', '", axis.BreakLabels)); } var transformData = axis.CoordinateTransform == AxisDescription.CoordTransform.None || axis.CoordinateTransform == AxisDescription.CoordTransform.Discrete ? string.Empty : string.Format("trans=log{0}_trans()", axis.CoordinateTransformBase); var limitData = (axis.Min != 0 || axis.Max != 0) && axis.Max > axis.Min ? string.Format("limits=c({0}, {1})", axis.Min, axis.Max) : string.Empty; return(string.Format( " scale_{0}_{1}({2}) + ", axis_name, axis.CoordinateTransform == AxisDescription.CoordTransform.Discrete ? "discrete" : "continuous", string.Join(", ", new string[] { transformData, breakData, limitData, }.Where(x => !string.IsNullOrEmpty(x))))); }
public static string XCoordinateTransform(AxisDescription axis) { return(CoordinateTransform(axis, "x")); }