forked from upstream-mirrors/OpenTracks
Share: removed Google's chart generator
This commit is contained in:
-75
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.apps.mytracks.util;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the Chart URL generator.
|
|
||||||
*
|
|
||||||
* @author Sandor Dornbush
|
|
||||||
*/
|
|
||||||
public class ChartURLGeneratorTest extends TestCase {
|
|
||||||
|
|
||||||
public void testgetChartUrl() {
|
|
||||||
Vector<Double> distances = new Vector<Double>();
|
|
||||||
Vector<Double> elevations = new Vector<Double>();
|
|
||||||
Track t = new Track();
|
|
||||||
TripStatistics stats = t.getTripStatistics();
|
|
||||||
stats.setMinElevation(0);
|
|
||||||
stats.setMaxElevation(2000);
|
|
||||||
stats.setTotalDistance(100);
|
|
||||||
|
|
||||||
distances.add(0.0);
|
|
||||||
elevations.add(10.0);
|
|
||||||
|
|
||||||
distances.add(10.0);
|
|
||||||
elevations.add(300.0);
|
|
||||||
|
|
||||||
distances.add(20.0);
|
|
||||||
elevations.add(800.0);
|
|
||||||
|
|
||||||
distances.add(50.0);
|
|
||||||
elevations.add(1900.0);
|
|
||||||
|
|
||||||
distances.add(75.0);
|
|
||||||
elevations.add(1200.0);
|
|
||||||
|
|
||||||
distances.add(90.0);
|
|
||||||
elevations.add(700.0);
|
|
||||||
|
|
||||||
distances.add(100.0);
|
|
||||||
elevations.add(70.0);
|
|
||||||
|
|
||||||
String chart = ChartURLGenerator.getChartUrl(distances,
|
|
||||||
elevations,
|
|
||||||
t,
|
|
||||||
"Title",
|
|
||||||
true);
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
"http://chart.apis.google.com/chart?&chs=600x350&cht=lxy&"
|
|
||||||
+ "chtt=Title&chxt=x,y&chxr=0,0,0,0|1,0.0,2100.0,300&chco=009A00&"
|
|
||||||
+ "chm=B,00AA00,0,0,0&chg=100000,14.285714285714286,1,0&"
|
|
||||||
+ "chd=e:AAGZMzf.v.5l..,ATJJYY55kkVVCI",
|
|
||||||
chart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.apps.mytracks.util;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A unit test for {@link ChartsExtendedEncoder}.
|
|
||||||
*
|
|
||||||
* @author Bartlomiej Niechwiej
|
|
||||||
*/
|
|
||||||
public class ChartsExtendedEncoderTest extends TestCase {
|
|
||||||
|
|
||||||
public void testGetEncodedValue_validArguments() {
|
|
||||||
// Valid arguments.
|
|
||||||
assertEquals("AK", ChartsExtendedEncoder.getEncodedValue(10));
|
|
||||||
assertEquals("JO", ChartsExtendedEncoder.getEncodedValue(590));
|
|
||||||
assertEquals("AA", ChartsExtendedEncoder.getEncodedValue(0));
|
|
||||||
// 64^2 = 4096.
|
|
||||||
assertEquals("..", ChartsExtendedEncoder.getEncodedValue(4095));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetEncodedValue_invalidArguments() {
|
|
||||||
// Invalid arguments.
|
|
||||||
assertEquals("__", ChartsExtendedEncoder.getEncodedValue(4096));
|
|
||||||
assertEquals("__", ChartsExtendedEncoder.getEncodedValue(1234564096));
|
|
||||||
assertEquals("__", ChartsExtendedEncoder.getEncodedValue(-10));
|
|
||||||
assertEquals("__", ChartsExtendedEncoder.getEncodedValue(-12324435));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetSeparator() {
|
|
||||||
assertEquals(",", ChartsExtendedEncoder.getSeparator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-7
@@ -20,7 +20,6 @@ import android.content.Context;
|
|||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.apps.mytracks.util.ChartURLGenerator;
|
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
@@ -65,12 +64,6 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
|||||||
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
|
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
|
||||||
builder.append(generateTripStatisticsDescription(track.getTripStatistics(), html));
|
builder.append(generateTripStatisticsDescription(track.getTripStatistics(), html));
|
||||||
|
|
||||||
// Elevation chart
|
|
||||||
if (html && distances != null && elevations != null) {
|
|
||||||
builder.append("<img border=\"0\" src=\""
|
|
||||||
+ ChartURLGenerator.getChartUrl(distances, elevations, track, context) + "\"/>");
|
|
||||||
builder.append(HTML_LINE_BREAK);
|
|
||||||
}
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.android.apps.mytracks.util;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class will generate google chart server url's.
|
|
||||||
*
|
|
||||||
* @author Sandor Dornbush
|
|
||||||
*/
|
|
||||||
public class ChartURLGenerator {
|
|
||||||
|
|
||||||
private static final String CHARTS_BASE_URL = "http://chart.apis.google.com/chart?";
|
|
||||||
|
|
||||||
private ChartURLGenerator() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a chart of a track.
|
|
||||||
*
|
|
||||||
* @param distances An array of distance measurements
|
|
||||||
* @param elevations A matching array of elevation measurements
|
|
||||||
* @param track The track for this chart
|
|
||||||
* @param context The current appplication context
|
|
||||||
*/
|
|
||||||
public static String getChartUrl(
|
|
||||||
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
|
|
||||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
|
||||||
return getChartUrl(
|
|
||||||
distances, elevations, track, context.getString(R.string.stats_elevation), metricUnits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a chart of a track. This form is for testing without contexts.
|
|
||||||
*
|
|
||||||
* @param distances An array of distance measurements
|
|
||||||
* @param elevations A matching array of elevation measurements
|
|
||||||
* @param track The track for this chart
|
|
||||||
* @param title The title for the chart
|
|
||||||
* @param metricUnits Should the data be displayed in metric units
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
static String getChartUrl(Vector<Double> distances, Vector<Double> elevations, Track track,
|
|
||||||
String title, boolean metricUnits) {
|
|
||||||
if (distances == null || elevations == null || track == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (distances.size() != elevations.size()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Round it up.
|
|
||||||
TripStatistics tripStatistics = track.getTripStatistics();
|
|
||||||
double effectiveMaxY = tripStatistics.getMaxElevation();
|
|
||||||
if (!metricUnits) {
|
|
||||||
effectiveMaxY *= UnitConversions.M_TO_FT;
|
|
||||||
}
|
|
||||||
effectiveMaxY = ((int) (effectiveMaxY / 100)) * 100 + 100;
|
|
||||||
|
|
||||||
// Round it down.
|
|
||||||
double effectiveMinY = tripStatistics.getMinElevation();
|
|
||||||
if (!metricUnits) {
|
|
||||||
effectiveMinY *= UnitConversions.M_TO_FT;
|
|
||||||
}
|
|
||||||
effectiveMinY = ((int) (effectiveMinY / 100)) * 100;
|
|
||||||
if (tripStatistics.getMinElevation() < 0) {
|
|
||||||
effectiveMinY -= 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ySpread = effectiveMaxY - effectiveMinY;
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(CHARTS_BASE_URL);
|
|
||||||
sb.append("&chs=600x350");
|
|
||||||
sb.append("&cht=lxy");
|
|
||||||
|
|
||||||
// Title
|
|
||||||
sb.append("&chtt=");
|
|
||||||
sb.append(title);
|
|
||||||
|
|
||||||
// Labels
|
|
||||||
sb.append("&chxt=x,y");
|
|
||||||
double totalDistance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
|
||||||
if (!metricUnits) {
|
|
||||||
totalDistance *= UnitConversions.KM_TO_MI;
|
|
||||||
}
|
|
||||||
int xInterval = ((int) (totalDistance / 6));
|
|
||||||
int yInterval = ((int) (ySpread / 600)) * 100;
|
|
||||||
if (yInterval < 100) {
|
|
||||||
yInterval = 25;
|
|
||||||
}
|
|
||||||
// Range
|
|
||||||
sb.append("&chxr=0,0,");
|
|
||||||
sb.append((int) totalDistance);
|
|
||||||
sb.append(',');
|
|
||||||
sb.append(xInterval);
|
|
||||||
|
|
||||||
sb.append("|1,");
|
|
||||||
sb.append(effectiveMinY);
|
|
||||||
sb.append(',');
|
|
||||||
sb.append(effectiveMaxY);
|
|
||||||
sb.append(',');
|
|
||||||
sb.append(yInterval);
|
|
||||||
|
|
||||||
// Line color
|
|
||||||
sb.append("&chco=009A00");
|
|
||||||
|
|
||||||
// Fill
|
|
||||||
sb.append("&chm=B,00AA00,0,0,0");
|
|
||||||
|
|
||||||
// Grid lines
|
|
||||||
double desiredGrids = ySpread / yInterval;
|
|
||||||
sb.append("&chg=100000,");
|
|
||||||
sb.append(100.0 / desiredGrids);
|
|
||||||
sb.append(",1,0");
|
|
||||||
|
|
||||||
// Data
|
|
||||||
sb.append("&chd=e:");
|
|
||||||
for (int i = 0; i < distances.size(); i++) {
|
|
||||||
int normalized = (int) (getNormalizedDistance(distances.elementAt(i), track) * 4095);
|
|
||||||
sb.append(ChartsExtendedEncoder.getEncodedValue(normalized));
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(ChartsExtendedEncoder.getSeparator());
|
|
||||||
for (int i = 0; i < elevations.size(); i++) {
|
|
||||||
double value = elevations.elementAt(i);
|
|
||||||
if (!metricUnits) {
|
|
||||||
value *= UnitConversions.M_TO_FT;
|
|
||||||
}
|
|
||||||
int normalized = (int) (getNormalizedElevation(value, effectiveMinY, ySpread) * 4095);
|
|
||||||
sb.append(ChartsExtendedEncoder.getEncodedValue(normalized));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double getNormalizedDistance(double value, Track track) {
|
|
||||||
return value / track.getTripStatistics().getTotalDistance();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double getNormalizedElevation(double value, double effectiveMinY, double ySpread) {
|
|
||||||
return (value - effectiveMinY) / ySpread;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.apps.mytracks.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The singleton class representing the extended encoding of chart data.
|
|
||||||
*/
|
|
||||||
public class ChartsExtendedEncoder {
|
|
||||||
|
|
||||||
// ChartServer data encoding in extended mode
|
|
||||||
private static final String CHARTSERVER_EXTENDED_ENCODING_SEPARATOR = ",";
|
|
||||||
private static final String CHARTSERVER_EXTENDED_ENCODING =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
|
|
||||||
private static final int CHARTSERVER_EXTENDED_SINGLE_CHARACTER_VALUES =
|
|
||||||
CHARTSERVER_EXTENDED_ENCODING.length();
|
|
||||||
private static final String MISSING_POINT_EXTENDED_ENCODING = "__";
|
|
||||||
|
|
||||||
private ChartsExtendedEncoder() { }
|
|
||||||
|
|
||||||
public static String getEncodedValue(int scaled) {
|
|
||||||
int index1 = scaled / CHARTSERVER_EXTENDED_SINGLE_CHARACTER_VALUES;
|
|
||||||
if (index1 < 0 || index1 >= CHARTSERVER_EXTENDED_SINGLE_CHARACTER_VALUES) {
|
|
||||||
return MISSING_POINT_EXTENDED_ENCODING;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index2 = scaled % CHARTSERVER_EXTENDED_SINGLE_CHARACTER_VALUES;
|
|
||||||
if (index2 < 0 || index2 >= CHARTSERVER_EXTENDED_SINGLE_CHARACTER_VALUES) {
|
|
||||||
return MISSING_POINT_EXTENDED_ENCODING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.valueOf(CHARTSERVER_EXTENDED_ENCODING.charAt(index1))
|
|
||||||
+ String.valueOf(CHARTSERVER_EXTENDED_ENCODING.charAt(index2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSeparator() {
|
|
||||||
return CHARTSERVER_EXTENDED_ENCODING_SEPARATOR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user