public void LoadFromFile() { try { if (!File.Exists("picConfig")) { return; } var rcls = new List <RockColor>(); var it = new List <double>(); using (var file = new StreamReader("picConfig")) { string line = file.ReadLine(); while (line != "~") { if (line == null) { return; } var sublines = line.Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (sublines.Count() < 5) { continue; } var rc = new RockColor() { Index = Convert.ToInt32(sublines[0]), Color = OxyColor.FromArgb(Convert.ToByte(sublines[1]), Convert.ToByte(sublines[2]), Convert.ToByte(sublines[3]), Convert.ToByte(sublines[4])) }; rcls.Add(rc); line = file.ReadLine(); } line = file.ReadLine(); while (line != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } it.Add(Convert.ToDouble(line)); line = file.ReadLine(); } } RocksColor = rcls; Isoterms = it; } catch (Exception ex) { return; } }
/// <summary> /// Adjusts the hue by the specificed percentage (10%) or degrees (10deg). /// </summary> /// <param name="input">The input.</param> /// <param name="amount">The amount.</param> /// <returns></returns> public static string AdjustHue(string input, string amount) { amount = amount.Trim(); // Adjust by percent if (amount.EndsWith("%")) { var color = new RockColor(input); color.AdjustHueByPercent(CleanColorAmount(amount)); return(GetColorString(color, input)); } // Adjust by degrees if (amount.EndsWith("deg")) { var color = new RockColor(input); color.AdjustHueByDegrees(CleanColorAmount(amount, "deg")); return(GetColorString(color, input)); } // They didn't provide a valid amount so give back the original color return(input); }
/// <summary> /// Decreases the opacity level by the given percentage. This makes the color less transparent (opaque). /// </summary> /// <param name="input">The input.</param> /// <param name="amount">The amount.</param> /// <returns></returns> public static string FadeIn(string input, string amount) { var color = new RockColor(input); color.FadeIn(CleanColorAmount(amount)); return(GetColorString(color, input)); }
/// <summary> /// Desaturates the color by the provided percentage amount. /// </summary> /// <param name="input">The input.</param> /// <param name="amount">The amount.</param> /// <returns></returns> public static string Desaturate(string input, string amount) { var color = new RockColor(input); color.Desaturate(CleanColorAmount(amount)); return(GetColorString(color, input)); }
/// <summary> /// Returns the color in greyscale. /// </summary> /// <param name="input">The input.</param> /// <returns></returns> public static string Grayscale(string input) { var color = new RockColor(input); color.Grayscale(); return(GetColorString(color, input)); }
/// <summary> /// Mixes the specified color with the input color with the given amount. /// </summary> /// <param name="input">The input.</param> /// <param name="mixColorInput">The mix color input.</param> /// <param name="amount">The amount.</param> /// <returns></returns> public static string Mix(string input, string mixColorInput, string amount) { var color = new RockColor(input); var mixColor = new RockColor(mixColorInput); color.Mix(mixColor, CleanColorAmount(amount)); return(GetColorString(color, input)); }
/// <summary> /// Saturates the color by the provided percentage amount. /// </summary> /// <param name="input">The input.</param> /// <param name="amount">The amount.</param> /// <returns></returns> public static string Saturate(string input, string amount) { var color = new RockColor(input); color.Saturate(CleanColorAmount(amount)); // return the color in a format that matched the input if (input.StartsWith("#")) { return(color.ToHex()); } return(color.ToRGBA()); }
/// <summary> /// Determines the proper return value of the color. /// </summary> /// <param name="color">The color.</param> /// <param name="input">The input.</param> /// <returns></returns> private static string GetColorString(RockColor color, string input) { if (color.Alpha != 1) { return(color.ToRGBA()); } if (input.StartsWith("#")) { return(color.ToHex()); } return(color.ToRGBA()); }
/// <summary> /// Mixes the color of the theme. /// </summary> /// <param name="color">The color.</param> /// <param name="level">The level.</param> /// <returns></returns> private static string MixThemeColor(string color, decimal level) { var mixcolor = "#ffffff"; if (level > 0) { mixcolor = "#000000"; } var originalColor = RockColor.FromHex(color); var mixColor = RockColor.FromHex(mixcolor); var mixPercent = ( int )((Math.Abs(level) * .08m) * 100); originalColor.Mix(mixColor, mixPercent); return(originalColor.ToHex()); }
/// <summary> /// Get a JSON data structure that represents Chart.js options to show discrete time categories on the X-axis. /// </summary> /// <returns></returns> /// <remarks> /// Using discrete categories for the time scale allows the data series to be padded with zero-values where no data is found. /// This often shows a more accurate representation of the data rather than allowing Chart.js to interpolate the empty intervals. /// </remarks> private dynamic GetChartJsonObjectForSpecificTimeScale() { // Group the datapoints according to the TimeScale setting. var datasets = GetCategoryDatasets(this.TimeScale); var categories = GetTimescaleCategories(this.TimeScale); var categoryNames = categories.Select(x => x.Category).ToList(); var availableColors = GetDatasetColors(); var jsDatasets = new List <object>(); foreach (var dataset in datasets) { // Use the line color specifically assigned to this dataset, or get the next color from the queue. string borderColor = dataset.BorderColor; if (string.IsNullOrWhiteSpace(borderColor)) { borderColor = GetNextQueueItem(availableColors); } // Create a sequence of datapoints, ensuring there is a value for each of the categories. var dataValues = GetDataPointsForAllCategories(dataset, categoryNames); // Calculate the fill color for the area bounded by this dataset. string fillColorText = dataset.FillColor; string fillOption; if (string.IsNullOrWhiteSpace(dataset.FillColor)) { // Fill color not specified, so disable fill but assign a backcolor so a filled square is shown on the legend. fillOption = "false"; fillColorText = borderColor; } else { fillOption = "origin"; fillColorText = borderColor; } // Get an opacity value between 0 and 1. var alpha = this.AreaFillOpacity; if (alpha < 0) { alpha = 0; } else if (alpha > 1) { alpha = 1; } if (alpha >= 0.1) { fillOption = "origin"; } else { // Opacity is set to near 0, so disable fill. // A backcolor must be specified to show a filled square in the legend. fillOption = "false"; } var backColor = new RockColor(fillColorText); // Add the alpha component to set the transparency level. if (alpha >= 0.1) { backColor = new RockColor(backColor.R, backColor.G, backColor.B, alpha); } var jsDataset = new { label = dataset.Name, borderColor, backgroundColor = backColor.ToRGBA(), fill = fillOption, lineTension = 0, data = dataValues }; jsDatasets.Add(jsDataset); } var chartData = new { datasets = jsDatasets, labels = categoryNames }; return(chartData); }