Hi team,
We have created a table object and tried to fit in some bar objects (stacked - favorable, neutral and unfavorable) for a report.
It was working properly before upgrade to 18.2 but unfortunately it seems to be displaced after the upgrade.
Below is the code snippet that we have used to achieve this. Please check the addRectangle inline method.
private static IList formatThreeBar(CellFormaterMessage message)
{
var tableCell = message.TableCell;
var dataCell = message.DataCell;
var dataRow = message.DataRow;
var fontSize = message.FontSize;
if (((dataCell.Favorable == null && dataCell.Neutral == null && dataCell.Unfavorable == null) || (Double.IsNaN(dataCell.Favorable.Value) && Double.IsNaN(dataCell.Neutral.Value) && Double.IsNaN(dataCell.Unfavorable.Value))))
{
if (dataCell.RawData == Setup.NanValueStr || dataCell.RawData == "")
{
dataCell.Title = message.NAText;
}
return formatScoreData(message);
}
tableCell.TextFrame.Text = "";
bool isAlt = message.TableCell.FirstRowIndex % 2 == 0 && !message.IsBreakoutTable;
if (dataRow.ItemType == QVDatasourceTransformer.Page.DataView.ItemTypeEnum.Category && !message.IsCategoriesOnlyTable)
SetCellBackgroundColor(message.TableCell, message.DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-Tables-Category-Background-Color").GetColor());
else
{
SetCellBackgroundColor(message.TableCell,
message.DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-Tables-" + (isAlt ? "Alt" : "") + "Row-Background-Color").GetColor());
}
var shapes = tableCell.Slide.Shapes;
var width = (float)tableCell.Width - (2 * horizontalPadding);
var x = (float)(tableCell.OffsetX + tableCell.Table.X);
var y = (float)(tableCell.OffsetY + tableCell.Table.Y - message.BarOffsetY);
var currentRectangleIndex = 0;
Dictionary<int, string> barItems;
if (message.LanguageIsRightToLeft)
{
barItems = new Dictionary<int, string>() { { 0, "UnFav" }, { 1, "Neu" }, { 2, "Fav" } };
}
else
{
barItems = new Dictionary<int, string>() { { 0, "Fav" }, { 1, "Neu" }, { 2, "UnFav" } };
}
Func<double, float> calculateWidth = val => (width / 100) * (float)val;
IAutoShape lastRectangle = null;
IGroupShape group = shapes.AddGroupShape(); //WCC-2693 - To group the rectangles.
group.Name = "ThreeBarGroup" + shapeID;
Func<double?, IShape> addRectangle = val =>
{
var rectX = lastRectangle != null ? lastRectangle.X + lastRectangle.Width : x + horizontalPadding;
var currentRect =
group.Shapes.AddAutoShape(ShapeType.Rectangle, rectX, **_y + verticalPadding_**, calculateWidth(val.Value), height);//WCC-2693 - Rectagle is created as a part of the grouped shape
if (lastRectangle == null)
{
var rec = currentRect.Y;
}
currentRect.Name = "ThreeBar" + shapeID.ToString();
shapeID++;
currentRect.FillFormat.FillType = FillType.Solid;
Color backgroundColor = message.DesignSettings.GetValueOrDefault(String.Format("@UISetting-OnScreenReport-{0}-Shading-Color".ToString(), barItems[currentRectangleIndex])).GetColor();
Color foreColor = message.DesignSettings.GetValueOrDefault(String.Format("@UISetting-OnScreenReport-{0}-Font-Color", barItems[currentRectangleIndex]).ToString()).GetColor();
currentRect.FillFormat.SolidFillColor.Color = backgroundColor;
currentRect.LineFormat.FillFormat.FillType = FillType.NoFill;
currentRect.LineFormat.Width = 0;
if(currentRect.Width>18)
{
var valueTextFrame = currentRect.AddTextFrame(string.Format("{0:F0}%", val.Value));
valueTextFrame.TextFrameFormat.CenterText = NullableBool.True;
valueTextFrame.OnEachPortion(portion =>
{
var portionFormat = portion.PortionFormat;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = foreColor;
portionFormat.FontHeight = fontSize;
});
valueTextFrame.OnEachParagraph(para =>
{
para.ParagraphFormat.DefaultPortionFormat.LatinFont =
new FontData(
message.DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-Tables-Row-Font-Type").Split(',')[0]);
});
valueTextFrame.TextFrameFormat.WrapText = NullableBool.False;
}
lastRectangle = currentRect;
currentRectangleIndex++;
return currentRect;
};
if ((dataCell.Favorable == null && dataCell.Neutral == null && dataCell.Unfavorable == null) || (dataCell.Favorable.Value == Setup.NaNValue && dataCell.Neutral.Value == Setup.NaNValue && dataCell.Unfavorable.Value == Setup.NaNValue))
{
if (dataCell.Attributes.Count > 0 &&
dataCell.Attributes.Exists(a => a.Name == "ScorelessItem") &&
Boolean.Parse(dataCell.Attributes.First(b => b.Name == "ScorelessItem").Value))
{
return null;
}
else
{
tableCell.TextFrame.Text = message.NAText;
return null;
}
}
else if ((dataCell.Favorable.Value == 0.0 && dataCell.Unfavorable.Value == 0.0 && dataCell.Neutral.Value == 0.0) || (dataCell.Favorable.Value == Setup.ZeroValue && dataCell.Unfavorable.Value == Setup.ZeroValue && dataCell.Neutral.Value == Setup.ZeroValue))
{
tableCell.TextFrame.Text = "0%";
return null;
}
List<IShape> rectangle;
if (message.LanguageIsRightToLeft)
{
rectangle = new List<IShape>()
{
group,
addRectangle(dataCell.Unfavorable),
addRectangle(dataCell.Neutral),
addRectangle(dataCell.Favorable)
};
}
else
{
rectangle = new List<IShape>()
{
group,
addRectangle(dataCell.Favorable),
addRectangle(dataCell.Neutral),
addRectangle(dataCell.Unfavorable)
};
}
return rectangle;
}
OverlappingSlide.zip (54.9 KB)