private int getXValue(int xPos, int xSize) { if (xPos < xAxis.getLowVal()) return 0; if (xPos > xAxis.getHighVal()) return xSize; int numPixelsToReserve = getLeftBorder(); float xVal = numPixelsToReserve + (xSize - numPixelsToReserve) * (xPos - xAxis.getLowVal()) / (xAxis.getHighVal() - xAxis.getLowVal()); return (int) xVal; }
private int getLeftBorder() { int numPixelsToReserve = selectedYAxis.getNumPixelsReserved(); if (!selectedYAxis.isDisplayed) numPixelsToReserve = 0; return numPixelsToReserve; }
public void drawGenbankAnnotations(Graphics g) { this.colorIndex = 0; int yOffset = 3; g.setFont(new Font("SansSerif", Font.BOLD, 12)); if (genbankAnnotationList == null || !showGeneAnnotations) return; int leftBorder = selectedYAxis.isDisplayed() ? selectedYAxis.getNumPixelsReserved() : 0; int xSize = getWidth(); Color oldColor = g.getColor(); int offSetSize = numPixelsReservedForGeneAnnotations / 5; for (GenbankAnnotations ga : genbankAnnotationList) { this.colorIndex++; yOffset += offSetSize; if (yOffset > numPixelsReservedForGeneAnnotations) yOffset = 3; if (colorIndex >= colors.length) colorIndex = 0; g.setColor(colors[colorIndex]); int x1 = getXValue(ga.getBeginPos(), xSize); int x2 = getXValue(ga.getEndPos(), xSize); // dummy values of 1 and 100 as the y axis is always ok for annotations if (lineIsInFrame(x1, x2, 1, xSize, 100)) { int yValue = getHeight() - yOffset; drawSomeLines(g, x1, x2, yValue, leftBorder, xSize); ga.setXPixelStart(x1); ga.setXPixelEnd(x2); if (showGeneLabels) { g.setColor(Color.BLACK); g.drawString(ga.getProduct(), x1, yValue); } } else { ga.setXPixelStart(-1); ga.setXPixelEnd(-1); } } g.setColor(oldColor); }
private void drawXAxis(Graphics g, Font font) { if (!xAxis.isDisplayed()) return; Color oldColor = g.getColor(); g.setColor(Color.BLACK); float leftBorder = getLeftBorder(); int yVal = getHeight() - getNumPixelsReservedOnBottom(); g.drawLine((int) leftBorder, yVal, getWidth(), yVal); float xInterval = (getWidth() - leftBorder) / xAxis.getNumberTicks(); FontMetrics fm = g.getFontMetrics(font); for (int x = 1; x < xAxis.getNumberTicks(); x++) { float xPos = leftBorder + (xInterval * x); g.setColor(Color.GRAY); g.drawLine((int) xPos, yVal, (int) (xPos), yVal + 5); float axisValue = xAxis.getLowVal() + (x / ((float) xAxis.getNumberTicks())) * (xAxis.getHighVal() - xAxis.getLowVal()); String axisString = new String("" + (int) (axisValue + 0.5)); float tickLabelPos = xPos - fm.stringWidth(axisString) / 2; g.setColor(Color.BLACK); g.drawString(axisString, (int) tickLabelPos, yVal + 18); } g.setColor(oldColor); }
private int getNumPixelsReservedOnBottom() { int numPixelsReserved = 0; if (showGeneAnnotations) numPixelsReserved += numPixelsReservedForGeneAnnotations; if (xAxis.isDisplayed) numPixelsReserved += xAxis.getNumPixelsReserved(); return numPixelsReserved; }
private int getYValue(HitScores hs, int ySize) { float val = selectedYAxis.getVal(hs); if (val > selectedYAxis.getHighVal()) return 0; if (val < selectedYAxis.getLowVal()) return ySize; float yVal = ySize - ySize * (val - selectedYAxis.getLowVal()) / (selectedYAxis.getHighVal() - selectedYAxis.getLowVal()); return (int) yVal; }
/** * Populates cells in the matrix corresponding to a particular axis. * * @param matrix Matrix to populate * @param axis Axis * @param axisInfo Description of axis * @param isColumns True if columns, false if rows * @param offset Ordinal of first cell to populate in matrix */ private void populateAxis( final Matrix matrix, final CellSetAxis axis, final AxisInfo axisInfo, final boolean isColumns, final int offset) { if (axis == null) return; final Member[] prevMembers = new Member[axisInfo.getWidth()]; final MemberCell[] prevMemberInfo = new MemberCell[axisInfo.getWidth()]; final Member[] members = new Member[axisInfo.getWidth()]; for (int i = 0; i < axis.getPositions().size(); i++) { final int x = offset + i; final Position position = axis.getPositions().get(i); int yOffset = 0; final List<Member> memberList = position.getMembers(); final Map<Hierarchy, List<Integer>> lvls = new HashMap<>(); for (int j = 0; j < memberList.size(); j++) { Member member = memberList.get(j); final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(j); List<Integer> depths = ordinalInfo.depths; Collections.sort(depths); lvls.put(member.getHierarchy(), depths); if (ordinalInfo.getDepths().size() > 0 && member.getDepth() < ordinalInfo.getDepths().get(0)) break; final int y = yOffset + ordinalInfo.depths.indexOf(member.getDepth()); members[y] = member; yOffset += ordinalInfo.getWidth(); } boolean expanded = false; boolean same = true; for (int y = 0; y < members.length; y++) { final MemberCell memberInfo = new MemberCell(); final Member member = members[y]; expanded = false; int index = memberList.indexOf(member); if (index >= 0) { final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(index); int depth_i = ordinalInfo.getDepths().indexOf(member.getDepth()); if (depth_i > 0) { expanded = true; } } memberInfo.setExpanded(expanded); same = same && i > 0 && Olap4jUtil.equal(prevMembers[y], member); if (member != null) { if (lvls != null && lvls.get(member.getHierarchy()) != null) { memberInfo.setProperty( "levelindex", "" + lvls.get(member.getHierarchy()).indexOf(member.getLevel().getDepth())); } if (x - 1 == offset) memberInfo.setLastRow(true); matrix.setOffset(offset); memberInfo.setRawValue(member.getUniqueName()); memberInfo.setFormattedValue(member.getCaption()); // First try to get a formatted value memberInfo.setParentDimension(member.getDimension().getName()); memberInfo.setHierarchy(member.getHierarchy().getUniqueName()); memberInfo.setLevel(member.getLevel().getUniqueName()); memberInfo.setUniquename(member.getUniqueName()); // try { // memberInfo.setChildMemberCount(member.getChildMemberCount()); // } catch (OlapException e) { // e.printStackTrace(); // throw new RuntimeException(e); // } // NamedList<Property> values = member.getLevel().getProperties(); // for(int j=0; j<values.size();j++){ // String val; // try { // val = member.getPropertyFormattedValue(values.get(j)); // } catch (OlapException e) { // e.printStackTrace(); // throw new RuntimeException(e); // } // memberInfo.setProperty(values.get(j).getCaption(), val); // } // if (y > 0) { // for (int previ = y-1; previ >= 0;previ--) { // if(prevMembers[previ] != null) { // memberInfo.setRightOf(prevMemberInfo[previ]); // memberInfo.setRightOfDimension(prevMembers[previ].getDimension().getName()); // previ = -1; // } // } // } // // // if (member.getParentMember() != null) // memberInfo.setParentMember(member.getParentMember().getUniqueName()); } else { memberInfo.setRawValue(null); memberInfo.setFormattedValue(null); memberInfo.setParentDimension(null); } if (isColumns) { memberInfo.setRight(false); memberInfo.setSameAsPrev(same); if (member != null) memberInfo.setParentDimension(member.getDimension().getName()); matrix.set(x, y, memberInfo); } else { memberInfo.setRight(false); memberInfo.setSameAsPrev(false); matrix.set(y, x, memberInfo); } int x_parent = isColumns ? x : y - 1; int y_parent = isColumns ? y - 1 : x; if (index >= 0) { final AxisOrdinalInfo ordinalInfo = axisInfo.ordinalInfos.get(index); int depth_i = ordinalInfo.getDepths().indexOf(member.getDepth()); while (depth_i > 0) { depth_i--; int parentDepth = (ordinalInfo.getDepths().get(depth_i)); Member parent = member.getParentMember(); while (parent != null && parent.getDepth() > parentDepth) { parent = parent.getParentMember(); } final MemberCell pInfo = new MemberCell(); if (parent != null) { pInfo.setRawValue(parent.getUniqueName()); pInfo.setFormattedValue(parent.getCaption()); // First try to get a formatted value pInfo.setParentDimension(parent.getDimension().getName()); pInfo.setHierarchy(parent.getHierarchy().getUniqueName()); pInfo.setUniquename(parent.getUniqueName()); pInfo.setLevel(parent.getLevel().getUniqueName()); } else { pInfo.setRawValue(""); pInfo.setFormattedValue(""); // First try to get a formatted value pInfo.setParentDimension(member.getDimension().getName()); pInfo.setHierarchy(member.getHierarchy().getUniqueName()); pInfo.setLevel(member.getLevel().getUniqueName()); pInfo.setUniquename(""); } matrix.set(x_parent, y_parent, pInfo); if (isColumns) { y_parent--; } else { x_parent--; } } } prevMembers[y] = member; prevMemberInfo[y] = memberInfo; members[y] = null; } } }
/** * Formats a two-dimensional page. * * @param cellSet Cell set * @param pageCoords Coordinates of page [page, chapter, section, ...] * @param columnsAxis Columns axis * @param columnsAxisInfo Description of columns axis * @param rowsAxis Rows axis * @param rowsAxisInfo Description of rows axis */ private Matrix formatPage( final CellSet cellSet, final int[] pageCoords, final CellSetAxis columnsAxis, final AxisInfo columnsAxisInfo, final CellSetAxis rowsAxis, final AxisInfo rowsAxisInfo) { // Figure out the dimensions of the blank rectangle in the top left // corner. final int yOffset = columnsAxisInfo.getWidth(); final int xOffsset = rowsAxisInfo.getWidth(); // Populate a string matrix final Matrix matrix = new Matrix( xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()), yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size())); // Populate corner List<Level> levels = new ArrayList<>(); if (rowsAxis != null && rowsAxis.getPositions().size() > 0) { Position p = rowsAxis.getPositions().get(0); for (int m = 0; m < p.getMembers().size(); m++) { AxisOrdinalInfo a = rowsAxisInfo.ordinalInfos.get(m); for (Integer depth : a.getDepths()) { levels.add(a.getLevel(depth)); } } for (int x = 0; x < xOffsset; x++) { Level xLevel = levels.get(x); String s = xLevel.getCaption(); for (int y = 0; y < yOffset; y++) { final MemberCell memberInfo = new MemberCell(false, x > 0); if (y == yOffset - 1) { memberInfo.setRawValue(s); memberInfo.setFormattedValue(s); memberInfo.setProperty("__headertype", "row_header_header"); memberInfo.setProperty("levelindex", "" + levels.indexOf(xLevel)); memberInfo.setHierarchy(xLevel.getHierarchy().getUniqueName()); memberInfo.setParentDimension(xLevel.getDimension().getName()); memberInfo.setLevel(xLevel.getUniqueName()); } matrix.set(x, y, memberInfo); } } } // Populate matrix with cells representing axes // noinspection SuspiciousNameCombination populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset); populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset); // Populate cell values for (final Cell cell : cellIter(pageCoords, cellSet)) { final List<Integer> coordList = cell.getCoordinateList(); int x = xOffsset; if (coordList.size() > 0) x += coordList.get(0); int y = yOffset; if (coordList.size() > 1) y += coordList.get(1); final DataCell cellInfo = new DataCell(true, false, coordList); cellInfo.setCoordinates(cell.getCoordinateList()); if (cell.getValue() != null) { try { cellInfo.setRawNumber(cell.getDoubleValue()); } catch (Exception e1) { } } String cellValue = cell.getFormattedValue(); // First try to get a // formatted value if (cellValue == null || cellValue.equals("null")) { // $NON-NLS-1$ cellValue = ""; // $NON-NLS-1$ } if (cellValue.length() < 1) { final Object value = cell.getValue(); if (value == null || value.equals("null")) // $NON-NLS-1$ cellValue = ""; // $NON-NLS-1$ else { try { // TODO this needs to become query / execution specific DecimalFormat myFormatter = new DecimalFormat(SaikuProperties.formatDefautNumberFormat); // $NON-NLS-1$ DecimalFormatSymbols dfs = new DecimalFormatSymbols(SaikuProperties.locale); myFormatter.setDecimalFormatSymbols(dfs); cellValue = myFormatter.format(cell.getValue()); } catch (Exception e) { // TODO: handle exception } } // the raw value } // Format string is relevant for Excel export // xmla cells can throw an error on this try { String formatString = (String) cell.getPropertyValue(Property.StandardCellProperty.FORMAT_STRING); if (formatString != null && !formatString.startsWith("|")) { cellInfo.setFormatString(formatString); } else { formatString = formatString.substring(1, formatString.length()); cellInfo.setFormatString(formatString.substring(0, formatString.indexOf("|"))); } } catch (Exception e) { // we tried } Map<String, String> cellProperties = new HashMap<>(); String val = Olap4jUtil.parseFormattedCellValue(cellValue, cellProperties); if (!cellProperties.isEmpty()) { cellInfo.setProperties(cellProperties); } cellInfo.setFormattedValue(val); matrix.set(x, y, cellInfo); } return matrix; }
public void setHighX(int highX) { xAxis.setHighVal(highX); }
public int getHighX() { return (int) xAxis.getHighVal(); }
public void setLowX(int lowX) { xAxis.setLowVal(lowX); }
public int getLowX() { return (int) xAxis.getLowVal(); }
public void zoomOutX(boolean repaint) { xAxis.zoomOut(hits); if (repaint) repaint(); }
public void zoomOutY(boolean repaint) { selectedYAxis.zoomOut(hits); if (repaint) repaint(); }
private void drawYAxisAndHorizontalLines(Graphics g, Font fontForAxisLabels) { Color oldColor = g.getColor(); g.setColor(Color.BLACK); float ySize = getHeight() - getNumPixelsReservedOnBottom(); if (selectedYAxis.isDisplayed()) g.drawLine( selectedYAxis.getNumPixelsReserved(), 0, selectedYAxis.getNumPixelsReserved(), (int) ySize); if (selectedYAxis.getNumberTicks() < 1) return; g.setFont(fontForAxisLabels); int leftBorder = getLeftBorder(); if (selectedYAxis.isDisplayed()) { g.setColor(Color.RED); g.drawString(selectedYAxis.getAxisName(), selectedYAxis.numPixelsReserved, 10); g.setColor(Color.BLACK); } float yInterval = ySize / selectedYAxis.getNumberTicks(); FontMetrics fm = g.getFontMetrics(fontForAxisLabels); int stringAscent = fm.getAscent(); for (int x = 1; x < selectedYAxis.getNumberTicks(); x++) { int yVal = (int) (yInterval * x); g.setColor(Color.GRAY); g.drawLine(leftBorder, yVal, getWidth(), yVal); float axisValue = selectedYAxis.getHighVal() - (x / ((float) selectedYAxis.getNumberTicks())) * (selectedYAxis.getHighVal() - selectedYAxis.getLowVal()); String axisString = getYAxisTickLabel(axisValue); int tickLabelPos = selectedYAxis.getNumPixelsReserved() - fm.stringWidth(axisString) - 2; g.setColor(Color.BLACK); if (selectedYAxis.isDisplayed()) g.drawString(axisString, tickLabelPos, yVal + stringAscent / 2); } g.setColor(oldColor); }