LineChart extends AnimatedComponent { public void configure(@NotNull RangedContinuousSeries series, @NotNull LineConfig config) { myLinesConfig.put(series, config); } @VisibleForTesting  LineChart(@NotNull LineChartModel model, @NotNull LineChartReducer reducer);  LineChart(@NotNull LineChartModel model);  LineChart(@NotNull List<RangedContinuousSeries> data); void configure(@NotNull RangedContinuousSeries series, @NotNull LineConfig config); void addCustomRenderer(@NotNull LineChartCustomRenderer renderer); @NotNull LineConfig getLineConfig(RangedContinuousSeries rangedContinuousSeries); static void drawLine(@NotNull Graphics2D g2d,
                              @NotNull Path2D path,
                              @NotNull LineConfig config); void setShowMaxLine(boolean showMaxLine); void setMaxLineColor(@NotNull Color maxLineColor); void setMaxLineMargin(int maxLineMargin); void setRenderOffset(int xOffset, int yOffset); void setTopPadding(int padding); void setFillEndGap(boolean fillEndGap);  }
@Test public void testAdjustDashPhase() { LineChartModel model = new LineChartModel(); Range xRange = new Range(0, 15); Range yRange = new Range(0, 15); DefaultDataSeries<Long> testSeries = new DefaultDataSeries<>(); testSeries.add(3, 0L); testSeries.add(3, 3L); testSeries.add(6, 7L); testSeries.add(9, 11L); testSeries.add(15, 15L); RangedContinuousSeries rangedSeries = new RangedContinuousSeries("test", xRange, yRange, testSeries); model.add(rangedSeries); LineChart chart = new LineChart(model); chart.setSize(15, 15); BasicStroke stroke = new BasicStroke(1f, CAP_SQUARE, JOIN_MITER, 10.0f, new float[]{1.0f, 2.0f}, 0.0f); LineConfig config = new LineConfig(Color.BLACK).setStroke(stroke); chart.configure(rangedSeries, config); Assert.assertTrue(config.isAdjustDash()); Assert.assertEquals(3, config.getDashLength(), 0); Assert.assertEquals(0, config.getAdjustedDashPhase(), 0); Graphics2D fakeGraphics = mock(Graphics2D.class); when(fakeGraphics.create()).thenReturn(fakeGraphics); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 0); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(2, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(1, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(2, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 8); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -8); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); }
@Test public void testAdjustDashPhaseForSteppedConfig() throws Exception { LineChartModel model = new LineChartModel(); Range xRange = new Range(0, 15); Range yRange = new Range(0, 15); DefaultDataSeries<Long> testSeries = new DefaultDataSeries<>(); testSeries.add(3, 0L); testSeries.add(3, 3L); testSeries.add(6, 7L); testSeries.add(9, 11L); testSeries.add(15, 15L); RangedContinuousSeries rangedSeries = new RangedContinuousSeries("test", xRange, yRange, testSeries); model.add(rangedSeries); LineChart chart = new LineChart(model); chart.setSize(15, 15); BasicStroke stroke = new BasicStroke(1f, CAP_SQUARE, JOIN_MITER, 10.0f, new float[]{1.0f, 2.0f}, 0.0f); LineConfig config = new LineConfig(Color.BLACK).setStroke(stroke).setStepped(true); chart.configure(rangedSeries, config); Assert.assertTrue(config.isAdjustDash()); Assert.assertEquals(3, config.getDashLength(), 0); Assert.assertEquals(0, config.getAdjustedDashPhase(), 0); Graphics2D fakeGraphics = mock(Graphics2D.class); when(fakeGraphics.create()).thenReturn(fakeGraphics); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 0); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(1, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 4); Assert.assertEquals(2, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(1, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -4); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, 8); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); shiftRangeAndRepaintChart(chart, model, xRange, fakeGraphics, -8); Assert.assertEquals(0, config.getAdjustedDashPhase(), LineChart.EPSILON); }
@Test public void testStackedConfigsDoNotModifyUnderlyingDataSeries() { final int dataCount = 10; LineChartModel model = new LineChartModel(); DefaultDataSeries<Long> series1 = new DefaultDataSeries<>(); DefaultDataSeries<Long> series2 = new DefaultDataSeries<>(); for (int i = 0; i <= dataCount; i++) { series1.add(i, (long)i); series2.add(i, (long)i); } RangedContinuousSeries rangedSeries1 = new RangedContinuousSeries("series1", new Range(0, dataCount), new Range(0, 0), series1); RangedContinuousSeries rangedSeries2 = new RangedContinuousSeries("series2", new Range(0, dataCount), new Range(0, 0), series2); model.add(rangedSeries1); model.add(rangedSeries2); LineChart chart = new LineChart(model); chart.configure(rangedSeries1, new LineConfig(Color.BLACK).setStacked(true)); chart.configure(rangedSeries2, new LineConfig(Color.WHITE).setStacked(true)); model.update(TimeUnit.SECONDS.toNanos(1)); chart.setSize(100, 100); Graphics2D fakeGraphics = mock(Graphics2D.class); when(fakeGraphics.create()).thenReturn(fakeGraphics); chart.paint(fakeGraphics); for (int i = 0; i < dataCount; i++) { assertThat(series1.getY(i)).isEqualTo(i); assertThat(series2.getY(i)).isEqualTo(i); } }