PageRenderTime 32ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/googlecode/charts4j/example/MapChartExample.java

http://charts4j.googlecode.com/
Java | 124 lines | 82 code | 11 blank | 31 comment | 0 complexity | 872f043dcdd2227238a9b641e4cb01ff MD5 | raw file
  1/**
  2 *
  3 * The MIT License
  4 *
  5 * Copyright (c) 2011 the original author or authors.
  6 *
  7 * Permission is hereby granted, free of charge, to any person obtaining a copy
  8 * of this software and associated documentation files (the "Software"), to deal
  9 * in the Software without restriction, including without limitation the rights
 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11 * copies of the Software, and to permit persons to whom the Software is
 12 * furnished to do so, subject to the following conditions:
 13
 14 * The above copyright notice and this permission notice shall be included in
 15 * all copies or substantial portions of the Software.
 16
 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23 * THE SOFTWARE.
 24 */
 25
 26package com.googlecode.charts4j.example;
 27
 28import static com.googlecode.charts4j.Color.*;
 29import static com.googlecode.charts4j.USAState.Code.*;
 30import static com.googlecode.charts4j.UrlUtil.normalize;
 31import static org.junit.Assert.assertEquals;
 32
 33import java.util.logging.Level;
 34import java.util.logging.Logger;
 35
 36import org.junit.BeforeClass;
 37import org.junit.Test;
 38
 39import com.googlecode.charts4j.Fills;
 40import com.googlecode.charts4j.GCharts;
 41import com.googlecode.charts4j.GeographicalArea;
 42import com.googlecode.charts4j.MapChart;
 43import com.googlecode.charts4j.PoliticalBoundary;
 44import com.googlecode.charts4j.USAState;
 45
 46/**
 47 *
 48 * @author Julien Chastang (julien.c.chastang at gmail dot com)
 49 */
 50public class MapChartExample {
 51
 52    @BeforeClass
 53    public static void setUpBeforeClass() throws Exception {
 54        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
 55    }
 56
 57    @Test
 58    public void example1() {
 59        // EXAMPLE CODE START
 60        MapChart chart = GCharts.newMapChart(GeographicalArea.USA);
 61
 62        PoliticalBoundary al = new USAState( AL, 10);
 63        PoliticalBoundary ak = new USAState( AK, 10);
 64        PoliticalBoundary az = new USAState( AZ, 10);
 65        PoliticalBoundary ar = new USAState( AR, 10);
 66        PoliticalBoundary ca = new USAState( CA, 90);
 67        PoliticalBoundary co = new USAState( CO, 50);
 68        PoliticalBoundary ct = new USAState( CT, 90);
 69        PoliticalBoundary de = new USAState( DE, 90);
 70        PoliticalBoundary fl = new USAState( FL, 50);
 71        PoliticalBoundary ga = new USAState( GA, 10);
 72        PoliticalBoundary hi = new USAState( HI, 90);
 73        PoliticalBoundary id = new USAState( ID, 10);
 74        PoliticalBoundary il = new USAState( IL, 90);
 75        PoliticalBoundary in = new USAState( IN, 50);
 76        PoliticalBoundary ia = new USAState( IA, 50);
 77        PoliticalBoundary ks = new USAState( KS, 10);
 78        PoliticalBoundary ky = new USAState( KY, 10);
 79        PoliticalBoundary la = new USAState( LA, 10);
 80        PoliticalBoundary me = new USAState( ME, 50);
 81        PoliticalBoundary md = new USAState( MD, 90);
 82        PoliticalBoundary ma = new USAState( MA, 90);
 83        PoliticalBoundary mi = new USAState( MI, 90);
 84        PoliticalBoundary mn = new USAState( MN, 90);
 85        PoliticalBoundary ms = new USAState( MS, 10);
 86        PoliticalBoundary mo = new USAState( MO, 10);
 87        PoliticalBoundary mt = new USAState( MT, 90);
 88        PoliticalBoundary ne = new USAState( NE, 10);
 89        PoliticalBoundary nv = new USAState( NV, 90);
 90        PoliticalBoundary nh = new USAState( NH, 90);
 91        PoliticalBoundary nj = new USAState( NJ, 90);
 92        PoliticalBoundary nm = new USAState( NM, 50);
 93        PoliticalBoundary ny = new USAState( NY, 90);
 94        PoliticalBoundary nc = new USAState( NC, 50);
 95        PoliticalBoundary nd = new USAState( ND, 90);
 96        PoliticalBoundary oh = new USAState( OH, 90);
 97        PoliticalBoundary ok = new USAState( OK, 10);
 98        PoliticalBoundary or = new USAState( OR, 90);
 99        PoliticalBoundary pa = new USAState( PA, 50);
100        PoliticalBoundary ri = new USAState( RI, 90);
101        PoliticalBoundary sc = new USAState( SC, 50);
102        PoliticalBoundary sd = new USAState( SD, 10);
103        PoliticalBoundary tn = new USAState( TN, 10);
104        PoliticalBoundary tx = new USAState( TX, 10);
105        PoliticalBoundary ut = new USAState( UT, 10);
106        PoliticalBoundary vt = new USAState( VT, 90);
107        PoliticalBoundary va = new USAState( VA, 50);
108        PoliticalBoundary wa = new USAState( WA, 90);
109        PoliticalBoundary wv = new USAState( WV, 10);
110        PoliticalBoundary wi = new USAState( WI, 90);
111        PoliticalBoundary wy = new USAState( WY, 10);
112
113        chart.addPoliticalBoundaries(al,ak,az,ar,ca,co,ct,de,fl,ga,hi,id,il,in,ia,ks,ky,la,me,md,ma,mi,mn,ms,mo,mt,ne,nv,nh,nj,nm,ny,nc,nd,oh,ok,or,pa,ri,sc,sd,tn,tx,ut,vt,va,wa,wv,wi,wy);
114        chart.setColorGradient(WHITE, RED, BLUE);
115        chart.setBackgroundFill(Fills.newSolidFill(ALICEBLUE));
116        String url = chart.toURLString();
117        // EXAMPLE CODE END. Use this url string in your web or
118        // Internet application.
119
120        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(url);
121        String expectedString = "http://chart.apis.google.com/chart?chf=bg,s,F0F8FF&chs=440x220&chd=e:GaGaGaGa5mgA5m5mgAGa5mGa5mgAgAGaGaGagA5m5m5m5mGaGa5mGa5m5m5mgA5mgA5m5mGa5mgA5mgAGaGaGaGa5mgA5mGa5mGa&chtm=usa&chco=FFFFFF,FF0000,0000FF&chld=ALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKORPARISCSDTNTXUTVTVAWAWVWIWY&cht=t";
122        assertEquals("Junit error", normalize(expectedString), normalize(url));
123    }
124}