I'm just starting out on some ember.js, and am pretty inexperienced. This is probably a very simple question to answer but I can't seem to get it to work. I'm in the controller for my chart trying to set range using
range: function() {
var dataArr = this.get("rawData");
if (!dataArr) return;
var range = "";
var xmax = -1 * Infinity;
var xmin = Infinity;
var ymax = -1 * Infinity;
var ymin = Infinity;
code to figure out xmin, max etc......
lowerBound = new Date(xmin)
upperBound = new Date(xmax)
range = d3.time.format.utc("%a, %b%e %-I:%M %p")(lowerBound) + " - " + d3.time.format.utc("%a, %b%e %-I:%M %p")(upperBound);
return range
}.observes('display', 'rawData'),
I then try to use this with handlebars {{range}} and it does not work... I dont know if I'm providing enough info but if anyone can help out its much appreciated, thank you!
You need to identify your range property as a property, thusly:
range: function() {
var dataArr = this.get("rawData");
// blah blah, your implementation
return range;
}.property('rawData'),
By specifying rawData as a dependency, Ember will automatically recompute range if rawData changes.
Related
I am developing the nearest Food Dish application location. I managed to display it based on the location closest to the user, using this plugin great_circle_distance
I want to know how to set the max radius? ex. < 30 Km
Here my code:
_foodByCategories.sort((a, b) {
var distance1 = new GreatCircleDistance.fromDegrees(
latitude1:
model.userLocation == null ? 0.0 : model.userLocation["latitude"],
longitude1: model.userLocation == null
? 0.0
: model.userLocation["longitude"],
latitude2: a.lat,
longitude2: a.long);
double totaldistance1 = distance1.haversineDistance();
var distance2 = new GreatCircleDistance.fromDegrees(
latitude1:
model.userLocation == null ? 0.0 : model.userLocation["latitude"],
longitude1: model.userLocation == null
? 0.0
: model.userLocation["longitude"],
latitude2: b.lat,
longitude2: b.long);
double totaldistance2 = distance2.haversineDistance();
return (totaldistance1 - totaldistance2).toInt();
});
Any answer will appreciated.
If I understand your question correct
_foodByCategories.where((a) {
var distance = new GreatCircleDistance.fromDegrees(latitude1: double.parse(widget.lat), longitude1: double.parse(widget.lng), latitude2: double.parse(a.lat), longitude2: double.parse(a.lng));
var totaldistance = distance.haversineDistance().toStringAsFixed(2);
double distanceDouble1 = double.parse(totaldistance);
return distance <= 30000; // or something like that
}).sort ... // and your sorting code
I can't see any way to do this within the package you are using. You could suggest to the developer to add this functionality in?
Alternatively, you are getting the total distance in your code so you could just do a simple if statement to check if the total distance is greater than your set max radius.
I've been tasked with implementing a Normal Distribution graph. I was wondering if Chart.js offers this functionality right out of the box or if I will need to extend it. The graph in question is here
Thank you
It is unfortunately not possible with Chart.js, except if you create it by yourself.
But, I found a library called ChartNew.js (Github) that provides a lot of functionalities that are not available on Chart.js :
Chart.js has been completely rewritten since ChartNew.js has been developed; Both code are now completely different. Most of the functionalities inserted in the new version of Chart.js are also available in ChartNew.js
And this library provides a Gaussian Function (also called Normal Distribution) :
To do it, take a look at the sample given in the Github.
I'm sure it will suit you if you change some data.
This Implementation has been done using React. The functions below can still be used in other programming languages built on top of Javascript.
The only two inputs required to plot a Normal Distribution curve will be Mean and Standard deviation
Defining states for mean and standard deviation & states for X and Y arrays
const [bellMean, setBellMean] = useState<number>(12.2036); //example
const [bellStdev, setBellStdev] = useState<number>(0.0008); //example
const [bellXValues, setBellXValues] = useState<(number)[]>([]);
const [bellYValues, setBellYValues] = useState<(number | null)[]>([]);
To Get X values for bell curve (if not using react can get rid of useEffect)
useEffect(() => {
// defining chart limits between which the graph will be plotted
let lcl = bellMean - bellStdev * 6;
let ucl = bellMean + bellStdev * 6;
let ticks = [lcl];
let steps = 100; // steps corresponds to the size of the output array
let stepSize = Math.round(((ucl - lcl) / steps) * 10000) / 10000;
let tickVal = lcl;
for (let i = 0; i <= steps; i++) {
ticks.push(Math.round(tickVal * 10000) / 10000); // rounding off to 4 decimal places
tickVal = tickVal + stepSize;
}
setBellXValues(ticks); //array for X values
}, [bellMean, bellStdev]);
To Get Y values for Bell curve (if not using react can get rid of useEffect)
useEffect(() => {
// Using PDF function from vega-statistics instead of importing the whole library
const densityNormal = (value: number, mean: number, stdev: number) => {
const SQRT2PI = Math.sqrt(2 * Math.PI);
stdev = (stdev == null) ? 1 : stdev;
const z = (value - (mean || 0)) / stdev;
return Math.exp(-0.5 * z * z) / (stdev * SQRT2PI);
};
let YValues = bellXValues.map((item: number) => {
if (bellMean === null || bellStdev === undefined) {
return null;
} else {
const pdfValue = densityNormal(item, bellMean, bellStdev);
return pdfValue === Infinity ? null : pdfValue;
}
});
setBellYValues(YValues); // array for Y values
}, [bellXValues]);
The arrays for X and Y can be fed to labels and data props of chartjs as it is.
I followed this tutorial in the mapnik github wiki to make a world map: https://github.com/mapnik/mapnik/wiki/GettingStartedInPython
I modified this example, and have now embedded the code into a Pyside Qt Widget. My question now is, how does one plot points on this map using x and y coordinates, or latitude and longitude points?
Here is the code I'm using to generate the map and to embed it in the widget:
import mapnik
m = mapnik.Map(1200,600)
m.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer(mapnik.Color('#f2eff9'))
r.symbols.append(polygon_symbolizer)
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('rgb(50%,50%,50%)'),0.1)
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('My Style',s)
ds = mapnik.Shapefile(file='/home/lee/shapefiles/ne_110m_admin_0_countries.shp')
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('My Style')
m.layers.append(layer)
m.zoom_all()
im = mapnik.Image(1200,600)
mapnik.render(m, im)
qim = QImage()
qim.loadFromData(QByteArray(im.tostring('png')))
label = QLabel(self)
label.setPixmap(QPixmap.fromImage(qim))
self.layout.addWidget(label)
Usually, you would connect your map to a datasource such as a PostGIS or SQLite database and let mapnik populate the points from said database, similar to something like this. Either in a python script or generated from xml.
However, in answer to your question, you could plot Lat/Lon points by creating a new Feature from a WKT string and adding that feature to a mapnik.MemoryDatasource().
Below is a simple snippet from a script using the mapfile found here
First we create our style and add it to our map:
s = mapnik.Style() # style object to hold rules
r = mapnik.Rule() # rule object to hold symbolizers
point_sym = mapnik.PointSymbolizer()
point_sym.filename = './symbols/airport.p.16.png'
r.symbols.append(point_sym) # add the symbolizer to the rule object
s.rules.append(r)
m.append_style('airport point', s)
Now we create our data source and add a Point geometry in WKT format:
ds = mapnik.MemoryDatasource()
f = mapnik.Feature(mapnik.Context(), 1)
f.add_geometries_from_wkt("POINT(-92.289595 34.746481)")
ds.add_feature(f)
Now we must create a new layer, add our style that we created, and add the layer to our map:
player = mapnik.Layer('airport_layer')
#since our map is mercator but you wanted to add lat lon points
#we must make sure our layer projection is set to lat lon
player.srs = longlat.params()
player.datasource = ds
player.styles.append('airport point')
m.layers.append(player)
m.zoom_all()
You can look at the entire script here.
If you need to get a geographic coordinate(ie:lat/lon) from the pixel coordinate, you probably need to add your converter functions.
The Google Maps JS code is as follow could perhaps help :
https://developers.google.com/maps/documentation/javascript/examples/map-coordinates
var TILE_SIZE = 256;
function bound(value, opt_min, opt_max) {
if (opt_min != null) value = Math.max(value, opt_min);
if (opt_max != null) value = Math.min(value, opt_max);
return value;
}
function degreesToRadians(deg) {
return deg * (Math.PI / 180);
}
function radiansToDegrees(rad) {
return rad / (Math.PI / 180);
}
/** #constructor */
function MercatorProjection() {
this.pixelOrigin_ = new google.maps.Point(TILE_SIZE / 2,
TILE_SIZE / 2);
this.pixelsPerLonDegree_ = TILE_SIZE / 360;
this.pixelsPerLonRadian_ = TILE_SIZE / (2 * Math.PI);
}
MercatorProjection.prototype.fromLatLngToPoint = function(latLng,
opt_point) {
var me = this;
var point = opt_point || new google.maps.Point(0, 0);
var origin = me.pixelOrigin_;
point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_;
// Truncating to 0.9999 effectively limits latitude to 89.189. This is
// about a third of a tile past the edge of the world tile.
var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999,
0.9999);
point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) *
-me.pixelsPerLonRadian_;
return point;
};
MercatorProjection.prototype.fromPointToLatLng = function(point) {
var me = this;
var origin = me.pixelOrigin_;
var lng = (point.x - origin.x) / me.pixelsPerLonDegree_;
var latRadians = (point.y - origin.y) / -me.pixelsPerLonRadian_;
var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) -
Math.PI / 2);
return new google.maps.LatLng(lat, lng);
};
I have a Visualisation table with server side constructed JSON.When I try to use color formatting based on cell value, it applies for particular only. I need to apply color for complete row based on the single cell value.
For Example,
C1 C2 C3 C4
R1 - - - 0 // This row should be "red"
R2 - - - 1 // This row should be "green"
R3 - - - 0
R4 - - - 1
But the color applies for C4 only.
MyCode :
var dataTable = new google.visualization.DataTable(data, 0.5);
var formatter_short1 = new google.visualization.DateFormat({pattern:'h:mm aa'});
formatter_short1.format(dataTable,1);
formatter_short1.format(dataTable,2);
var view = new google.visualization.DataView(dataTable);
view.hideColumns([0,3,4,5,8,9,14]);
var color_formatter = new google.visualization.ColorFormat();
color_formatter.addRange(0,1, 'green', 'orange');
color_formatter.addRange(1,null, 'orange', 'green');
//color_formatter.format(dataTable, 1,2,6,7,9,11,12,13); // Apply formatter to 10 column
color_formatter.format(dataTable, 10); // Apply formatter to 10 column
I didn't find answer on this question, so I'll post my solution for this old question here.
Looks like Google doesn't support such behaviour out of box, but you can achieve it with custom formatter. This one works in my case:
function RowColorFormat() {
var colorFormat = new google.visualization.ColorFormat();
this.addRange = function(from, to, color, bgcolor) {
colorFormat.addRange(from, to, color, bgcolor);
};
this.addGradientRange = function(from, to, color, fromBgColor, toBgColor) {
colorFormat.addGradientRange(from, to, color, bgcolor);
};
this.format = function(dataTable, column) {
dataTable.setPropertyOverriden = dataTable.setProperty;
dataTable.setProperty = function (row, column, name, value) {
var length = this.getNumberOfColumns();
for (var i = 0; i < length; i++) {
this.setPropertyOverriden(row, i, name, value);
}
};
colorFormat.format(dataTable, column);
dataTable.setProperty = dataTable.setPropertyOverriden;
delete dataTable.setPropertyOverriden;
};
}
and use it like google.visualization.ColorFormat
I build my action for create image thumbs, and I want add to the end of action auto rotate to my thumb.
My question is: How add rotate with random angle from -45 to 45 degree?
You can rotate an image automatically via an Adobe Script:
if (!app.documents.length > 0) {
alert("No active document");
}
else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) {
docRef.rotateCanvas(90);
}
}
Random numbers can be generated with:
this.rawValue = Math.random() * (45 - 1) + 1;
I've not done enough Adobe Script to tell you how to put this all together, but I'm sure you are clever enough!
Helpful site: http://www.photoshopsupport.com/tutorials/jennifer/photoshop-scripts.html
Enjoi!
Sorry for another answer, I didn't want to make my other one massive and unreadable.
I have attempted (VERY BADLY) the script (and, for the record, it's not been tested or anything and I'm not great at this)
if (!app.documents.length > 0) {
alert("No active document"); //no document?! whats happening?!
} else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) { //if width is greater than height
PlusMinus.rawValue = Math.random() * (2 - 1) + 1; //GET 1 OR 2
if (PlusMinus.rawValue == 1) {
deLimit = "-"; //set minus if its a 1
} else {
deLimit = "+"; //set plus if its a 2
}
Angles.rawValue = Math.random() * (45 - 1) + 1; //GET NUMBER FROM 1-45
docRef.rotateCanvas(deLimit+Angles);
}
}
I'm sure you will get the idea from that!