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.

XSSFDateAxis.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.xssf.usermodel.charts;
  16. import org.apache.poi.ss.usermodel.charts.AxisCrosses;
  17. import org.apache.poi.ss.usermodel.charts.AxisOrientation;
  18. import org.apache.poi.ss.usermodel.charts.AxisPosition;
  19. import org.apache.poi.ss.usermodel.charts.AxisTickMark;
  20. import org.apache.poi.ss.usermodel.charts.ChartAxis;
  21. import org.apache.poi.util.Internal;
  22. import org.apache.poi.util.Removal;
  23. import org.apache.poi.xddf.usermodel.chart.XDDFDateAxis;
  24. import org.apache.poi.xssf.usermodel.XSSFChart;
  25. import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
  26. import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
  27. import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartLines;
  28. import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
  29. import org.openxmlformats.schemas.drawingml.x2006.chart.CTDateAx;
  30. import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
  31. import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
  32. import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
  33. import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
  34. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  35. /**
  36. * Date axis type. Currently only implements the same values as {@link XSSFCategoryAxis}, since the two are nearly identical.
  37. *
  38. * @deprecated use {@link XDDFDateAxis} instead
  39. */
  40. @Deprecated
  41. @Removal(version="4.2")
  42. public class XSSFDateAxis extends XSSFChartAxis {
  43. private CTDateAx ctDateAx;
  44. public XSSFDateAxis(XSSFChart chart, long id, AxisPosition pos) {
  45. super(chart);
  46. createAxis(id, pos);
  47. }
  48. public XSSFDateAxis(XSSFChart chart, CTDateAx ctDateAx) {
  49. super(chart);
  50. this.ctDateAx = ctDateAx;
  51. }
  52. @Override
  53. public long getId() {
  54. return ctDateAx.getAxId().getVal();
  55. }
  56. @Override
  57. @Internal
  58. public CTShapeProperties getLine() {
  59. return ctDateAx.getSpPr();
  60. }
  61. @Override
  62. protected CTAxPos getCTAxPos() {
  63. return ctDateAx.getAxPos();
  64. }
  65. @Override
  66. protected CTNumFmt getCTNumFmt() {
  67. if (ctDateAx.isSetNumFmt()) {
  68. return ctDateAx.getNumFmt();
  69. }
  70. return ctDateAx.addNewNumFmt();
  71. }
  72. @Override
  73. protected CTScaling getCTScaling() {
  74. return ctDateAx.getScaling();
  75. }
  76. @Override
  77. protected CTCrosses getCTCrosses() {
  78. return ctDateAx.getCrosses();
  79. }
  80. @Override
  81. protected CTBoolean getDelete() {
  82. return ctDateAx.getDelete();
  83. }
  84. @Override
  85. protected CTTickMark getMajorCTTickMark() {
  86. return ctDateAx.getMajorTickMark();
  87. }
  88. @Override
  89. protected CTTickMark getMinorCTTickMark() {
  90. return ctDateAx.getMinorTickMark();
  91. }
  92. @Override
  93. @Internal
  94. public CTChartLines getMajorGridLines() {
  95. return ctDateAx.getMajorGridlines();
  96. }
  97. @Override
  98. public void crossAxis(ChartAxis axis) {
  99. ctDateAx.getCrossAx().setVal(axis.getId());
  100. }
  101. private void createAxis(long id, AxisPosition pos) {
  102. ctDateAx = chart.getCTChart().getPlotArea().addNewDateAx();
  103. ctDateAx.addNewAxId().setVal(id);
  104. ctDateAx.addNewAxPos();
  105. ctDateAx.addNewScaling();
  106. ctDateAx.addNewCrosses();
  107. ctDateAx.addNewCrossAx();
  108. ctDateAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
  109. ctDateAx.addNewDelete();
  110. ctDateAx.addNewMajorTickMark();
  111. ctDateAx.addNewMinorTickMark();
  112. setPosition(pos);
  113. setOrientation(AxisOrientation.MIN_MAX);
  114. setCrosses(AxisCrosses.AUTO_ZERO);
  115. setVisible(true);
  116. setMajorTickMark(AxisTickMark.CROSS);
  117. setMinorTickMark(AxisTickMark.NONE);
  118. }
  119. @Override
  120. public boolean hasNumberFormat() {
  121. return ctDateAx.isSetNumFmt();
  122. }
  123. }