You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XDDFValueAxis.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xddf.usermodel.chart;
  16. import org.apache.poi.util.Beta;
  17. import org.apache.poi.util.Internal;
  18. import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
  19. import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
  20. import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
  21. import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
  22. import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
  23. import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
  24. import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
  25. import org.openxmlformats.schemas.drawingml.x2006.chart.CTUnsignedInt;
  26. import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
  27. import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  29. @Beta
  30. public class XDDFValueAxis extends XDDFChartAxis {
  31. private CTValAx ctValAx;
  32. public XDDFValueAxis(CTPlotArea plotArea, AxisPosition position) {
  33. initializeAxis(plotArea, position);
  34. }
  35. public XDDFValueAxis(CTValAx ctValAx) {
  36. this.ctValAx = ctValAx;
  37. }
  38. @Override
  39. @Internal
  40. public CTShapeProperties getMajorGridLines() {
  41. if (!ctValAx.isSetMajorGridlines()) {
  42. ctValAx.addNewMajorGridlines();
  43. }
  44. if (!ctValAx.getMajorGridlines().isSetSpPr()) {
  45. ctValAx.getMajorGridlines().addNewSpPr();
  46. }
  47. return ctValAx.getMajorGridlines().getSpPr();
  48. }
  49. @Override
  50. @Internal
  51. public CTShapeProperties getLine() {
  52. return ctValAx.getSpPr();
  53. }
  54. @Override
  55. public void crossAxis(XDDFChartAxis axis) {
  56. ctValAx.getCrossAx().setVal(axis.getId());
  57. }
  58. @Override
  59. protected CTUnsignedInt getCTAxId() {
  60. return ctValAx.getAxId();
  61. }
  62. @Override
  63. protected CTAxPos getCTAxPos() {
  64. return ctValAx.getAxPos();
  65. }
  66. @Override
  67. public boolean hasNumberFormat() {
  68. return ctValAx.isSetNumFmt();
  69. }
  70. @Override
  71. protected CTNumFmt getCTNumFmt() {
  72. if (ctValAx.isSetNumFmt()) {
  73. return ctValAx.getNumFmt();
  74. }
  75. return ctValAx.addNewNumFmt();
  76. }
  77. @Override
  78. protected CTScaling getCTScaling() {
  79. return ctValAx.getScaling();
  80. }
  81. @Override
  82. protected CTCrosses getCTCrosses() {
  83. CTCrosses crosses = ctValAx.getCrosses();
  84. if (crosses == null) {
  85. return ctValAx.addNewCrosses();
  86. } else {
  87. return crosses;
  88. }
  89. }
  90. @Override
  91. protected CTBoolean getDelete() {
  92. return ctValAx.getDelete();
  93. }
  94. @Override
  95. protected CTTickMark getMajorCTTickMark() {
  96. return ctValAx.getMajorTickMark();
  97. }
  98. @Override
  99. protected CTTickMark getMinorCTTickMark() {
  100. return ctValAx.getMinorTickMark();
  101. }
  102. public AxisCrossBetween getCrossBetween() {
  103. return AxisCrossBetween.valueOf(ctValAx.getCrossBetween().getVal());
  104. }
  105. public void setCrossBetween(AxisCrossBetween crossBetween) {
  106. ctValAx.getCrossBetween().setVal(crossBetween.underlying);
  107. }
  108. private void initializeAxis(CTPlotArea plotArea, AxisPosition position) {
  109. final long id = getNextAxId(plotArea);
  110. ctValAx = plotArea.addNewValAx();
  111. ctValAx.addNewAxId().setVal(id);
  112. ctValAx.addNewAxPos();
  113. ctValAx.addNewScaling();
  114. ctValAx.addNewCrossBetween();
  115. ctValAx.addNewCrosses();
  116. ctValAx.addNewCrossAx();
  117. ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
  118. ctValAx.addNewDelete();
  119. ctValAx.addNewMajorTickMark();
  120. ctValAx.addNewMinorTickMark();
  121. setPosition(position);
  122. setOrientation(AxisOrientation.MIN_MAX);
  123. setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
  124. setCrosses(AxisCrosses.AUTO_ZERO);
  125. setVisible(true);
  126. setMajorTickMark(AxisTickMark.CROSS);
  127. setMinorTickMark(AxisTickMark.NONE);
  128. }
  129. }