-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
* Add data random generator to the demo project * Rebuild demo project in gh-pages folder
- Loading branch information
There are no files selected for viewing
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
1528713D7407FF13820C8F50520D85A2.cache.js | ||
232191D8E66FED5F01011B2E300163D8.cache.js | ||
user.agent ie8 | ||
|
||
42651C5509F904C2E001E8ABBC3342CF.cache.js | ||
user.agent ie10 | ||
|
||
54FF3BFC4D9EDCBC344F95EAE556EA69.cache.js | ||
user.agent safari | ||
|
||
4DE01F3CE42C8756A13A68194A001D30.cache.js | ||
73904F0A3D64960DA7B41CA0CD41001A.cache.js | ||
user.agent ie9 | ||
|
||
64291DDFF50D6FA97222882E09D6E3BE.cache.js | ||
91713A0D428598BBCDC3015D9FFF8323.cache.js | ||
user.agent gecko1_8 | ||
|
||
6CD98EF82D73C964F00189C66B6ACC8D.cache.js | ||
user.agent ie8 | ||
|
||
D254F627D8BB96446B19E3E929E44274.cache.js | ||
user.agent ie10 | ||
|
||
Devmode:devmode.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pl.itrack.leafletd3demo.client; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
import java.util.stream.IntStream; | ||
|
||
/** | ||
* A simple data generator using D3 JavaScript library. | ||
* The JsInterop was used to map required suff to be accessible from Java. | ||
* (JsInterop technique description: | ||
* http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJsInterop.html | ||
* https://docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit#) | ||
* <p> | ||
* The mapping implementation way inspired from: | ||
* https://github.com/gwtd3/gwt-d3/blob/master/gwt-d3-api/src/main/java/com/github/gwtd3/api/core/Random.java | ||
* and https://npm.runkit.com/d3-random | ||
* <p> | ||
* Alternatively I could simply use the `gwt-d3` library, but just a very small piece was needed. | ||
*/ | ||
@JsType | ||
class DataGenerator { | ||
|
||
private static final int NUMBER_OF_ITEMS = 1000; | ||
private static final int DEFAULT_DEVIATION = 1; | ||
|
||
static double[][] generateCoordinates(double centerLatitude, double centerLongitude) { | ||
return IntStream.range(0, NUMBER_OF_ITEMS) | ||
.mapToObj(i -> new double[]{ | ||
D3.randomNormal(centerLongitude, DEFAULT_DEVIATION).generate(), | ||
D3.randomNormal(centerLatitude, DEFAULT_DEVIATION).generate()}) | ||
.toArray(double[][]::new); | ||
} | ||
|
||
/* | ||
Below is the mapping to enable possibility of calling the native JavaScript stuff like below: | ||
var d3 = require("d3-random"); | ||
var latFn = d3.randomNormal(52.233333, 1); | ||
latFn(); | ||
PS: It's kind of a stub for D3 wrapper library, but the one already exists: https://github.com/gwtd3/gwt-d3. | ||
The `gwt-d3` is a bit old-fashioned and doesn't use JsInterop. It is at least GWT 2.8 compatible, | ||
what is good and beneficial, so still an option to be considered. | ||
*/ | ||
|
||
/** | ||
* The mapping to access d3.randomNormal() JavaScript function | ||
*/ | ||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "d3") | ||
public static class D3 { | ||
|
||
@JsFunction | ||
@FunctionalInterface | ||
public interface Random { | ||
double generate(); | ||
} | ||
|
||
/** | ||
* Returns a function for generating random number with a | ||
* <a href="http://en.wikipedia.org/wiki/Normal_distribution">normal (Gaussian) distribution</a>, | ||
* with the given mean, and the given deviation. | ||
* | ||
* @param expectation the mean of the distribution | ||
* @param deviation the standard deviation | ||
* @return the generator | ||
*/ | ||
public static native Random randomNormal(double expectation, double deviation); | ||
} | ||
} |
Large diffs are not rendered by default.