示例#1
0
 private void assertColorPalettes(final OrdinalScale scale, final String colorString) {
   String[] expectedColors = colorString.split(" ");
   int i = 0;
   for (String color : expectedColors) {
     assertEquals(color, scale.apply(i++).asString());
   }
 }
示例#2
0
  @Override
  public void doTest(final ComplexPanel sandbox) {

    // new ordinal scale is undefined
    assertTrue(D3.scale.ordinal().apply(10).isUndefined());

    testColorPalettes();

    // copy
    OrdinalScale ordinal = D3.scale.ordinal();
    ordinal.domain(1, 2);
    OrdinalScale copy = ordinal.copy();
    copy.domain(2, 3);
    assertEquals(1.0, ordinal.domain().getNumber(0));
    assertEquals(2.0, ordinal.domain().getNumber(1));

    OrdinalScale scale = D3.scale.ordinal();
    scale.domain((byte) 0, (byte) 10);
    scale.domain(0f, 10f);
    scale.domain(0d, 10d);
    scale.domain(0, 10);
    scale.domain(0l, 10l);
    scale.domain((short) 0, (short) 10);
    scale.domain("0", "10");

    // range
    scale.range((byte) 1, (byte) 2, (byte) 3);
    scale.range(1d, 2d, 3d);
    scale.range(1f, 2f, 3f);
    scale.range(1, 2, 3);
    scale.range(1l, 2l, 3l);
    scale.range((short) 1, (short) 2, (short) 3);
    scale.range("1", "2");
    scale.range();
    // range round
    scale.rangeBands(0, 100);
    scale.rangeBands(0, 100, 0.5);
    scale.rangeBands(0, 100, 0.5, 0.6);

    scale.rangePoints(50, 60, 1);
    scale.rangePoints(50, 60);

    scale.rangeRoundBands(0, 100);
    scale.rangeRoundBands(0, 100, 0.5);
    scale.rangeRoundBands(0, 100, 0.5, 0.6);

    scale.rangeExtent();

    scale.rangeBand();

    // behaviour

    OrdinalScale ordinal2 = D3.scale.ordinal().rangeBands(0, 1000, 0.1, 0.1);
    ordinal2.domain("01/01", "01/02", "01/03", "01/04", "01/05");

    System.out.println(ordinal2.apply("01/01").asInt());
    System.out.println(ordinal2.apply("01/02").asInt());
    System.out.println(ordinal2.apply("01/03").asInt());
    System.out.println(ordinal2.apply("01/04").asInt());
    System.out.println(ordinal2.apply("01/05").asInt());
    System.out.println(ordinal2.rangeBand());

    assertEquals(19, ordinal2.apply("01/01").asInt());
    assertEquals(215, ordinal2.apply("01/02").asInt());
    assertEquals(411, ordinal2.apply("01/03").asInt());
    assertEquals(607, ordinal2.apply("01/04").asInt());
    assertEquals(803, ordinal2.apply("01/05").asInt());

    assertEquals(176.47, ordinal2.rangeBand(), 0.005);
  }