Hi team,
I am trying to fit a stacked bar inside a table. I am actually retrieving the tableCell’s offsetY attribute summing it up with the Table’s Y attribubte and addign a padding of 3 and placing the bars there. Attaching the downloaded file with overflow. For some reason the offsetY seems to be giving me a wrong value.
This issue is happening only for chinese and other languages not in english.
Could you please help checking this?aspose.Slides Overflow.jpg (105.7 KB)
Below is the simple function to do this for me (Please see the internal function addRectangle where I am trying to create bars inside the table cell),
private static IList<IShape> formatThreeBar(CellFormaterMessage message)
{
var tableCell = message.TableCell;
var dataCell = message.DataCell;
var dataRow = message.DataRow;
var fontSize = message.FontSize;
//Special logic for the "BreakoutsTable" item/category row in order to display the item/category title across the whole row or if the threebar data is not available (NA).
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);
if (y + verticalPadding >= 370)//max table height reached
{
y = 360;
}
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;
//WCC 3576 - % Label on Three Bar wraps oddly
//Commenting the below code and adding a check if the currentrect width is >18 only then print the value else empty text.
//if (val.Value > 21) // some formula to determine min value to print based on whole width
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;
});
//WCC 3576 - % Label on Three Bar wraps oddly
// Removed autofit and disabled the WRAPTEXT so that the value does not wrap up oddly. Also font type is set as per design settings.
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;
}
}
// WCC-2693 - Desc: Table Type I - 3 Bar Column - NA does not display on editable PPTX export Soln: Added a check to see if the value is 0% - then write 0% to the text cell.
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;
}