I have a pretty basic line chart I'm using to plot some data on based on time. This is all working fine however the problem I need to address is when the plots along the time axes are very close.
Consider the following data points:
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-01T18:49:06"}
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-02T28:49:06"}
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-03T18:49:06"}
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-04T08:10:06"}
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-04T09:21:06"}
{ "Id": 101, x:15, y: 10, "OriginDt": "2012-12-04T11:32:06"}
For the first 3 points the chart looks fine but as soon as it gets to data that occurs within a short space of time the data starts to get bunched up and very hard to appreciate in the chart.
I've been trying to find a sample online that deals with something like this but haven't found it yet.
I've tried using the basic interpolation commands on the axes but these don't work.
How can I change my axes:
var yAxis = d3.svg.axis()
.tickSize(-width).tickPadding(10)
.scale(y)
.orient("left");
To "spread out" the points in these situations?
This would be a comment but I don't have the necessary reputation.
You might want to look into cartesian fisheye distortion
Related
I installed the Guna theme which brings a nice color scheme that I would like to keep; however, the theme comes with a clock and weather widget that I can't remove even if I set the theme back to default.
I have tried setting the layer where the clock texture is contained, to have zero opacity, but then the most I got it to do was showing the clock in a different color.
The following lines are in the Guna theme's default settings, starting at line 166:
{
"class": "sidebar_container",
"layer0.texture": "Guna/assets/simple/sidebar/sidebar-bg-clock-nb.png",
"layer0.inner_margin": [15, 55, 15, 0],
//"layer0.inner_margin": [15, 70, 15, 0],
//"layer0.inner_margin": [15, 92, 15, 0],
"layer0.tint": "color(var(--background))",
"layer0.opacity": 1,
"content_margin": [0, 45, 0, 0],
//"content_margin": [0, 60, 0, 0],
//"content_margin": [0, 82, 0, 0],
},
{
"class": "sidebar_container",
"settings": ["gnwidgx"],
"layer0.texture": "Guna/assets/simple/sidebar/sidebar-bg-nb.png",
"layer0.inner_margin": [15, 55, 15, 0],
"layer0.tint": "color(var(--background))",
"layer0.opacity": 1,
"content_margin": [0, 0, 0, 0]
}
I tried setting the content margin to [0,0] for the clock widget (like I've seen it's possible to do to hide file icons), like so:
{
"variables": {
},
"rules":
[
{
"class": "sidebar_container",
"content_margin": [0,0],
"layer0.opacity": 0
},
{
"class": "sidebar_container",
"content_margin": [0,0],
"layer1.opacity": 0
}
]
}
And the result is this: every sidebar element, including the files and folders, bugs out and leaves a trail as if I were shift+dragging everything in mspaint.
Thanks in advance!
Apparently Guna has a setting that adds the widgets (clock, weather, etc.) to all themes. Fortunately, it can be turned off. Select Preferences → Package Settings → Guna → Settings and add the following to the right pane:
"sidebar_widget_on_other_theme": false,
You can turn off the widgets in Guna itself with this setting:
"sidebar_widget": [],
Valid values for that array are empty (as above) or any combination of "clock", "weather", and "date".
Save the right pane when you're done, and the settings should be applied immediately. If not, you might need to restart Sublime.
I have a HandsOnTable with mergeCells option, on particular event I make a server call which gives me updated data and hence merge cells options also need to be updated.
For e.g. before server call, grouping was for every 5 rows, but after it's for 4 rows.
I used hot.updateSettings(hotOptions) in which mergeCells of hotOptions is updated, but it does not update the setting.
Before server call:
var hotOptions =
{
data: Handsontable.helper.createSpreadsheetData(5,5),
colWidths: [47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47],
rowHeaders: true,
colHeaders: true,
contextMenu: true,
mergeCells: [
{row: 0, col: 0, rowspan: 2, colspan: 2},
{row: 3, col: 3, rowspan: 2, colspan: 2}
]
};
hot = new Handsontable(container, hotOptions);
After server call:
hotOptions.mergeCells = [
{row: 0, col: 0, rowspan: 3, colspan: 3},
{row: 0, col: 3, rowspan: 2, colspan: 1}
];
//just to prove that data is updating
hotOptions.colWidths = [100, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47];
hot.updateSettings(hotOptions);
I can destroy earlier HOT instance and create new one with new options (attached fiddle does this), but I want to achieve the same with updateSettings.
More details: http://jsfiddle.net/ru53zo3o/1/
I think I have fixed this.
Just before calling updateSettings of the HOT instance, update its mergeCells attribute with the new instance of Handsontable.MergeCells object by passing updated mergeCells array as an attribute.
hotOptions.mergeCells = [{row: 0, col: 0, rowspan: 2, colspan: 3} ];
hot.mergeCells = new Handsontable.MergeCells(hotOptions.mergeCells);
hot.updateSettings(hotOptions);
See it working here: http://jsfiddle.net/gncb55jp/3/
In the meantime you could keep track of your "cells to merge" in an object array, then modify that array once you get the new data. Afterwards you can call render(). Definitely a workaround, but it will tide you over if you need to have it ready for a deadline of any kind while your waiting for the next release.
I have n columns of data that I would like to make D3 scatter plots from. It takes 2 columns to make a plot so n columns would end up n-permutations of 2 times of the same code that I would like to make a plot function from. Problem is I don't know how to set the variable in D3 fashion. An example of data and the snippet of code are bellow. I appreciate for any hint. Thanks.
// Potentially, there are a lot more columns.
var data = [
{"col1": 34, "col2": 54, "col3": 345, "col4": 35, "col5": 52},
{"col1": 75, "col2": 98, "col3": 917, "col4": 03, "col5": 47},
{"col1": 63, "col2": 23, "col3": 236, "col4": 34, "col5": 78},
{"col1": 23, "col2": 38, "col3": 198, "col4": 12, "col5": 18},
{"col1": 57, "col2": 48, "col3": 274, "col4": 67, "col5": 39},
{"col1": 65, "col2": 12, "col3": 381, "col4": 27, "col5": 45}
];
// The code is long
// I just list here the parts that are involved
// How to replace FOO and BAR with a pair of parameters "col1", "col2", etc ...
var x = d3.scale.linear().range([0, width]),
y = d3.scale.linear().range([height, 0]);
x.domain(d3.extent(data, function(q) {return q.FOO;}));
y.domain(d3.extent(data, function(q) {return q.BAR;}));
svg.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("r", 4)
.attr("cx", function(d) {return x(d.FOO);})
.attr("cy", function(d) {return y(d.BAR);})
.style('fill', 'blue');
EDIT:
I took a hint from mgold and make a function to rebuild the original dataset to a 2 columns dataset instead of a function of drawing scatter plot. It may not be elegant but just works. :) Thanks!
function get2Columns(foo, bar) {
var tempArr = [];
for (var i = 0; i < data.length; i++) {
tempArr.push({"FOO":data[i][foo],"BAR":data[i][bar]});
}
return tempArr;
}
data = get2Columns('col1', 'col2');
I'm not sure exactly what you're looking for, but I can try to talk about things that I think are relevant and hopefully give you some leads.
I would represent your data as an array of arrays, rather than an array of objects. This makes it much more amenable to array methods, from both vanilla JavaScript and D3. The transpose method may be especially useful, coupled with some mapping and reducing, for finding extents.
There are a handful of ways to choose two elements from an array or similar data structure. Zipping takes a pair of arrays and returns an array of pairs: the 0th items together, the 1st items together, and so on. Pairing takes one array and returns sequential pairs. Both of these have D3 implementations among those array methods.
Closer to what you want (maybe?) is the product of arrays, which given n arrays is every way to pick 1 item from each. This is typically represented as an array of arrays where the inner arrays have length n. There doesn't seem to be a D3 function to do this (I'd support adding one) but you can see this SO post. (No luck with Underscore either.)
But since you already have your matrix, maybe all you need to know is that functions like attr pass their second argument (when a function) not just the datum d but also the index i. You can also try using each and/or forEach to go from an array of values to individual values, keeping the indices distinct to get your 2D coordinate.
(On reread, the last paragraph is likely to be the most helpful.)
I'm very new to mongodb, I've done simple stuff like storing and retrieving documents.
I have a collection of documents (thousands and growing) with and embedded array of integers (can be as large as 5000 integers) between 0 and 255
Example Mongo Collection Data:
{
"name": "item1",
"values": [1, 93, 45, 67, 89, 1, 2, 32, 45]
},
{
"name": "item2",
"values": [1, 23, 45, 123, 1, 5, 89, 14, 22]
},
{
"name": "item3",
"values": [23, 1, 44, 78, 89, 22, 150, 23, 12]
},
{
"name": "item4",
"values": [90, 23, 11, 67, 29, 1, 2, 1, 45]
}
Comparison would be:
pseudo code:
distance = 0
for a in passed_in_item
for b in mongo_collection
distance += a - b
end
end
an example passed in array (same as the ones in the mongo document, they will always be the same length):
[1, 93, 45, 67, 89, 1, 2, 32, 45]
I'd like to pass in an array of integers as a query and difference it against the array in the document to find the one with the least difference. Is this the sort of thing map reduce is good at and how would I roughly go about it? An example would be great. Also eventually I'd like the passed in array to come from another document in Mongo in a different collection.
Thanks!
I am trying to construct a single column stacked bar chart with d3.js, my data array might look like this in some instances:
[{x: 0, y:1, y0: 0}, {x: 1, y: 10, y0: 1}, {x: 2, y:2, y0: 11}]
but in another instance it might look like this:
[{x: 0, y:20, y0: 0}, {x: 1, y: 300, y0: 20}, {x: 2, y:2189, y0: 320}]
I am having trouble with the log scale. The chart's height is always 150px and the rectangles for the stacked chart should not be smaller than 10px ever.