@Test public void largeAndSmallCells() throws Exception { Cell2DDataset data = largeAndSmallCellsDataset(); IntensityGraph2DRenderer renderer = new IntensityGraph2DRenderer(100, 100); GraphBuffer graphBuffer = new GraphBuffer(renderer); renderer.draw(graphBuffer, data); ImageAssert.compareImages("intensityGraph2D.largeAndSmallCells", graphBuffer.getImage()); }
public void draw(GraphBuffer graphBuffer, Cell2DDataset data) { this.g = graphBuffer.getGraphicsContext(); GraphAreaData area = new GraphAreaData(); BufferedImage image = graphBuffer.getImage(); calculateRanges(data.getXRange(), data.getXRange(), data.getYRange(), data.getYRange()); area.setGraphBuffer(graphBuffer); graphBuffer.drawBackground(backgroundColor); calculateZRange(data.getStatistics().getRange(), data.getDisplayRange()); int areaRightPixel; if(drawLegend){ calculateZLabels(); areaRightPixel = getImageWidth() - 1 - (graphAreaToLegendMargin + legendWidth + zLabelMargin + zLabelMaxWidth + rightMargin); } else { areaRightPixel = getImageWidth() - 1 - rightMargin; } area.setGraphArea(leftMargin, getImageHeight() - 1 - bottomMargin, areaRightPixel, topMargin); area.setGraphPadding(leftAreaMargin, bottomAreaMargin, rightAreaMargin, topAreaMargin); area.setLabelMargin(xLabelMargin, yLabelMargin); area.setRanges(getXPlotRange(), xValueScale, getYPlotRange(), yValueScale); area.prepareLabels(labelFont, labelColor); area.prepareGraphArea(true, referenceLineColor); area.drawGraphArea(); if(drawLegend){ if (zReferenceValues != null) { int[] zRefCoords = new int[zReferenceValues.size()]; if(zRefCoords.length == 1){ zRefCoords[0] = area.areaTop; } else{ for (int i = 0; i < zRefCoords.length; i++) { zRefCoords[i] = (int) scaledZ(zReferenceValues.getDouble(i), area.graphBottom, area.graphTop); } } zReferenceCoords = new ArrayInt(zRefCoords); } } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (!optimizeColorScheme){ colorMapInstance = colorMap.createInstance(zPlotRange); } else { if (colorMapInstance == null || !Objects.equals(optimizedRange, zRange)) { colorMapInstance = colorMap.createInstance(zPlotRange); colorMapInstance = NumberColorMaps.optimize(colorMapInstance, zPlotRange); optimizedRange = zPlotRange; } } double xStartGraph = super.xPlotCoordStart; double yEndGraph = area.graphBottom; double yHeightTotal = area.graphBottom - area.graphTop + 1; int startX = area.graphLeft; int startY = area.graphTop; int endX = area.graphRight; int endY = area.graphBottom; PointToDataMap xPointToDataMap = createXPointToDataMap(startX, endX, graphBuffer, data.getXBoundaries()); PointToDataMap yPointToDataMap = createYPointToDataMap(startY, endY, graphBuffer, data.getYBoundaries()); graphBuffer.drawDataImage(xPointToDataMap.startPoint, yPointToDataMap.startPoint, xPointToDataMap.pointToDataMap, yPointToDataMap.pointToDataMap, data, colorMapInstance); if(drawLegend && legendWidth>0){ ListNumber dataList = ListNumbers.linearListFromRange(zPlotRange.getMinimum(),zPlotRange.getMaximum(),(int)yHeightTotal); Cell2DDataset legendData = Cell2DDatasets.linearRange(dataList, Ranges.range(0, 1), 1, Ranges.range(0, (int)yHeightTotal), (int)yHeightTotal); int xLegendStart = getImageWidth() - originalRightMargin - zLabelMaxWidth - zLabelMargin - legendWidth; drawRectanglesArray(g, legendData, xLegendStart, yEndGraph, legendWidth, yHeightTotal, 1, legendWidth, image); graphBuffer.drawLeftLabels(zReferenceLabels, zReferenceCoords, labelColor, labelFont, area.areaBottom, area.areaTop, getImageWidth() - originalRightMargin - 1); } if (xPixelSelectionRange != null && yPixelSelectionRange != null) { int selectionLeftPixel = (int) xPixelSelectionRange.getMinimum(); int selectionRightPixel = (int) xPixelSelectionRange.getMaximum(); int selectionTopPixel = (int) yPixelSelectionRange.getMinimum(); int selectionBottomPixel = (int) yPixelSelectionRange.getMaximum(); double selectionLeftValue = graphBuffer.xPixelLeftToValue(selectionLeftPixel); double selectionRightValue = graphBuffer.xPixelRightToValue(selectionRightPixel); double selectionTopValue = graphBuffer.yPixelTopToValue(selectionTopPixel); double selectionBottomValue = graphBuffer.yPixelBottomToValue(selectionBottomPixel); xValueSelectionRange = Ranges.range(selectionLeftValue, selectionRightValue); yValueSelectionRange = Ranges.range(selectionBottomValue, selectionTopValue); int xLeftOffset = selectionLeftPixel - xPointToDataMap.startPoint; int xRightOffset = selectionRightPixel - xPointToDataMap.startPoint; if ((xLeftOffset < 0 && xRightOffset <0) || (xLeftOffset >= xPointToDataMap.pointToDataMap.length && xRightOffset >= xPointToDataMap.pointToDataMap.length)) { xIndexSelectionRange = null; } else { xLeftOffset = Math.max(0, xLeftOffset); xRightOffset = Math.min(xPointToDataMap.pointToDataMap.length, xRightOffset); xIndexSelectionRange = Ranges.range(xPointToDataMap.pointToDataMap[xLeftOffset], xPointToDataMap.pointToDataMap[xRightOffset]); } int yBottomOffset = selectionBottomPixel - yPointToDataMap.startPoint; int yTopOffset = selectionTopPixel - yPointToDataMap.startPoint; if ((yBottomOffset < 0 && yTopOffset <0) || (yBottomOffset >= yPointToDataMap.pointToDataMap.length && yTopOffset >= yPointToDataMap.pointToDataMap.length)) { yIndexSelectionRange = null; } else { yTopOffset = Math.max(0, yTopOffset); yBottomOffset = Math.min(xPointToDataMap.pointToDataMap.length, yBottomOffset); yIndexSelectionRange = Ranges.range(yPointToDataMap.pointToDataMap[yBottomOffset], yPointToDataMap.pointToDataMap[yTopOffset]); } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setColor(Color.BLACK); graphBuffer.getGraphicsContext().drawRect(selectionLeftPixel, selectionTopPixel, selectionRightPixel - selectionLeftPixel, selectionBottomPixel - selectionTopPixel); } }
IntensityGraph2DRenderer extends Graph2DRenderer<IntensityGraph2DRendererUpdate> { public void draw(GraphBuffer graphBuffer, Cell2DDataset data) { this.g = graphBuffer.getGraphicsContext(); GraphAreaData area = new GraphAreaData(); BufferedImage image = graphBuffer.getImage(); calculateRanges(data.getXRange(), data.getXRange(), data.getYRange(), data.getYRange()); area.setGraphBuffer(graphBuffer); graphBuffer.drawBackground(backgroundColor); calculateZRange(data.getStatistics().getRange(), data.getDisplayRange()); int areaRightPixel; if(drawLegend){ calculateZLabels(); areaRightPixel = getImageWidth() - 1 - (graphAreaToLegendMargin + legendWidth + zLabelMargin + zLabelMaxWidth + rightMargin); } else { areaRightPixel = getImageWidth() - 1 - rightMargin; } area.setGraphArea(leftMargin, getImageHeight() - 1 - bottomMargin, areaRightPixel, topMargin); area.setGraphPadding(leftAreaMargin, bottomAreaMargin, rightAreaMargin, topAreaMargin); area.setLabelMargin(xLabelMargin, yLabelMargin); area.setRanges(getXPlotRange(), xValueScale, getYPlotRange(), yValueScale); area.prepareLabels(labelFont, labelColor); area.prepareGraphArea(true, referenceLineColor); area.drawGraphArea(); if(drawLegend){ if (zReferenceValues != null) { int[] zRefCoords = new int[zReferenceValues.size()]; if(zRefCoords.length == 1){ zRefCoords[0] = area.areaTop; } else{ for (int i = 0; i < zRefCoords.length; i++) { zRefCoords[i] = (int) scaledZ(zReferenceValues.getDouble(i), area.graphBottom, area.graphTop); } } zReferenceCoords = new ArrayInt(zRefCoords); } } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (!optimizeColorScheme){ colorMapInstance = colorMap.createInstance(zPlotRange); } else { if (colorMapInstance == null || !Objects.equals(optimizedRange, zRange)) { colorMapInstance = colorMap.createInstance(zPlotRange); colorMapInstance = NumberColorMaps.optimize(colorMapInstance, zPlotRange); optimizedRange = zPlotRange; } } double xStartGraph = super.xPlotCoordStart; double yEndGraph = area.graphBottom; double yHeightTotal = area.graphBottom - area.graphTop + 1; int startX = area.graphLeft; int startY = area.graphTop; int endX = area.graphRight; int endY = area.graphBottom; PointToDataMap xPointToDataMap = createXPointToDataMap(startX, endX, graphBuffer, data.getXBoundaries()); PointToDataMap yPointToDataMap = createYPointToDataMap(startY, endY, graphBuffer, data.getYBoundaries()); graphBuffer.drawDataImage(xPointToDataMap.startPoint, yPointToDataMap.startPoint, xPointToDataMap.pointToDataMap, yPointToDataMap.pointToDataMap, data, colorMapInstance); if(drawLegend && legendWidth>0){ ListNumber dataList = ListNumbers.linearListFromRange(zPlotRange.getMinimum(),zPlotRange.getMaximum(),(int)yHeightTotal); Cell2DDataset legendData = Cell2DDatasets.linearRange(dataList, Ranges.range(0, 1), 1, Ranges.range(0, (int)yHeightTotal), (int)yHeightTotal); int xLegendStart = getImageWidth() - originalRightMargin - zLabelMaxWidth - zLabelMargin - legendWidth; drawRectanglesArray(g, legendData, xLegendStart, yEndGraph, legendWidth, yHeightTotal, 1, legendWidth, image); graphBuffer.drawLeftLabels(zReferenceLabels, zReferenceCoords, labelColor, labelFont, area.areaBottom, area.areaTop, getImageWidth() - originalRightMargin - 1); } if (xPixelSelectionRange != null && yPixelSelectionRange != null) { int selectionLeftPixel = (int) xPixelSelectionRange.getMinimum(); int selectionRightPixel = (int) xPixelSelectionRange.getMaximum(); int selectionTopPixel = (int) yPixelSelectionRange.getMinimum(); int selectionBottomPixel = (int) yPixelSelectionRange.getMaximum(); double selectionLeftValue = graphBuffer.xPixelLeftToValue(selectionLeftPixel); double selectionRightValue = graphBuffer.xPixelRightToValue(selectionRightPixel); double selectionTopValue = graphBuffer.yPixelTopToValue(selectionTopPixel); double selectionBottomValue = graphBuffer.yPixelBottomToValue(selectionBottomPixel); xValueSelectionRange = Ranges.range(selectionLeftValue, selectionRightValue); yValueSelectionRange = Ranges.range(selectionBottomValue, selectionTopValue); int xLeftOffset = selectionLeftPixel - xPointToDataMap.startPoint; int xRightOffset = selectionRightPixel - xPointToDataMap.startPoint; if ((xLeftOffset < 0 && xRightOffset <0) || (xLeftOffset >= xPointToDataMap.pointToDataMap.length && xRightOffset >= xPointToDataMap.pointToDataMap.length)) { xIndexSelectionRange = null; } else { xLeftOffset = Math.max(0, xLeftOffset); xRightOffset = Math.min(xPointToDataMap.pointToDataMap.length, xRightOffset); xIndexSelectionRange = Ranges.range(xPointToDataMap.pointToDataMap[xLeftOffset], xPointToDataMap.pointToDataMap[xRightOffset]); } int yBottomOffset = selectionBottomPixel - yPointToDataMap.startPoint; int yTopOffset = selectionTopPixel - yPointToDataMap.startPoint; if ((yBottomOffset < 0 && yTopOffset <0) || (yBottomOffset >= yPointToDataMap.pointToDataMap.length && yTopOffset >= yPointToDataMap.pointToDataMap.length)) { yIndexSelectionRange = null; } else { yTopOffset = Math.max(0, yTopOffset); yBottomOffset = Math.min(xPointToDataMap.pointToDataMap.length, yBottomOffset); yIndexSelectionRange = Ranges.range(yPointToDataMap.pointToDataMap[yBottomOffset], yPointToDataMap.pointToDataMap[yTopOffset]); } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setColor(Color.BLACK); graphBuffer.getGraphicsContext().drawRect(selectionLeftPixel, selectionTopPixel, selectionRightPixel - selectionLeftPixel, selectionBottomPixel - selectionTopPixel); } } }
IntensityGraph2DRenderer extends Graph2DRenderer<IntensityGraph2DRendererUpdate> { public void draw(GraphBuffer graphBuffer, Cell2DDataset data) { this.g = graphBuffer.getGraphicsContext(); GraphAreaData area = new GraphAreaData(); BufferedImage image = graphBuffer.getImage(); calculateRanges(data.getXRange(), data.getXRange(), data.getYRange(), data.getYRange()); area.setGraphBuffer(graphBuffer); graphBuffer.drawBackground(backgroundColor); calculateZRange(data.getStatistics().getRange(), data.getDisplayRange()); int areaRightPixel; if(drawLegend){ calculateZLabels(); areaRightPixel = getImageWidth() - 1 - (graphAreaToLegendMargin + legendWidth + zLabelMargin + zLabelMaxWidth + rightMargin); } else { areaRightPixel = getImageWidth() - 1 - rightMargin; } area.setGraphArea(leftMargin, getImageHeight() - 1 - bottomMargin, areaRightPixel, topMargin); area.setGraphPadding(leftAreaMargin, bottomAreaMargin, rightAreaMargin, topAreaMargin); area.setLabelMargin(xLabelMargin, yLabelMargin); area.setRanges(getXPlotRange(), xValueScale, getYPlotRange(), yValueScale); area.prepareLabels(labelFont, labelColor); area.prepareGraphArea(true, referenceLineColor); area.drawGraphArea(); if(drawLegend){ if (zReferenceValues != null) { int[] zRefCoords = new int[zReferenceValues.size()]; if(zRefCoords.length == 1){ zRefCoords[0] = area.areaTop; } else{ for (int i = 0; i < zRefCoords.length; i++) { zRefCoords[i] = (int) scaledZ(zReferenceValues.getDouble(i), area.graphBottom, area.graphTop); } } zReferenceCoords = new ArrayInt(zRefCoords); } } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (!optimizeColorScheme){ colorMapInstance = colorMap.createInstance(zPlotRange); } else { if (colorMapInstance == null || !Objects.equals(optimizedRange, zRange)) { colorMapInstance = colorMap.createInstance(zPlotRange); colorMapInstance = NumberColorMaps.optimize(colorMapInstance, zPlotRange); optimizedRange = zPlotRange; } } double xStartGraph = super.xPlotCoordStart; double yEndGraph = area.graphBottom; double yHeightTotal = area.graphBottom - area.graphTop + 1; int startX = area.graphLeft; int startY = area.graphTop; int endX = area.graphRight; int endY = area.graphBottom; PointToDataMap xPointToDataMap = createXPointToDataMap(startX, endX, graphBuffer, data.getXBoundaries()); PointToDataMap yPointToDataMap = createYPointToDataMap(startY, endY, graphBuffer, data.getYBoundaries()); graphBuffer.drawDataImage(xPointToDataMap.startPoint, yPointToDataMap.startPoint, xPointToDataMap.pointToDataMap, yPointToDataMap.pointToDataMap, data, colorMapInstance); if(drawLegend && legendWidth>0){ ListNumber dataList = ListNumbers.linearListFromRange(zPlotRange.getMinimum(),zPlotRange.getMaximum(),(int)yHeightTotal); Cell2DDataset legendData = Cell2DDatasets.linearRange(dataList, Ranges.range(0, 1), 1, Ranges.range(0, (int)yHeightTotal), (int)yHeightTotal); int xLegendStart = getImageWidth() - originalRightMargin - zLabelMaxWidth - zLabelMargin - legendWidth; drawRectanglesArray(g, legendData, xLegendStart, yEndGraph, legendWidth, yHeightTotal, 1, legendWidth, image); graphBuffer.drawLeftLabels(zReferenceLabels, zReferenceCoords, labelColor, labelFont, area.areaBottom, area.areaTop, getImageWidth() - originalRightMargin - 1); } if (xPixelSelectionRange != null && yPixelSelectionRange != null) { int selectionLeftPixel = (int) xPixelSelectionRange.getMinimum(); int selectionRightPixel = (int) xPixelSelectionRange.getMaximum(); int selectionTopPixel = (int) yPixelSelectionRange.getMinimum(); int selectionBottomPixel = (int) yPixelSelectionRange.getMaximum(); double selectionLeftValue = graphBuffer.xPixelLeftToValue(selectionLeftPixel); double selectionRightValue = graphBuffer.xPixelRightToValue(selectionRightPixel); double selectionTopValue = graphBuffer.yPixelTopToValue(selectionTopPixel); double selectionBottomValue = graphBuffer.yPixelBottomToValue(selectionBottomPixel); xValueSelectionRange = Ranges.range(selectionLeftValue, selectionRightValue); yValueSelectionRange = Ranges.range(selectionBottomValue, selectionTopValue); int xLeftOffset = selectionLeftPixel - xPointToDataMap.startPoint; int xRightOffset = selectionRightPixel - xPointToDataMap.startPoint; if ((xLeftOffset < 0 && xRightOffset <0) || (xLeftOffset >= xPointToDataMap.pointToDataMap.length && xRightOffset >= xPointToDataMap.pointToDataMap.length)) { xIndexSelectionRange = null; } else { xLeftOffset = Math.max(0, xLeftOffset); xRightOffset = Math.min(xPointToDataMap.pointToDataMap.length, xRightOffset); xIndexSelectionRange = Ranges.range(xPointToDataMap.pointToDataMap[xLeftOffset], xPointToDataMap.pointToDataMap[xRightOffset]); } int yBottomOffset = selectionBottomPixel - yPointToDataMap.startPoint; int yTopOffset = selectionTopPixel - yPointToDataMap.startPoint; if ((yBottomOffset < 0 && yTopOffset <0) || (yBottomOffset >= yPointToDataMap.pointToDataMap.length && yTopOffset >= yPointToDataMap.pointToDataMap.length)) { yIndexSelectionRange = null; } else { yTopOffset = Math.max(0, yTopOffset); yBottomOffset = Math.min(xPointToDataMap.pointToDataMap.length, yBottomOffset); yIndexSelectionRange = Ranges.range(yPointToDataMap.pointToDataMap[yBottomOffset], yPointToDataMap.pointToDataMap[yTopOffset]); } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setColor(Color.BLACK); graphBuffer.getGraphicsContext().drawRect(selectionLeftPixel, selectionTopPixel, selectionRightPixel - selectionLeftPixel, selectionBottomPixel - selectionTopPixel); } } IntensityGraph2DRenderer(int imageWidth, int imageHeight);  IntensityGraph2DRenderer(); }
IntensityGraph2DRenderer extends Graph2DRenderer<IntensityGraph2DRendererUpdate> { public void draw(GraphBuffer graphBuffer, Cell2DDataset data) { this.g = graphBuffer.getGraphicsContext(); GraphAreaData area = new GraphAreaData(); BufferedImage image = graphBuffer.getImage(); calculateRanges(data.getXRange(), data.getXRange(), data.getYRange(), data.getYRange()); area.setGraphBuffer(graphBuffer); graphBuffer.drawBackground(backgroundColor); calculateZRange(data.getStatistics().getRange(), data.getDisplayRange()); int areaRightPixel; if(drawLegend){ calculateZLabels(); areaRightPixel = getImageWidth() - 1 - (graphAreaToLegendMargin + legendWidth + zLabelMargin + zLabelMaxWidth + rightMargin); } else { areaRightPixel = getImageWidth() - 1 - rightMargin; } area.setGraphArea(leftMargin, getImageHeight() - 1 - bottomMargin, areaRightPixel, topMargin); area.setGraphPadding(leftAreaMargin, bottomAreaMargin, rightAreaMargin, topAreaMargin); area.setLabelMargin(xLabelMargin, yLabelMargin); area.setRanges(getXPlotRange(), xValueScale, getYPlotRange(), yValueScale); area.prepareLabels(labelFont, labelColor); area.prepareGraphArea(true, referenceLineColor); area.drawGraphArea(); if(drawLegend){ if (zReferenceValues != null) { int[] zRefCoords = new int[zReferenceValues.size()]; if(zRefCoords.length == 1){ zRefCoords[0] = area.areaTop; } else{ for (int i = 0; i < zRefCoords.length; i++) { zRefCoords[i] = (int) scaledZ(zReferenceValues.getDouble(i), area.graphBottom, area.graphTop); } } zReferenceCoords = new ArrayInt(zRefCoords); } } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (!optimizeColorScheme){ colorMapInstance = colorMap.createInstance(zPlotRange); } else { if (colorMapInstance == null || !Objects.equals(optimizedRange, zRange)) { colorMapInstance = colorMap.createInstance(zPlotRange); colorMapInstance = NumberColorMaps.optimize(colorMapInstance, zPlotRange); optimizedRange = zPlotRange; } } double xStartGraph = super.xPlotCoordStart; double yEndGraph = area.graphBottom; double yHeightTotal = area.graphBottom - area.graphTop + 1; int startX = area.graphLeft; int startY = area.graphTop; int endX = area.graphRight; int endY = area.graphBottom; PointToDataMap xPointToDataMap = createXPointToDataMap(startX, endX, graphBuffer, data.getXBoundaries()); PointToDataMap yPointToDataMap = createYPointToDataMap(startY, endY, graphBuffer, data.getYBoundaries()); graphBuffer.drawDataImage(xPointToDataMap.startPoint, yPointToDataMap.startPoint, xPointToDataMap.pointToDataMap, yPointToDataMap.pointToDataMap, data, colorMapInstance); if(drawLegend && legendWidth>0){ ListNumber dataList = ListNumbers.linearListFromRange(zPlotRange.getMinimum(),zPlotRange.getMaximum(),(int)yHeightTotal); Cell2DDataset legendData = Cell2DDatasets.linearRange(dataList, Ranges.range(0, 1), 1, Ranges.range(0, (int)yHeightTotal), (int)yHeightTotal); int xLegendStart = getImageWidth() - originalRightMargin - zLabelMaxWidth - zLabelMargin - legendWidth; drawRectanglesArray(g, legendData, xLegendStart, yEndGraph, legendWidth, yHeightTotal, 1, legendWidth, image); graphBuffer.drawLeftLabels(zReferenceLabels, zReferenceCoords, labelColor, labelFont, area.areaBottom, area.areaTop, getImageWidth() - originalRightMargin - 1); } if (xPixelSelectionRange != null && yPixelSelectionRange != null) { int selectionLeftPixel = (int) xPixelSelectionRange.getMinimum(); int selectionRightPixel = (int) xPixelSelectionRange.getMaximum(); int selectionTopPixel = (int) yPixelSelectionRange.getMinimum(); int selectionBottomPixel = (int) yPixelSelectionRange.getMaximum(); double selectionLeftValue = graphBuffer.xPixelLeftToValue(selectionLeftPixel); double selectionRightValue = graphBuffer.xPixelRightToValue(selectionRightPixel); double selectionTopValue = graphBuffer.yPixelTopToValue(selectionTopPixel); double selectionBottomValue = graphBuffer.yPixelBottomToValue(selectionBottomPixel); xValueSelectionRange = Ranges.range(selectionLeftValue, selectionRightValue); yValueSelectionRange = Ranges.range(selectionBottomValue, selectionTopValue); int xLeftOffset = selectionLeftPixel - xPointToDataMap.startPoint; int xRightOffset = selectionRightPixel - xPointToDataMap.startPoint; if ((xLeftOffset < 0 && xRightOffset <0) || (xLeftOffset >= xPointToDataMap.pointToDataMap.length && xRightOffset >= xPointToDataMap.pointToDataMap.length)) { xIndexSelectionRange = null; } else { xLeftOffset = Math.max(0, xLeftOffset); xRightOffset = Math.min(xPointToDataMap.pointToDataMap.length, xRightOffset); xIndexSelectionRange = Ranges.range(xPointToDataMap.pointToDataMap[xLeftOffset], xPointToDataMap.pointToDataMap[xRightOffset]); } int yBottomOffset = selectionBottomPixel - yPointToDataMap.startPoint; int yTopOffset = selectionTopPixel - yPointToDataMap.startPoint; if ((yBottomOffset < 0 && yTopOffset <0) || (yBottomOffset >= yPointToDataMap.pointToDataMap.length && yTopOffset >= yPointToDataMap.pointToDataMap.length)) { yIndexSelectionRange = null; } else { yTopOffset = Math.max(0, yTopOffset); yBottomOffset = Math.min(xPointToDataMap.pointToDataMap.length, yBottomOffset); yIndexSelectionRange = Ranges.range(yPointToDataMap.pointToDataMap[yBottomOffset], yPointToDataMap.pointToDataMap[yTopOffset]); } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setColor(Color.BLACK); graphBuffer.getGraphicsContext().drawRect(selectionLeftPixel, selectionTopPixel, selectionRightPixel - selectionLeftPixel, selectionBottomPixel - selectionTopPixel); } } IntensityGraph2DRenderer(int imageWidth, int imageHeight);  IntensityGraph2DRenderer(); @Override void update(IntensityGraph2DRendererUpdate update); void draw(GraphBuffer graphBuffer, Cell2DDataset data); @Override IntensityGraph2DRendererUpdate newUpdate(); boolean isDrawLegend(); NumberColorMap getColorMap(); Range getXIndexSelectionRange(); Range getYIndexSelectionRange(); Range getXValueSelectionRange(); Range getYValueSelectionRange(); Range getXPixelSelectionRange(); Range getYPixelSelectionRange(); }
IntensityGraph2DRenderer extends Graph2DRenderer<IntensityGraph2DRendererUpdate> { public void draw(GraphBuffer graphBuffer, Cell2DDataset data) { this.g = graphBuffer.getGraphicsContext(); GraphAreaData area = new GraphAreaData(); BufferedImage image = graphBuffer.getImage(); calculateRanges(data.getXRange(), data.getXRange(), data.getYRange(), data.getYRange()); area.setGraphBuffer(graphBuffer); graphBuffer.drawBackground(backgroundColor); calculateZRange(data.getStatistics().getRange(), data.getDisplayRange()); int areaRightPixel; if(drawLegend){ calculateZLabels(); areaRightPixel = getImageWidth() - 1 - (graphAreaToLegendMargin + legendWidth + zLabelMargin + zLabelMaxWidth + rightMargin); } else { areaRightPixel = getImageWidth() - 1 - rightMargin; } area.setGraphArea(leftMargin, getImageHeight() - 1 - bottomMargin, areaRightPixel, topMargin); area.setGraphPadding(leftAreaMargin, bottomAreaMargin, rightAreaMargin, topAreaMargin); area.setLabelMargin(xLabelMargin, yLabelMargin); area.setRanges(getXPlotRange(), xValueScale, getYPlotRange(), yValueScale); area.prepareLabels(labelFont, labelColor); area.prepareGraphArea(true, referenceLineColor); area.drawGraphArea(); if(drawLegend){ if (zReferenceValues != null) { int[] zRefCoords = new int[zReferenceValues.size()]; if(zRefCoords.length == 1){ zRefCoords[0] = area.areaTop; } else{ for (int i = 0; i < zRefCoords.length; i++) { zRefCoords[i] = (int) scaledZ(zReferenceValues.getDouble(i), area.graphBottom, area.graphTop); } } zReferenceCoords = new ArrayInt(zRefCoords); } } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (!optimizeColorScheme){ colorMapInstance = colorMap.createInstance(zPlotRange); } else { if (colorMapInstance == null || !Objects.equals(optimizedRange, zRange)) { colorMapInstance = colorMap.createInstance(zPlotRange); colorMapInstance = NumberColorMaps.optimize(colorMapInstance, zPlotRange); optimizedRange = zPlotRange; } } double xStartGraph = super.xPlotCoordStart; double yEndGraph = area.graphBottom; double yHeightTotal = area.graphBottom - area.graphTop + 1; int startX = area.graphLeft; int startY = area.graphTop; int endX = area.graphRight; int endY = area.graphBottom; PointToDataMap xPointToDataMap = createXPointToDataMap(startX, endX, graphBuffer, data.getXBoundaries()); PointToDataMap yPointToDataMap = createYPointToDataMap(startY, endY, graphBuffer, data.getYBoundaries()); graphBuffer.drawDataImage(xPointToDataMap.startPoint, yPointToDataMap.startPoint, xPointToDataMap.pointToDataMap, yPointToDataMap.pointToDataMap, data, colorMapInstance); if(drawLegend && legendWidth>0){ ListNumber dataList = ListNumbers.linearListFromRange(zPlotRange.getMinimum(),zPlotRange.getMaximum(),(int)yHeightTotal); Cell2DDataset legendData = Cell2DDatasets.linearRange(dataList, Ranges.range(0, 1), 1, Ranges.range(0, (int)yHeightTotal), (int)yHeightTotal); int xLegendStart = getImageWidth() - originalRightMargin - zLabelMaxWidth - zLabelMargin - legendWidth; drawRectanglesArray(g, legendData, xLegendStart, yEndGraph, legendWidth, yHeightTotal, 1, legendWidth, image); graphBuffer.drawLeftLabels(zReferenceLabels, zReferenceCoords, labelColor, labelFont, area.areaBottom, area.areaTop, getImageWidth() - originalRightMargin - 1); } if (xPixelSelectionRange != null && yPixelSelectionRange != null) { int selectionLeftPixel = (int) xPixelSelectionRange.getMinimum(); int selectionRightPixel = (int) xPixelSelectionRange.getMaximum(); int selectionTopPixel = (int) yPixelSelectionRange.getMinimum(); int selectionBottomPixel = (int) yPixelSelectionRange.getMaximum(); double selectionLeftValue = graphBuffer.xPixelLeftToValue(selectionLeftPixel); double selectionRightValue = graphBuffer.xPixelRightToValue(selectionRightPixel); double selectionTopValue = graphBuffer.yPixelTopToValue(selectionTopPixel); double selectionBottomValue = graphBuffer.yPixelBottomToValue(selectionBottomPixel); xValueSelectionRange = Ranges.range(selectionLeftValue, selectionRightValue); yValueSelectionRange = Ranges.range(selectionBottomValue, selectionTopValue); int xLeftOffset = selectionLeftPixel - xPointToDataMap.startPoint; int xRightOffset = selectionRightPixel - xPointToDataMap.startPoint; if ((xLeftOffset < 0 && xRightOffset <0) || (xLeftOffset >= xPointToDataMap.pointToDataMap.length && xRightOffset >= xPointToDataMap.pointToDataMap.length)) { xIndexSelectionRange = null; } else { xLeftOffset = Math.max(0, xLeftOffset); xRightOffset = Math.min(xPointToDataMap.pointToDataMap.length, xRightOffset); xIndexSelectionRange = Ranges.range(xPointToDataMap.pointToDataMap[xLeftOffset], xPointToDataMap.pointToDataMap[xRightOffset]); } int yBottomOffset = selectionBottomPixel - yPointToDataMap.startPoint; int yTopOffset = selectionTopPixel - yPointToDataMap.startPoint; if ((yBottomOffset < 0 && yTopOffset <0) || (yBottomOffset >= yPointToDataMap.pointToDataMap.length && yTopOffset >= yPointToDataMap.pointToDataMap.length)) { yIndexSelectionRange = null; } else { yTopOffset = Math.max(0, yTopOffset); yBottomOffset = Math.min(xPointToDataMap.pointToDataMap.length, yBottomOffset); yIndexSelectionRange = Ranges.range(yPointToDataMap.pointToDataMap[yBottomOffset], yPointToDataMap.pointToDataMap[yTopOffset]); } g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setColor(Color.BLACK); graphBuffer.getGraphicsContext().drawRect(selectionLeftPixel, selectionTopPixel, selectionRightPixel - selectionLeftPixel, selectionBottomPixel - selectionTopPixel); } } IntensityGraph2DRenderer(int imageWidth, int imageHeight);  IntensityGraph2DRenderer(); @Override void update(IntensityGraph2DRendererUpdate update); void draw(GraphBuffer graphBuffer, Cell2DDataset data); @Override IntensityGraph2DRendererUpdate newUpdate(); boolean isDrawLegend(); NumberColorMap getColorMap(); Range getXIndexSelectionRange(); Range getYIndexSelectionRange(); Range getXValueSelectionRange(); Range getYValueSelectionRange(); Range getXPixelSelectionRange(); Range getYPixelSelectionRange(); static NumberColorMap DEFAULT_COLOR_MAP; static boolean DEFAULT_DRAW_LEGEND; public boolean useColorArray; }