Bug 54696: Add overlay setting to ChartLegend
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1539169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fc086aba47
commit
3976993fda
@ -23,6 +23,7 @@ import org.apache.poi.util.Beta;
|
|||||||
* High level representation of chart legend.
|
* High level representation of chart legend.
|
||||||
*
|
*
|
||||||
* @author Roman Kashitsyn
|
* @author Roman Kashitsyn
|
||||||
|
* @author Martin Andersson
|
||||||
*/
|
*/
|
||||||
@Beta
|
@Beta
|
||||||
public interface ChartLegend extends ManuallyPositionable {
|
public interface ChartLegend extends ManuallyPositionable {
|
||||||
@ -36,4 +37,19 @@ public interface ChartLegend extends ManuallyPositionable {
|
|||||||
* @param position new legend position
|
* @param position new legend position
|
||||||
*/
|
*/
|
||||||
void setPosition(LegendPosition position);
|
void setPosition(LegendPosition position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return overlay value.
|
||||||
|
*/
|
||||||
|
boolean isOverlay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true the legend is positioned over the chart area otherwise
|
||||||
|
* the legend is displayed next to it.
|
||||||
|
*
|
||||||
|
* Default is no overlay.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
void setOverlay(boolean value);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.STLegendPos;
|
|||||||
/**
|
/**
|
||||||
* Represents a SpreadsheetML chart legend
|
* Represents a SpreadsheetML chart legend
|
||||||
* @author Roman Kashitsyn
|
* @author Roman Kashitsyn
|
||||||
|
* @author Martin Andersson
|
||||||
*/
|
*/
|
||||||
@Beta
|
@Beta
|
||||||
public final class XSSFChartLegend implements ChartLegend {
|
public final class XSSFChartLegend implements ChartLegend {
|
||||||
@ -47,6 +48,18 @@ public final class XSSFChartLegend implements ChartLegend {
|
|||||||
this.legend = (ctChart.isSetLegend()) ?
|
this.legend = (ctChart.isSetLegend()) ?
|
||||||
ctChart.getLegend() :
|
ctChart.getLegend() :
|
||||||
ctChart.addNewLegend();
|
ctChart.addNewLegend();
|
||||||
|
|
||||||
|
setDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set sensible default styling.
|
||||||
|
*/
|
||||||
|
private void setDefaults() {
|
||||||
|
if (!legend.isSetOverlay()) {
|
||||||
|
legend.addNewOverlay();
|
||||||
|
}
|
||||||
|
legend.getOverlay().setVal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +97,14 @@ public final class XSSFChartLegend implements ChartLegend {
|
|||||||
return new XSSFManualLayout(legend.getLayout());
|
return new XSSFManualLayout(legend.getLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOverlay() {
|
||||||
|
return legend.getOverlay().getVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOverlay(boolean value) {
|
||||||
|
legend.getOverlay().setVal(value);
|
||||||
|
}
|
||||||
|
|
||||||
private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
|
private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case BOTTOM: return STLegendPos.B;
|
case BOTTOM: return STLegendPos.B;
|
||||||
|
@ -24,6 +24,12 @@ import org.apache.poi.ss.usermodel.charts.ChartLegend;
|
|||||||
import org.apache.poi.ss.usermodel.charts.LegendPosition;
|
import org.apache.poi.ss.usermodel.charts.LegendPosition;
|
||||||
import org.apache.poi.xssf.usermodel.*;
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests ChartLegend
|
||||||
|
*
|
||||||
|
* @author Martin Andersson
|
||||||
|
* @author Cedric dot Walter at gmail dot com
|
||||||
|
*/
|
||||||
public final class TestXSSFChartLegend extends TestCase {
|
public final class TestXSSFChartLegend extends TestCase {
|
||||||
|
|
||||||
public void testLegendPositionAccessMethods() throws Exception {
|
public void testLegendPositionAccessMethods() throws Exception {
|
||||||
@ -37,4 +43,35 @@ public final class TestXSSFChartLegend extends TestCase {
|
|||||||
legend.setPosition(LegendPosition.TOP_RIGHT);
|
legend.setPosition(LegendPosition.TOP_RIGHT);
|
||||||
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
|
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse() {
|
||||||
|
// Arrange
|
||||||
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Drawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
Chart chart = drawing.createChart(anchor);
|
||||||
|
ChartLegend legend = chart.getOrCreateLegend();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertFalse(legend.isOverlay());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue() {
|
||||||
|
// Arrange
|
||||||
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Drawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
Chart chart = drawing.createChart(anchor);
|
||||||
|
ChartLegend legend = chart.getOrCreateLegend();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
legend.setOverlay(true);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertTrue(legend.isOverlay());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user