SankeyChart.java

  1. /*
  2.  * Copyright 2014 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.widgets.charts;

  20. import java.util.UUID;

  21. import org.apache.commons.lang3.builder.EqualsBuilder;
  22. import org.apache.commons.lang3.builder.HashCodeBuilder;

  23. import com.vaadin.annotations.JavaScript;
  24. import com.vaadin.ui.AbstractJavaScriptComponent;

  25. /**
  26.  * The Class SankeyChart.
  27.  */
  28. @JavaScript({ "https://www.gstatic.com/charts/loader.js", "SankeyChart.js" })
  29. public final class SankeyChart extends AbstractJavaScriptComponent {

  30.     /** The Constant serialVersionUID. */
  31.     private static final long serialVersionUID = 1L;

  32.     /** The my id. */
  33.     private String myId;

  34.     /**
  35.      * Instantiates a new sankey chart.
  36.      */
  37.     public SankeyChart() {
  38.         myId = "gBarChartComponent" + UUID.randomUUID().toString();
  39.         callFunction("setId", myId);
  40.         setSizeFull();
  41.         setHeight("100%");
  42.         setId(myId);
  43.         getState().myId=myId;
  44.     }

  45.     @Override
  46.     protected SankeyChartState getState() {
  47.         return (SankeyChartState) super.getState();
  48.     }

  49.     /**
  50.      * Adds the data row.
  51.      *
  52.      * @param from
  53.      *            the from
  54.      * @param to
  55.      *            the to
  56.      * @param weight
  57.      *            the weight
  58.      */
  59.     public void addDataRow(final String from, final String to, int weight) {
  60.         getState().addDataRow(from, to, weight);
  61.     }

  62.     /**
  63.      * Draw chart.
  64.      */
  65.     public void drawChart() {
  66.         callFunction("doDraw");
  67.     }

  68.     @Override
  69.     public int hashCode() {
  70.         return HashCodeBuilder.reflectionHashCode(this, false);
  71.     }

  72.     @Override
  73.     public boolean equals(Object obj) {
  74.         return EqualsBuilder.reflectionEquals(this, obj);
  75.     }

  76. }