Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/EPPlus/Drawing/Chart/ExcelChartAxisStandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ internal override ExcelChartTitle GetTitle()
if (_title == null)
{
AddTitleNode();
_title = new ExcelChartTitleStandard(_chart, NameSpaceManager, TopNode, "c", "title", IsVertical ? 270 : 0);

_title = new ExcelChartTitleStandard(_chart, NameSpaceManager, TopNode, "c", "title", 0); //Stop putting 'IsVertical ? 270 : 0' here. Excel does not do that. It's based on textDirection not being vertical
}
return _title;
}
Expand Down
47 changes: 32 additions & 15 deletions src/EPPlus/Drawing/Renderer/Chart/ChartAxisRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ private double GetTextHeight(ExcelChartAxisStandard ax, bool isMulti)
if (string.IsNullOrEmpty(s))
continue;

highest = GetHightestAxisValue(shaper, fontSize, lineHeight, highest, s, LabelOrientation);
highest = GetHighestAxisValue(shaper, fontSize, lineHeight, highest, s, LabelOrientation);
}
}
return highest.PointToPixel();
}

private double GetHightestAxisValue(ITextShaper shaper, float fontSize, float lineHeight, double highest, string s, eTextOrientation labelOrientation)
private double GetHighestAxisValue(ITextShaper shaper, float fontSize, float lineHeight, double highest, string s, eTextOrientation labelOrientation)
{
switch (labelOrientation)
{
Expand Down Expand Up @@ -824,16 +824,23 @@ private List<DrawingTextContainer> GetAxisValueTextBoxes(out double widest, out
var lblAlignment = (Axis as ExcelChartAxisStandard)?.LabelAlignment ?? OfficeOpenXml.eAxisLabelAlignment.Center;
var majorWidth = Rectangle.Width / count;

switch (lblAlignment)
if (Chart.IsTypeBar() == false)
{
case OfficeOpenXml.eAxisLabelAlignment.Left:
break;
case OfficeOpenXml.eAxisLabelAlignment.Center:
tb.Left += majorWidth / 2 - tb.Width / 2;
break;
case OfficeOpenXml.eAxisLabelAlignment.Right:
tb.Left += majorWidth - tb.Width;
break;
switch (lblAlignment)
{
case OfficeOpenXml.eAxisLabelAlignment.Left:
break;
case OfficeOpenXml.eAxisLabelAlignment.Center:
tb.Left += majorWidth / 2 - tb.Width / 2;
break;
case OfficeOpenXml.eAxisLabelAlignment.Right:
tb.Left += majorWidth - tb.Width;
break;
}
}
else
{

}
}
}
Expand Down Expand Up @@ -864,14 +871,15 @@ private List<DrawingTextContainer> AddTextboxes(ITextShaper shaper, float fontSi
if (i + 1 < Values.Count)
{
var nextTicMarkX = GetAxisItemLeft(i + 1);
majorTickMarkWidth = nextTicMarkX - ticMarkX;
//Abs neccesary for reversed axis
majorTickMarkWidth = Math.Abs(nextTicMarkX - ticMarkX);
}
else
{
if (i > 0)
{
var prevTickMarkX = GetAxisItemLeft(i - 1);
majorTickMarkWidth = ticMarkX - prevTickMarkX;
majorTickMarkWidth = Math.Abs(ticMarkX - prevTickMarkX);
}
else
{
Expand Down Expand Up @@ -997,8 +1005,8 @@ private List<DrawingTextContainer> AddTextboxes(ITextShaper shaper, float fontSi
x = x - width * cos;

// Wrapping may be undesireable in this case?
//See Epplus_Svg_Bar Axes|chart 22 when this is not doen it's wrapped even with the margins
availableTextLength = width;
//See Epplus_Svg_Bar Axes|chart 22 when this is not done it's wrapped even with the margins
availableTextLength = width + RightMargin;
}
else
{
Expand Down Expand Up @@ -1029,6 +1037,15 @@ private List<DrawingTextContainer> AddTextboxes(ITextShaper shaper, float fontSi
var diff = Math.Abs(distX - halfWidth);

x = xPosStart;

if (width > majorTickMarkWidth)
{
//x = x - width * cos;

// Wrapping may be undesireable in this case?
//See Epplus_Svg_Bar Axes|chart 22 when this is not done it's wrapped even with the margins
availableTextLength = width + RightMargin;
}
//if (width > majorTickMarkWidth)
//{
// x = x + width * cos;
Expand Down
13 changes: 12 additions & 1 deletion src/EPPlus/Drawing/Renderer/Chart/ChartTitleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,18 @@ internal double GetBottomOverlay(double overlayValue=0)
}
else
{
return Rectangle.GlobalBottom;
var lastLine = TextBox?.TextBody?.Paragraphs?.Last().Lines?.Last();
if(lastLine != null)
{

//Excel spaces the bottom one line lower than the rect
var lineSpace = lastLine.LargestDescent*2d;
return Rectangle.GlobalBottom + lineSpace;
}
else
{
return Rectangle.GlobalBottom;
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/EPPlus/Drawing/Renderer/ChartRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public ChartRenderer(ExcelChart chart, SvgRenderOptions options) : base(chart, o
//As we need the plotarea dimensions to calculate the axis positions we need to set the axis positions after creating the plotarea.
SetAxisPositionsFromPlotarea();

//Plotarea.SetPlotAreaRectangle();

Plotarea.DrawSeries();

//Append all renderitems after everything has been created and positioned, to ensure the correct z-ordering.
Expand Down Expand Up @@ -156,15 +158,15 @@ private void SetAxisPositionsFromPlotarea()
SecondHorizontalAxis.AddTickmarksAndValues(DefItems);
}

PlaceHorizontalAxisTitle(HorizontalAxis);
PlaceHorizontalAxisTitle(SecondHorizontalAxis);
PlaceVerticalAxisTitle(VerticalAxis);
PlaceVerticalAxisTitle(SecondVerticalAxis);

HorizontalAxis?.CalculateWidthHeightFromContent();
VerticalAxis?.CalculateWidthHeightFromContent();
SecondVerticalAxis?.CalculateWidthHeightFromContent();
SecondHorizontalAxis?.CalculateWidthHeightFromContent();

PlaceHorizontalAxisTitle(HorizontalAxis);
PlaceHorizontalAxisTitle(SecondHorizontalAxis);
PlaceVerticalAxisTitle(VerticalAxis);
PlaceVerticalAxisTitle(SecondVerticalAxis);
}
private void PlaceDisplayUnitTitle(ChartAxisRenderer axis)
{
Expand Down Expand Up @@ -484,7 +486,7 @@ private void PlaceVerticalAxisTitle(ChartAxisRenderer verticalAxis)
{
var sinRot = Math.Abs(Math.Sin(MathHelper.Radians(verticalAxis.Title.TextBox.Rotation)));
var cosRot = Math.Abs(Math.Cos(MathHelper.Radians(verticalAxis.Title.TextBox.Rotation)));
verticalAxis.Title.TextBox.Top = Plotarea.Group.Top + (Plotarea.Rectangle.Height / 2) + ((verticalAxis.Title.TextBox.Height * cosRot + verticalAxis.Title.TextBox.Width * sinRot) / 2);
verticalAxis.Title.TextBox.Top = Plotarea.Group.Top + (Plotarea.Rectangle.Height / 2) - ((verticalAxis.Title.TextBox.Height * cosRot + verticalAxis.Title.TextBox.Width * sinRot) / 2);

if (verticalAxis.Axis.AxisPosition == eAxisPosition.Left)
{
Expand Down
Loading