/// <summary> /// Gets the rectangle. /// </summary> /// <param name="format">The format.</param> /// <param name="xStart">The x start.</param> /// <param name="yStart">The y start.</param> /// <param name="color">The color.</param> /// <param name="Opacity">The opacity.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns></returns> public static SvgRectangle GetRectangle(this cursorZoneSpatialSettings format, Int32 xStart, Int32 yStart, Color color, float Opacity = 0.5F, Double scaleFactor = 1) { var rct = new SvgRectangle(); var tmp = format.GetResized(scaleFactor); Int32 newX = Convert.ToInt32((Convert.ToDouble(format.width) / 2) - (Convert.ToDouble(format.width) * (scaleFactor / 2))); Int32 newY = Convert.ToInt32((Convert.ToDouble(format.height) / 2) - (Convert.ToDouble(format.height) * (scaleFactor / 2))); rct.Fill = new SvgColourServer(color); rct.Stroke = new SvgColourServer(Color.White); rct.StrokeWidth = 1; rct.FillOpacity = Opacity; rct.FillRule = SvgFillRule.Inherit; // rct.Font = "Gulliver"; // rct.FontSize = 10; rct.Opacity = Opacity; rct.X = (xStart + newX + tmp.innerLeftPosition).Get_upx(); rct.Y = (yStart + newY + tmp.innerTopPosition).Get_upx(); rct.Width = tmp.innerBoxedWidth; rct.Height = tmp.innerBoxedHeight; return(rct); }
/// <summary> /// Gets the resized. /// </summary> /// <param name="format">The format.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns></returns> public static cursorZoneSpatialSettings GetResized(this cursorZoneSpatialSettings format, Double scaleFactor) { Int32 newWidth = Convert.ToInt32(Convert.ToDouble(format.width) * scaleFactor); Int32 newHeight = Convert.ToInt32(Convert.ToDouble(format.height) * scaleFactor); var output = new cursorZoneSpatialSettings(newWidth, newHeight, format.margin.left, format.margin.top, format.padding.left, format.padding.top); return(output); }
/// <summary> /// Gets the SVG text. /// </summary> /// <param name="text">The text.</param> /// <param name="format">The format.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static SvgText GetSvgText(this String text, cursorZoneSpatialSettings format, Int32 x, Int32 y) { Int32 xStart = x * format.width; Int32 yStart = y * format.height; Svg.SvgText label = new SvgText(text); label.X = new SvgUnit(xStart + (format.width / 2) - ((text.Length * format.spatialUnit) / 2)); label.Y = new SvgUnit((yStart + (format.height / 2) + (format.spatialUnitHeight))); label.Fill = new SvgColourServer(Color.Black); //label.Font = new Font("Gulliver"); return(label); }
/// <summary> /// Renders the specified <see cref="HeatMapModel"/>, optionally saves the output SVG /// </summary> /// <param name="model">The model.</param> /// <param name="filePath">The file path.</param> /// <returns></returns> public Svg.SvgDocument Render(HeatMapModel model, String filePath = "") { rangeFinder valueRange = model.DetectMinMax(); var lColor = style.LowColor.GetColorVersionWithAlpha(style.MinOpacity); //.ColorToHex(); var hColor = style.HighColor.GetColorVersionWithAlpha(style.MaxOpacity); //.ColorToHex(); ColorGradient colorGradient = new ColorGradient(lColor, hColor, ColorGradientFunction.AllAToB); cursorZoneSpatialSettings format = style.fieldContainer.GetFormatSetup(); format.spatialUnit = 8; format.spatialUnitHeight = 10; Int32 width = (model.weight * format.width) + format.margin.right; Int32 height = (model.height * format.height) + format.margin.bottom; Svg.SvgDocument output = new Svg.SvgDocument { Width = width, Height = height, Ppi = 100 }; var mainContainer = new SvgGroup(); output.Children.Add(mainContainer); //(new SvgLength(width), new SvgLength(height)); // output.ViewBox = new SvgViewBox(-100, -100, width+100, height+100); var group = new SvgGroup(); mainContainer.Children.Add(group); var layerTwo = new SvgGroup(); mainContainer.Children.Add(layerTwo); prepareLabels(model); var hor = new SvgGroup(); if (style.options.HasFlag(HeatMapRenderOptions.addHorizontalLabels)) { layerTwo.Children.Add(hor); } for (int x = 0; x < model.weight; x++) { Int32 xStart = x * format.width; Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1); //Svg.SvgText label = new SvgText(xLabels[x]) //{ // X = (xStart + (format.width / 2) - format.margin.right).Get_px(), // Y = (-format.height / 2).Get_px(), // Color = new SvgColourServer(Color.Black), // Font = "Gulliver" //}; hor.Children.Add(label); var vert = new SvgGroup(); layerTwo.Children.Add(vert); var vertLabels = new SvgGroup(); var vertValues = new SvgGroup(); var vertScale = new SvgGroup(); if (style.options.HasFlag(HeatMapRenderOptions.addVerticalLabels)) { vert.Children.Add(vertLabels); } if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale)) { vert.Children.Add(vertScale); } if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale)) { vert.Children.Add(vertValues); } for (int y = 0; y < model.height; y++) { Int32 yStart = y * format.height; if (x == 0) { Double ratio = valueRange.GetPositionInRange(y); //model.GetRatioForScale(y, style.minimalOpacity, model.height); //(1+ style.minimalOpacity).GetRatio(y+1); Double scaleFactor2 = ratio; if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields)) { scaleFactor2 = 1; } if (ratio > 1) { ratio = 1; } var lbl2 = format.GetRectangle((-format.width * 2), yStart, colorGradient.GetColor(ratio), Convert.ToSingle(ratio), scaleFactor2); vertScale.Children.Add(lbl2); Svg.SvgText label2 = yLabels[y].GetSvgText(format, -1, y); vertLabels.Children.Add(label2); //Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1); //Svg.SvgText label2 = new SvgText(yLabels[y]) //{ // X = (format.margin.left - format.width).Get_px(), // Y = (yStart+(format.height / 2)).Get_px(), // Color = new SvgColourServer(Color.Black), // Font = "Gulliver" //}; Int32 xp = Convert.ToInt32((-Convert.ToDouble(format.width) * 2.5) + format.margin.left); //Double vl = (1.GetRatio(y + 1)) * model.ranger.Maximum; Double vl = model.GetValueForScaleY(y); Svg.SvgText value = vl.ToString(style.valueFormat).GetSvgText(format, -3, y); //Svg.SvgText value = new SvgText() //{ // X = (xp- format.margin.right).Get_px(), // Y = (yStart + (format.height / 2) ).Get_px(), // Fill = new SvgColourServer(Color.Black), // // Color = new SvgColourServer(Color.White), // Font = "Gulliver" //}; vertValues.Children.Add(value); } Double val = valueRange.GetPositionInRange(model[x, y]); // model.GetRatioValue(x, y, style.minimalOpacity); Color valC = colorGradient.GetColor(val); Double scaleFactor = val; if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields)) { scaleFactor = 1; } var rct = format.GetRectangle(xStart, yStart, valC, Convert.ToSingle(val), scaleFactor); group.Children.Add(rct); } } if (!filePath.isNullOrEmpty()) { if (!filePath.EndsWith(".svg", true, CultureInfo.CurrentCulture)) { filePath += ".svg"; } output.Save(filePath); // throw new NotImplementedException(); /* var code = output.GetXML(); //Encoding.UTF8.GetString(stream.GetBuffer()); * */ } return(output); }
/// <summary> /// Returns the zone spatial settings -- btw. top/bottom and left/right margin and padding are equalized: top=>bottom, left=>right /// </summary> /// <returns></returns> public cursorZoneSpatialSettings GetFormatSetup() { cursorZoneSpatialSettings output = new cursorZoneSpatialSettings(minSize.width, minSize.height, sizeAndBorder.left.margin, sizeAndBorder.top.margin, sizeAndBorder.left.padding, sizeAndBorder.top.padding); return(output); }