Issue with updating d3 interactive matrix scatterplot to v4 - scatter-plot
I'm trying to improve my skills with D3.js by updating various v3 scripts I'm interested in to v4, but I got stuck while trying to "port" the interactive scatterplot matrix that Mike Bostok posted here: https://bl.ocks.org/mbostock/4063663
While I've ported with no problem the static version of the code (with no brush), when trying to implement the brush in the same fashion as in v3, I have found an issue that seems an actual D3 problem more than being related to my D3 noob-ness: brush seems to stick on the wrong cell on the scatterplot matrix!
In particular, if I remove the brushmove part and I just log to console the quantities p.i and p.j (which identify which cell in the scatterplot matrix we are brushing on), I got a stuck i = 3 index.
var width = 960,
size = 230,
padding = 20;
var x = d3.scaleLinear()
.range([padding / 2, size - padding / 2]);
var y = d3.scaleLinear()
.range([size - padding / 2, padding / 2]);
var xAxis = d3.axisBottom()
.scale(x)
.ticks(6);
var yAxis = d3.axisLeft()
.scale(y)
.ticks(6);
var color = d3.scaleOrdinal(d3.schemeCategory10);
//d3.csv("flowers.csv", function(error, data) {
// if (error) throw error;
data = iris;
var domainByTrait = {},
traits = d3.keys(data[0]).filter(function(d) { return d !== "species"; }),
n = traits.length;
traits.forEach(function(trait) {
domainByTrait[trait] = d3.extent(data, function(d) { return d[trait]; });
});
xAxis.tickSize(size * n);
yAxis.tickSize(-size * n);
var brush = d3.brush()
.on("start", brushstart)
.on("brush", brushmove)
.on("end", brushend);
var svg = d3.select("body").append("svg")
.attr("width", size * n + padding)
.attr("height", size * n + padding)
.append("g")
.attr("transform", "translate(" + padding + "," + padding / 2 + ")");
svg.selectAll(".x.axis")
.data(traits)
.enter().append("g")
.attr("class", "x axis")
.attr("transform", function(d, i) { return "translate(" + (n - i - 1) * size + ",0)"; })
.each(function(d) { x.domain(domainByTrait[d]); d3.select(this).call(xAxis); });
svg.selectAll(".y.axis")
.data(traits)
.enter().append("g")
.attr("class", "y axis")
.attr("transform", function(d, i) { return "translate(0," + i * size + ")"; })
.each(function(d) { y.domain(domainByTrait[d]); d3.select(this).call(yAxis); });
var cell = svg.selectAll(".cell")
.data(cross(traits, traits))
.enter().append("g")
.attr("class", "cell")
.attr("transform", function(d) { return "translate(" + (n - d.i - 1) * size + "," + d.j * size + ")"; })
.each(plot);
// Titles for the diagonal.
cell.filter(function(d) { return d.i === d.j; }).append("text")
.attr("x", padding)
.attr("y", padding)
.attr("dy", ".71em")
.text(function(d) { return d.x; });
cell.call(brush);
function plot(p) {
var cell = d3.select(this);
x.domain(domainByTrait[p.x]);
y.domain(domainByTrait[p.y]);
cell.append("rect")
.attr("class", "frame")
.attr("x", padding / 2)
.attr("y", padding / 2)
.attr("width", size - padding)
.attr("height", size - padding);
cell.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", function(d) { return x(d[p.x]); })
.attr("cy", function(d) { return y(d[p.y]); })
.attr("r", 4)
.style("fill", function(d) { return color(d.species); });
}
var brushCell;
// Clear the previously-active brush, if any.
function brushstart(p) {
if (brushCell !== this) {
d3.select(brushCell).call(brush.move, null);
x.domain(domainByTrait[p.x]);
y.domain(domainByTrait[p.y]);
brushCell = this;
}
}
// Highlight the selected circles.
function brushmove(p) {
// ??
console.log(p.i +" " + p.j)
}
// If the brush is empty, select all circles.
function brushend(p) {
if (!d3.event.selection) svg.selectAll(".hidden").classed("hidden", false);
}
//});
function cross(a, b) {
var c = [], n = a.length, m = b.length, i, j;
for (i = -1; ++i < n;) for (j = -1; ++j < m;) c.push({x: a[i], i: i, y: b[j], j: j});
return c;
}
The code is up for review at JSFiddle as well together with the iris object: https://jsfiddle.net/fabio_p/pmpjawmm/
Notice that the variable brushcell defined in function brushstart is the wrong one as well (suggesting that it's the "this" passed to the brush functions to be wrong)
Even weirder (at least to my unexperienced eyes), things seem to go in a better way if I change the order in which I add cells, as you can see at this other fiddle: https://jsfiddle.net/fabio_p/7pf4cqrg/
Here I just changed indexes at line 220 (and for scale consistency at line 206), and the index i is not stuck anymore at 3...
Any insights about what I'm doing wrong or where is D3 going wrong?
No problems with d3, you just have two minor problems in your code.
1) The move from v3 to v4 (as noted in the CHANGELOG) added the .extent() method for denoting the selection area. The default extent falls back to the size of the svg. If you look at each of your overlay objects they are the size of the entire svg document, that is what is causing your indexing to be wonky. The simple fix is to set the extent,
var brush = d3.brush()
.on("start", brushstart)
.on("brush", brushmove)
.on("end", brushend)
.extent([[0, 0], [size, size]]);
Now when you do your selections, the area is again limited to each graph and they have the correct indexes.
Problem 2)
Due to the change from using a scale to using coordinates, you need to translate the absolute coordinate within the selection to your scale, as noted in the change log linked above, this can be done using .invert() on the defined scales.
// Highlight the selected circles.
function brushmove(p) {
if(d3.event.selection){
var e = d3.event.selection;
svg.selectAll("circle").classed("hidden", function(d) {
return x.invert(e[0][0]) > d[p.x] || x.invert(e[1][0]) < d[p.x]
|| y.invert(e[0][1]) < d[p.y] || y.invert(e[1][1]) > d[p.y];
});
}
}
Putting these two fixes in gets us back to the correct functionality,
iris = [{
"sepal.length": "5.1",
"sepal.width": "3.5",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.9",
"sepal.width": "3",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.7",
"sepal.width": "3.2",
"petal.length": "1.3",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.6",
"sepal.width": "3.1",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.6",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.9",
"sepal.width": "3.1",
"petal.length": "1.5",
"petal.width": "0.1",
"species": "setosa"
}, {
"sepal.length": "5.4",
"sepal.width": "3.7",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.8",
"sepal.width": "3.4",
"petal.length": "1.6",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.8",
"sepal.width": "3",
"petal.length": "1.4",
"petal.width": "0.1",
"species": "setosa"
}, {
"sepal.length": "4.3",
"sepal.width": "3",
"petal.length": "1.1",
"petal.width": "0.1",
"species": "setosa"
}, {
"sepal.length": "5.8",
"sepal.width": "4",
"petal.length": "1.2",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.7",
"sepal.width": "4.4",
"petal.length": "1.5",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "5.4",
"sepal.width": "3.9",
"petal.length": "1.3",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.5",
"petal.length": "1.4",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "5.7",
"sepal.width": "3.8",
"petal.length": "1.7",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.8",
"petal.length": "1.5",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "5.4",
"sepal.width": "3.4",
"petal.length": "1.7",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.7",
"petal.length": "1.5",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "4.6",
"sepal.width": "3.6",
"petal.length": "1",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.3",
"petal.length": "1.7",
"petal.width": "0.5",
"species": "setosa"
}, {
"sepal.length": "4.8",
"sepal.width": "3.4",
"petal.length": "1.9",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3",
"petal.length": "1.6",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.4",
"petal.length": "1.6",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "5.2",
"sepal.width": "3.5",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.2",
"sepal.width": "3.4",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.7",
"sepal.width": "3.2",
"petal.length": "1.6",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.8",
"sepal.width": "3.1",
"petal.length": "1.6",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.4",
"sepal.width": "3.4",
"petal.length": "1.5",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "5.2",
"sepal.width": "4.1",
"petal.length": "1.5",
"petal.width": "0.1",
"species": "setosa"
}, {
"sepal.length": "5.5",
"sepal.width": "4.2",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.9",
"sepal.width": "3.1",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.2",
"petal.length": "1.2",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.5",
"sepal.width": "3.5",
"petal.length": "1.3",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.9",
"sepal.width": "3.6",
"petal.length": "1.4",
"petal.width": "0.1",
"species": "setosa"
}, {
"sepal.length": "4.4",
"sepal.width": "3",
"petal.length": "1.3",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.4",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.5",
"petal.length": "1.3",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "4.5",
"sepal.width": "2.3",
"petal.length": "1.3",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "4.4",
"sepal.width": "3.2",
"petal.length": "1.3",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.5",
"petal.length": "1.6",
"petal.width": "0.6",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.8",
"petal.length": "1.9",
"petal.width": "0.4",
"species": "setosa"
}, {
"sepal.length": "4.8",
"sepal.width": "3",
"petal.length": "1.4",
"petal.width": "0.3",
"species": "setosa"
}, {
"sepal.length": "5.1",
"sepal.width": "3.8",
"petal.length": "1.6",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "4.6",
"sepal.width": "3.2",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5.3",
"sepal.width": "3.7",
"petal.length": "1.5",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "5",
"sepal.width": "3.3",
"petal.length": "1.4",
"petal.width": "0.2",
"species": "setosa"
}, {
"sepal.length": "7",
"sepal.width": "3.2",
"petal.length": "4.7",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "6.4",
"sepal.width": "3.2",
"petal.length": "4.5",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "6.9",
"sepal.width": "3.1",
"petal.length": "4.9",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "5.5",
"sepal.width": "2.3",
"petal.length": "4",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.5",
"sepal.width": "2.8",
"petal.length": "4.6",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "5.7",
"sepal.width": "2.8",
"petal.length": "4.5",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.3",
"sepal.width": "3.3",
"petal.length": "4.7",
"petal.width": "1.6",
"species": "versicolor"
}, {
"sepal.length": "4.9",
"sepal.width": "2.4",
"petal.length": "3.3",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "6.6",
"sepal.width": "2.9",
"petal.length": "4.6",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.2",
"sepal.width": "2.7",
"petal.length": "3.9",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "5",
"sepal.width": "2",
"petal.length": "3.5",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "5.9",
"sepal.width": "3",
"petal.length": "4.2",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "6",
"sepal.width": "2.2",
"petal.length": "4",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "6.1",
"sepal.width": "2.9",
"petal.length": "4.7",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "5.6",
"sepal.width": "2.9",
"petal.length": "3.6",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.7",
"sepal.width": "3.1",
"petal.length": "4.4",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "5.6",
"sepal.width": "3",
"petal.length": "4.5",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "5.8",
"sepal.width": "2.7",
"petal.length": "4.1",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "6.2",
"sepal.width": "2.2",
"petal.length": "4.5",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "5.6",
"sepal.width": "2.5",
"petal.length": "3.9",
"petal.width": "1.1",
"species": "versicolor"
}, {
"sepal.length": "5.9",
"sepal.width": "3.2",
"petal.length": "4.8",
"petal.width": "1.8",
"species": "versicolor"
}, {
"sepal.length": "6.1",
"sepal.width": "2.8",
"petal.length": "4",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.3",
"sepal.width": "2.5",
"petal.length": "4.9",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "6.1",
"sepal.width": "2.8",
"petal.length": "4.7",
"petal.width": "1.2",
"species": "versicolor"
}, {
"sepal.length": "6.4",
"sepal.width": "2.9",
"petal.length": "4.3",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.6",
"sepal.width": "3",
"petal.length": "4.4",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "6.8",
"sepal.width": "2.8",
"petal.length": "4.8",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "6.7",
"sepal.width": "3",
"petal.length": "5",
"petal.width": "1.7",
"species": "versicolor"
}, {
"sepal.length": "6",
"sepal.width": "2.9",
"petal.length": "4.5",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "5.7",
"sepal.width": "2.6",
"petal.length": "3.5",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "5.5",
"sepal.width": "2.4",
"petal.length": "3.8",
"petal.width": "1.1",
"species": "versicolor"
}, {
"sepal.length": "5.5",
"sepal.width": "2.4",
"petal.length": "3.7",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "5.8",
"sepal.width": "2.7",
"petal.length": "3.9",
"petal.width": "1.2",
"species": "versicolor"
}, {
"sepal.length": "6",
"sepal.width": "2.7",
"petal.length": "5.1",
"petal.width": "1.6",
"species": "versicolor"
}, {
"sepal.length": "5.4",
"sepal.width": "3",
"petal.length": "4.5",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "6",
"sepal.width": "3.4",
"petal.length": "4.5",
"petal.width": "1.6",
"species": "versicolor"
}, {
"sepal.length": "6.7",
"sepal.width": "3.1",
"petal.length": "4.7",
"petal.width": "1.5",
"species": "versicolor"
}, {
"sepal.length": "6.3",
"sepal.width": "2.3",
"petal.length": "4.4",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.6",
"sepal.width": "3",
"petal.length": "4.1",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.5",
"sepal.width": "2.5",
"petal.length": "4",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.5",
"sepal.width": "2.6",
"petal.length": "4.4",
"petal.width": "1.2",
"species": "versicolor"
}, {
"sepal.length": "6.1",
"sepal.width": "3",
"petal.length": "4.6",
"petal.width": "1.4",
"species": "versicolor"
}, {
"sepal.length": "5.8",
"sepal.width": "2.6",
"petal.length": "4",
"petal.width": "1.2",
"species": "versicolor"
}, {
"sepal.length": "5",
"sepal.width": "2.3",
"petal.length": "3.3",
"petal.width": "1",
"species": "versicolor"
}, {
"sepal.length": "5.6",
"sepal.width": "2.7",
"petal.length": "4.2",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.7",
"sepal.width": "3",
"petal.length": "4.2",
"petal.width": "1.2",
"species": "versicolor"
}, {
"sepal.length": "5.7",
"sepal.width": "2.9",
"petal.length": "4.2",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.2",
"sepal.width": "2.9",
"petal.length": "4.3",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "5.1",
"sepal.width": "2.5",
"petal.length": "3",
"petal.width": "1.1",
"species": "versicolor"
}, {
"sepal.length": "5.7",
"sepal.width": "2.8",
"petal.length": "4.1",
"petal.width": "1.3",
"species": "versicolor"
}, {
"sepal.length": "6.3",
"sepal.width": "3.3",
"petal.length": "6",
"petal.width": "2.5",
"species": "virginica"
}, {
"sepal.length": "5.8",
"sepal.width": "2.7",
"petal.length": "5.1",
"petal.width": "1.9",
"species": "virginica"
}, {
"sepal.length": "7.1",
"sepal.width": "3",
"petal.length": "5.9",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "6.3",
"sepal.width": "2.9",
"petal.length": "5.6",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.5",
"sepal.width": "3",
"petal.length": "5.8",
"petal.width": "2.2",
"species": "virginica"
}, {
"sepal.length": "7.6",
"sepal.width": "3",
"petal.length": "6.6",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "4.9",
"sepal.width": "2.5",
"petal.length": "4.5",
"petal.width": "1.7",
"species": "virginica"
}, {
"sepal.length": "7.3",
"sepal.width": "2.9",
"petal.length": "6.3",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.7",
"sepal.width": "2.5",
"petal.length": "5.8",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "7.2",
"sepal.width": "3.6",
"petal.length": "6.1",
"petal.width": "2.5",
"species": "virginica"
}, {
"sepal.length": "6.5",
"sepal.width": "3.2",
"petal.length": "5.1",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "6.4",
"sepal.width": "2.7",
"petal.length": "5.3",
"petal.width": "1.9",
"species": "virginica"
}, {
"sepal.length": "6.8",
"sepal.width": "3",
"petal.length": "5.5",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "5.7",
"sepal.width": "2.5",
"petal.length": "5",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "5.8",
"sepal.width": "2.8",
"petal.length": "5.1",
"petal.width": "2.4",
"species": "virginica"
}, {
"sepal.length": "6.4",
"sepal.width": "3.2",
"petal.length": "5.3",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "6.5",
"sepal.width": "3",
"petal.length": "5.5",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "7.7",
"sepal.width": "3.8",
"petal.length": "6.7",
"petal.width": "2.2",
"species": "virginica"
}, {
"sepal.length": "7.7",
"sepal.width": "2.6",
"petal.length": "6.9",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "6",
"sepal.width": "2.2",
"petal.length": "5",
"petal.width": "1.5",
"species": "virginica"
}, {
"sepal.length": "6.9",
"sepal.width": "3.2",
"petal.length": "5.7",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "5.6",
"sepal.width": "2.8",
"petal.length": "4.9",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "7.7",
"sepal.width": "2.8",
"petal.length": "6.7",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "6.3",
"sepal.width": "2.7",
"petal.length": "4.9",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.7",
"sepal.width": "3.3",
"petal.length": "5.7",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "7.2",
"sepal.width": "3.2",
"petal.length": "6",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.2",
"sepal.width": "2.8",
"petal.length": "4.8",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.1",
"sepal.width": "3",
"petal.length": "4.9",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.4",
"sepal.width": "2.8",
"petal.length": "5.6",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "7.2",
"sepal.width": "3",
"petal.length": "5.8",
"petal.width": "1.6",
"species": "virginica"
}, {
"sepal.length": "7.4",
"sepal.width": "2.8",
"petal.length": "6.1",
"petal.width": "1.9",
"species": "virginica"
}, {
"sepal.length": "7.9",
"sepal.width": "3.8",
"petal.length": "6.4",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "6.4",
"sepal.width": "2.8",
"petal.length": "5.6",
"petal.width": "2.2",
"species": "virginica"
}, {
"sepal.length": "6.3",
"sepal.width": "2.8",
"petal.length": "5.1",
"petal.width": "1.5",
"species": "virginica"
}, {
"sepal.length": "6.1",
"sepal.width": "2.6",
"petal.length": "5.6",
"petal.width": "1.4",
"species": "virginica"
}, {
"sepal.length": "7.7",
"sepal.width": "3",
"petal.length": "6.1",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "6.3",
"sepal.width": "3.4",
"petal.length": "5.6",
"petal.width": "2.4",
"species": "virginica"
}, {
"sepal.length": "6.4",
"sepal.width": "3.1",
"petal.length": "5.5",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6",
"sepal.width": "3",
"petal.length": "4.8",
"petal.width": "1.8",
"species": "virginica"
}, {
"sepal.length": "6.9",
"sepal.width": "3.1",
"petal.length": "5.4",
"petal.width": "2.1",
"species": "virginica"
}, {
"sepal.length": "6.7",
"sepal.width": "3.1",
"petal.length": "5.6",
"petal.width": "2.4",
"species": "virginica"
}, {
"sepal.length": "6.9",
"sepal.width": "3.1",
"petal.length": "5.1",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "5.8",
"sepal.width": "2.7",
"petal.length": "5.1",
"petal.width": "1.9",
"species": "virginica"
}, {
"sepal.length": "6.8",
"sepal.width": "3.2",
"petal.length": "5.9",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "6.7",
"sepal.width": "3.3",
"petal.length": "5.7",
"petal.width": "2.5",
"species": "virginica"
}, {
"sepal.length": "6.7",
"sepal.width": "3",
"petal.length": "5.2",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "6.3",
"sepal.width": "2.5",
"petal.length": "5",
"petal.width": "1.9",
"species": "virginica"
}, {
"sepal.length": "6.5",
"sepal.width": "3",
"petal.length": "5.2",
"petal.width": "2",
"species": "virginica"
}, {
"sepal.length": "6.2",
"sepal.width": "3.4",
"petal.length": "5.4",
"petal.width": "2.3",
"species": "virginica"
}, {
"sepal.length": "5.9",
"sepal.width": "3",
"petal.length": "5.1",
"petal.width": "1.8",
"species": "virginica"
}];
var width = 960,
size = 230,
padding = 20;
var x = d3.scaleLinear()
.range([padding / 2, size - padding / 2]);
var y = d3.scaleLinear()
.range([size - padding / 2, padding / 2]);
var xAxis = d3.axisBottom()
.scale(x)
.ticks(6);
var yAxis = d3.axisLeft()
.scale(y)
.ticks(6);
var color = d3.scaleOrdinal(d3.schemeCategory10);
//d3.csv("flowers.csv", function(error, data) {
// if (error) throw error;
data = iris;
var domainByTrait = {},
traits = d3.keys(data[0]).filter(function(d) {
return d !== "species";
}),
n = traits.length;
traits.forEach(function(trait) {
domainByTrait[trait] = d3.extent(data, function(d) {
return d[trait];
});
});
xAxis.tickSize(size * n);
yAxis.tickSize(-size * n);
var brush = d3.brush()
.on("start", brushstart)
.on("brush", brushmove)
.on("end", brushend)
.extent([
[0, 0],
[size, size]
]);
var svg = d3.select("body").append("svg")
.attr("width", size * n + padding)
.attr("height", size * n + padding)
.append("g")
.attr("transform", "translate(" + padding + "," + padding / 2 + ")");
svg.selectAll(".x.axis")
.data(traits)
.enter().append("g")
.attr("class", "x axis")
.attr("transform", function(d, i) {
return "translate(" + (n - i - 1) * size + ",0)";
})
.each(function(d) {
x.domain(domainByTrait[d]);
d3.select(this).call(xAxis);
});
svg.selectAll(".y.axis")
.data(traits)
.enter().append("g")
.attr("class", "y axis")
.attr("transform", function(d, i) {
return "translate(0," + i * size + ")";
})
.each(function(d) {
y.domain(domainByTrait[d]);
d3.select(this).call(yAxis);
});
var cell = svg.selectAll(".cell")
.data(cross(traits, traits))
.enter().append("g")
.attr("class", "cell")
.attr("transform", function(d) {
return "translate(" + (n - d.i - 1) * size + "," + d.j * size + ")";
})
.each(plot);
// Titles for the diagonal.
cell.filter(function(d) {
return d.i === d.j;
}).append("text")
.attr("x", padding)
.attr("y", padding)
.attr("dy", ".71em")
.text(function(d) {
return d.x;
});
cell.call(brush);
//console.log(traits.map(function(d) { return domainByTrait[d];}));
function plot(p) {
var cell = d3.select(this);
x.domain(domainByTrait[p.x]);
y.domain(domainByTrait[p.y]);
cell.append("rect")
.attr("class", "frame")
.attr("x", padding / 2)
.attr("y", padding / 2)
.attr("width", size - padding)
.attr("height", size - padding);
cell.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", function(d) {
return x(d[p.x]);
})
.attr("cy", function(d) {
return y(d[p.y]);
})
.attr("r", 4)
.style("fill", function(d) {
return color(d.species);
});
}
var brushCell;
// Clear the previously-active brush, if any.
function brushstart(p) {
if (brushCell !== this) {
d3.select(brushCell).call(brush.move, null);
x.domain(domainByTrait[p.x]);
y.domain(domainByTrait[p.y]);
brushCell = this;
}
}
// Highlight the selected circles.
function brushmove(p) {
if (d3.event.selection) {
var e = d3.event.selection;
svg.selectAll("circle").classed("hidden", function(d) {
return x.invert(e[0][0]) > d[p.x] || x.invert(e[1][0]) < d[p.x] || y.invert(e[0][1]) < d[p.y] || y.invert(e[1][1]) > d[p.y];
});
}
}
// If the brush is empty, select all circles.
function brushend(p) {
if (!d3.event.selection) svg.selectAll(".hidden").classed("hidden", false);
}
//});
function cross(a, b) {
var c = [],
n = a.length,
m = b.length,
i, j;
for (i = -1; ++i < n;)
for (j = -1; ++j < m;) c.push({
x: a[i],
i: i,
y: b[j],
j: j
});
return c;
}
svg {
font: 10px sans-serif;
padding: 10px;
}
.axis,
.frame {
shape-rendering: crispEdges;
}
.axis line {
stroke: #ddd;
}
.axis path {
display: none;
}
.cell text {
font-weight: bold;
text-transform: capitalize;
}
.frame {
fill: none;
stroke: #aaa;
}
circle {
fill-opacity: .7;
}
circle.hidden {
fill: #ccc !important;
}
.extent {
fill: #000;
fill-opacity: .125;
stroke: #fff;
}
<!DOCTYPE html>
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
</body>
Related
Elsa Document Approval Workflow (using VIsual Designer) always return 400
I am following Elsa Workflow tutorial here: https://elsa-workflows.github.io/elsa-core/docs/next/guides/guides-document-approval#document-approval-workflow-visual-designer I am using the docker version, which should be the latest. But whenever I sent a POST request using postman, it always returns 400. I believe I am following the tutorial exactly as described. The workflow isn't being triggered at all..., I suspect http://localhost:13000/v2/documents is not the correct url. Here is what I have designed. This is what I POST using Postman. This is the exported workflow definition. { "$id": "1", "definitionId": "94e1b452fe8e4239aeff1cf779a65329", "versionId": "cb2fbcfe31c44875b6f82b01ef477ea9", "name": "VisualDocumentApprovalWorkflow", "displayName": "Visual Document Approval Workflow", "version": 3, "variables": { "$id": "2", "data": {} }, "customAttributes": { "$id": "3", "data": {} }, "isSingleton": false, "persistenceBehavior": "WorkflowBurst", "deleteCompletedInstances": false, "isPublished": true, "isLatest": true, "createdAt": "2022-11-23T08:43:45.6472218Z", "activities": [ { "$id": "4", "activityId": "b1d82194-6a6b-4568-adde-382b16027c93", "type": "HttpEndpoint", "displayName": "HTTP Endpoint", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "5", "name": "Path", "expressions": { "$id": "6", "Literal": "/v2/documents/" } }, { "$id": "7", "name": "Methods", "expressions": { "$id": "8", "Json": "[\"POST\"]" } }, { "$id": "9", "name": "ReadContent", "expressions": { "$id": "10", "Literal": "true" } }, { "$id": "11", "name": "TargetType", "expressions": { "$id": "12" } }, { "$id": "13", "name": "Schema", "syntax": "Literal", "expressions": { "$id": "14", "Literal": "" } }, { "$id": "15", "name": "Authorize", "expressions": { "$id": "16", "Literal": "false" } }, { "$id": "17", "name": "Policy", "expressions": { "$id": "18", "Literal": "adaa" } } ], "propertyStorageProviders": { "$id": "19" } }, { "$id": "20", "activityId": "2e7f8800-d49f-4485-b47b-0c9f3cb82a48", "type": "SetVariable", "displayName": "Set Variable", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "21", "name": "VariableName", "expressions": { "$id": "22", "Literal": "Document" } }, { "$id": "23", "name": "Value", "syntax": "JavaScript", "expressions": { "$id": "24", "Literal": "input.Body", "JavaScript": "input.Body" } } ], "propertyStorageProviders": { "$id": "25" } }, { "$id": "26", "activityId": "b10ffb0d-c9ae-439a-86fa-b4351294666d", "type": "SendEmail", "displayName": "Send Email", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "27", "name": "From", "expressions": { "$id": "28", "Literal": "workflow#acme.com" } }, { "$id": "29", "name": "To", "expressions": { "$id": "30", "Json": "[\"josh#acme.com\"]" } }, { "$id": "31", "name": "Subject", "syntax": "Liquid", "expressions": { "$id": "32", "Literal": "Document received from {{Variables.Document.Author.Name}}", "Liquid": "Document received from {{Variables.Document.Author.Name}}" } }, { "$id": "33", "name": "Attachments", "expressions": { "$id": "34" } }, { "$id": "35", "name": "Body", "expressions": { "$id": "36", "Literal": "Document from {{ Variables.Document.Author.Name }} received for review.<br>Approve or Reject" } }, { "$id": "37", "name": "Cc", "expressions": { "$id": "38" } }, { "$id": "39", "name": "Bcc", "expressions": { "$id": "40" } } ], "propertyStorageProviders": { "$id": "41" } }, { "$id": "42", "activityId": "90942864-bd26-4309-82fd-51f27b8e3615", "type": "WriteHttpResponse", "displayName": "HTTP Response", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "43", "name": "Content", "expressions": { "$id": "44", "Literal": "<h1>Request for Approval Sent</h1><p>Your document has been received and will be reviewed shortly.</p>" } }, { "$id": "45", "name": "ContentType", "expressions": { "$id": "46", "Literal": "text/html" } }, { "$id": "47", "name": "StatusCode", "expressions": { "$id": "48", "Literal": "OK" } }, { "$id": "49", "name": "CharSet", "expressions": { "$id": "50", "Literal": "" } }, { "$id": "51", "name": "ResponseHeaders", "expressions": { "$id": "52" } } ], "propertyStorageProviders": { "$id": "53" } }, { "$id": "54", "activityId": "c62c8ff0-db76-4dea-b1a6-6cc138415b17", "type": "Fork", "displayName": "Fork", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "55", "name": "Branches", "expressions": { "$id": "56", "Json": "[\"Approve\",\"Reject\",\"Remind\"]" } } ], "propertyStorageProviders": { "$id": "57" } }, { "$id": "58", "activityId": "aa201fb5-a50f-44b1-989f-7a7b57b3b52d", "type": "SignalReceived", "displayName": "Signal Received", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "59", "name": "Signal", "expressions": { "$id": "60", "Literal": "Approve" } } ], "propertyStorageProviders": { "$id": "61" } }, { "$id": "62", "activityId": "615f0e0d-9f7a-4a2f-ab9e-97b3bea10cbe", "type": "SendEmail", "displayName": "Send Email", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "63", "name": "From", "expressions": { "$id": "64", "Literal": "workflow#acme.com" } }, { "$id": "65", "name": "To", "syntax": "JavaScript", "expressions": { "$id": "66", "Json": "[\"[Document.Author.Email]\"]", "JavaScript": "[Document.Author.Email]" } }, { "$id": "67", "name": "Subject", "syntax": "Liquid", "expressions": { "$id": "68", "Liquid": "Document {{ Variables.Document.Id }} Approved!" } }, { "$id": "69", "name": "Attachments", "expressions": { "$id": "70" } }, { "$id": "71", "name": "Body", "syntax": "Liquid", "expressions": { "$id": "72", "Liquid": "Great job {{ Variables.Document.Author.Name }}, that document is perfect." } }, { "$id": "73", "name": "Cc", "expressions": { "$id": "74" } }, { "$id": "75", "name": "Bcc", "expressions": { "$id": "76" } } ], "propertyStorageProviders": { "$id": "77" } }, { "$id": "78", "activityId": "af52dae7-254b-4602-be35-0c0ef23a4ba5", "type": "SignalReceived", "displayName": "Signal Received", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "79", "name": "Signal", "expressions": { "$id": "80", "Literal": "Reject" } } ], "propertyStorageProviders": { "$id": "81" } }, { "$id": "82", "activityId": "ce2c17ff-cb9e-430a-a11e-9c92f0f4aa46", "type": "SendEmail", "displayName": "Send Email", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "83", "name": "From", "expressions": { "$id": "84", "Literal": "workflow#acme.com" } }, { "$id": "85", "name": "To", "syntax": "JavaScript", "expressions": { "$id": "86", "JavaScript": "[Document.Author.Email]" } }, { "$id": "87", "name": "Subject", "syntax": "Liquid", "expressions": { "$id": "88", "Literal": "Document {{ Variables.Document.Id }} Rejected", "JavaScript": "Document {{ Variables.Document.Id }} Rejected" } }, { "$id": "89", "name": "Attachments", "expressions": { "$id": "90" } }, { "$id": "91", "name": "Body", "syntax": "Liquid", "expressions": { "$id": "92", "Liquid": "Nice try {{ Variables.Document.Author.Name }}, but that document needs work." } }, { "$id": "93", "name": "Cc", "expressions": { "$id": "94" } }, { "$id": "95", "name": "Bcc", "expressions": { "$id": "96" } } ], "propertyStorageProviders": { "$id": "97" } }, { "$id": "98", "activityId": "0be8d291-f88e-4db6-866e-fc722df70b27", "type": "Timer", "displayName": "Timer", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "99", "name": "Timeout", "syntax": "JavaScript", "expressions": { "$id": "100", "JavaScript": "Duration.FromSeconds(10)" } } ], "propertyStorageProviders": { "$id": "101" } }, { "$id": "102", "activityId": "01b73005-d48e-46eb-88ae-55a08f96c356", "type": "SendEmail", "displayName": "Send Email", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "103", "name": "From", "expressions": { "$id": "104", "Literal": "workflow#acme.com" } }, { "$id": "105", "name": "To", "expressions": { "$id": "106", "Json": "[\"josh#acme.com\"]" } }, { "$id": "107", "name": "Subject", "syntax": "Liquid", "expressions": { "$id": "108", "Liquid": "{{ Variables.Document.Author.Name }} is waiting for your review!" } }, { "$id": "109", "name": "Attachments", "expressions": { "$id": "110" } }, { "$id": "111", "name": "Body", "syntax": "Liquid", "expressions": { "$id": "112", "Liquid": "Don't forget to review document {{ Variables.Document.Id }}.<br>Approve or Reject" } }, { "$id": "113", "name": "Cc", "expressions": { "$id": "114" } }, { "$id": "115", "name": "Bcc", "expressions": { "$id": "116" } } ], "propertyStorageProviders": { "$id": "117" } }, { "$id": "118", "activityId": "e1c0aedb-c75b-4386-a20a-b0121f3a1421", "type": "Join", "displayName": "Join", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "119", "name": "EagerJoin", "expressions": { "$id": "120" } }, { "$id": "121", "name": "Mode", "expressions": { "$id": "122", "Literal": "WaitAny" } } ], "propertyStorageProviders": { "$id": "123" } }, { "$id": "124", "activityId": "84247af4-66a8-41ab-a442-b72b1d256154", "type": "WriteHttpResponse", "displayName": "HTTP Response", "persistWorkflow": false, "loadWorkflowContext": false, "saveWorkflowContext": false, "properties": [ { "$id": "125", "name": "Content", "expressions": { "$id": "126", "Literal": "Thanks for the hard work!" } }, { "$id": "127", "name": "ContentType", "expressions": { "$id": "128", "Literal": "text/html" } }, { "$id": "129", "name": "StatusCode", "expressions": { "$id": "130", "Literal": "OK" } }, { "$id": "131", "name": "CharSet", "expressions": { "$id": "132", "Literal": "" } }, { "$id": "133", "name": "ResponseHeaders", "expressions": { "$id": "134" } } ], "propertyStorageProviders": { "$id": "135" } } ], "connections": [ { "$id": "136", "sourceActivityId": "b1d82194-6a6b-4568-adde-382b16027c93", "targetActivityId": "2e7f8800-d49f-4485-b47b-0c9f3cb82a48", "outcome": "Done" }, { "$id": "137", "sourceActivityId": "2e7f8800-d49f-4485-b47b-0c9f3cb82a48", "targetActivityId": "b10ffb0d-c9ae-439a-86fa-b4351294666d", "outcome": "Done" }, { "$id": "138", "sourceActivityId": "b10ffb0d-c9ae-439a-86fa-b4351294666d", "targetActivityId": "90942864-bd26-4309-82fd-51f27b8e3615", "outcome": "Done" }, { "$id": "139", "sourceActivityId": "90942864-bd26-4309-82fd-51f27b8e3615", "targetActivityId": "c62c8ff0-db76-4dea-b1a6-6cc138415b17", "outcome": "Done" }, { "$id": "140", "sourceActivityId": "c62c8ff0-db76-4dea-b1a6-6cc138415b17", "targetActivityId": "aa201fb5-a50f-44b1-989f-7a7b57b3b52d", "outcome": "Approve" }, { "$id": "141", "sourceActivityId": "aa201fb5-a50f-44b1-989f-7a7b57b3b52d", "targetActivityId": "615f0e0d-9f7a-4a2f-ab9e-97b3bea10cbe", "outcome": "Done" }, { "$id": "142", "sourceActivityId": "c62c8ff0-db76-4dea-b1a6-6cc138415b17", "targetActivityId": "af52dae7-254b-4602-be35-0c0ef23a4ba5", "outcome": "Reject" }, { "$id": "143", "sourceActivityId": "af52dae7-254b-4602-be35-0c0ef23a4ba5", "targetActivityId": "ce2c17ff-cb9e-430a-a11e-9c92f0f4aa46", "outcome": "Done" }, { "$id": "144", "sourceActivityId": "c62c8ff0-db76-4dea-b1a6-6cc138415b17", "targetActivityId": "0be8d291-f88e-4db6-866e-fc722df70b27", "outcome": "Remind" }, { "$id": "145", "sourceActivityId": "0be8d291-f88e-4db6-866e-fc722df70b27", "targetActivityId": "01b73005-d48e-46eb-88ae-55a08f96c356", "outcome": "Done" }, { "$id": "146", "sourceActivityId": "01b73005-d48e-46eb-88ae-55a08f96c356", "targetActivityId": "0be8d291-f88e-4db6-866e-fc722df70b27", "outcome": "Done" }, { "$id": "147", "sourceActivityId": "615f0e0d-9f7a-4a2f-ab9e-97b3bea10cbe", "targetActivityId": "e1c0aedb-c75b-4386-a20a-b0121f3a1421", "outcome": "Done" }, { "$id": "148", "sourceActivityId": "ce2c17ff-cb9e-430a-a11e-9c92f0f4aa46", "targetActivityId": "e1c0aedb-c75b-4386-a20a-b0121f3a1421", "outcome": "Done" }, { "$id": "149", "sourceActivityId": "e1c0aedb-c75b-4386-a20a-b0121f3a1421", "targetActivityId": "84247af4-66a8-41ab-a442-b72b1d256154", "outcome": "Done" } ], "id": "cb2fbcfe31c44875b6f82b01ef477ea9" }
Nevermind..., the correct url is http://localhost:13000/workflows/v2/documents instead of http://localhost:13000/v2/documents. I found this by trial and error. I will submit a PR to amend the documentation.
How to get one element from array of objects in elasticsearch
I have a products index which has an offers field. Offers is an array of objects. I want to return one offer by seller_id in an array or in a new field. Input: with seller_id=5 { "_index":"dev_products", "_type":"_doc", "_id":"138", "_score":1.0, "_source":{ "is_adult":false, "status_id":3, "allow_publish":false, "name":"Consequuntur expedita sit perferendis est.", "category_id":816, "brand_id":363, "description":"Nec.", "type":3, "vendor_code":"4968258909901", "barcode":"98735976", "code":"consequuntur-expedita-sit-perferendis-est", "updated_at":"2022-11-15T10:42:33.000000Z", "created_at":"2022-11-15T10:42:33.000000Z", "id":138, "offers":[ { "product_id":"138", "seller_id":"1", "sale_status":"2", "external_id":"1267631", "store_id":"2", "qty":"44", "storage_address":"", "base_price":"312.84", "updated_at":"2022-11-15T10:42:49.000000Z", "created_at":"2022-11-15T10:42:49.000000Z", "id":74 }, { "product_id":"138", "seller_id":"2", "sale_status":"1", "external_id":"2795841", "store_id":"2", "qty":"1", "storage_address":"", "base_price":"1812.3", "updated_at":"2022-11-15T10:44:50.000000Z", "created_at":"2022-11-15T10:44:50.000000Z", "id":76 }, { "product_id":"138", "seller_id":"3", "sale_status":"1", "external_id":"32219", "store_id":"1", "qty":"32", "storage_address":"", "base_price":"1556.25", "updated_at":"2022-11-15T10:50:16.000000Z", "created_at":"2022-11-15T10:50:16.000000Z", "id":77 }, { "product_id":"138", "seller_id":"4", "sale_status":"1", "external_id":"967427", "store_id":"1", "qty":"35", "storage_address":"", "base_price":"137.62", "updated_at":"2022-11-15T10:50:18.000000Z", "created_at":"2022-11-15T10:50:18.000000Z", "id":78 }, { "product_id":"138", "seller_id":"5", "sale_status":"2", "external_id":"209466", "store_id":"1", "qty":"45", "storage_address":"", "base_price":"187.03", "updated_at":"2022-11-15T10:50:19.000000Z", "created_at":"2022-11-15T10:50:19.000000Z", "id":79 }, { "product_id":"138", "seller_id":"6", "sale_status":"1", "external_id":"522912", "store_id":"1", "qty":"61", "storage_address":"", "base_price":"306.39", "updated_at":"2022-11-15T10:50:20.000000Z", "created_at":"2022-11-15T10:50:20.000000Z", "id":80 } ] } } Expected: { "_index":"dev_products", "_type":"_doc", "_id":"138", "_score":1.0, "_source":{ "is_adult":false, "status_id":3, "allow_publish":false, "name":"Consequuntur expedita sit perferendis est.", "category_id":816, "brand_id":363, "description":"Nec.", "type":3, "vendor_code":"4968258909901", "barcode":"98735976", "code":"consequuntur-expedita-sit-perferendis-est", "updated_at":"2022-11-15T10:42:33.000000Z", "created_at":"2022-11-15T10:42:33.000000Z", "id":138, "offers":[ { "product_id":"138", "seller_id":"5", "sale_status":"2", "external_id":"209466", "store_id":"1", "qty":"45", "storage_address":"", "base_price":"187.03", "updated_at":"2022-11-15T10:50:19.000000Z", "created_at":"2022-11-15T10:50:19.000000Z", "id":79 } ] } } Or expected: { "_index":"dev_products", "_type":"_doc", "_id":"138", "_score":1.0, "_source":{ "is_adult":false, "status_id":3, "allow_publish":false, "name":"Consequuntur expedita sit perferendis est.", "category_id":816, "brand_id":363, "description":"Nec.", "type":3, "vendor_code":"4968258909901", "barcode":"98735976", "code":"consequuntur-expedita-sit-perferendis-est", "updated_at":"2022-11-15T10:42:33.000000Z", "created_at":"2022-11-15T10:42:33.000000Z", "id":138, "offer":{ "product_id":"138", "seller_id":"5", "sale_status":"2", "external_id":"209466", "store_id":"1", "qty":"45", "storage_address":"", "base_price":"187.03", "updated_at":"2022-11-15T10:50:19.000000Z", "created_at":"2022-11-15T10:50:19.000000Z", "id":79 } } } Thanks for help!
If the offers field is nested type you can to use inner hits to get only object match in list. The object you expected will in "inner_hits" response. Query GET idx_nested/_search?filter_path=hits.hits { "query": { "nested": { "path": "offers", "query": { "match": { "offers.seller_id": "5" } }, "inner_hits": {} } } } Response: { "hits": { "hits": [ { "_index": "idx_nested", "_id": "kYyYf4QBgXg8h_rctd1z", "_score": 1.540445, "_source": { "is_adult": false, "status_id": 3, "allow_publish": false, "name": "Consequuntur expedita sit perferendis est.", "category_id": 816, "brand_id": 363, "description": "Nec.", "type": 3, "vendor_code": "4968258909901", "barcode": "98735976", "code": "consequuntur-expedita-sit-perferendis-est", "updated_at": "2022-11-15T10:42:33.000000Z", "created_at": "2022-11-15T10:42:33.000000Z", "id": 138, "offers": [ { "product_id": "138", "seller_id": "1", "sale_status": "2", "external_id": "1267631", "store_id": "2", "qty": "44", "storage_address": "", "base_price": "312.84", "updated_at": "2022-11-15T10:42:49.000000Z", "created_at": "2022-11-15T10:42:49.000000Z", "id": 74 }, { "product_id": "138", "seller_id": "2", "sale_status": "1", "external_id": "2795841", "store_id": "2", "qty": "1", "storage_address": "", "base_price": "1812.3", "updated_at": "2022-11-15T10:44:50.000000Z", "created_at": "2022-11-15T10:44:50.000000Z", "id": 76 }, { "product_id": "138", "seller_id": "3", "sale_status": "1", "external_id": "32219", "store_id": "1", "qty": "32", "storage_address": "", "base_price": "1556.25", "updated_at": "2022-11-15T10:50:16.000000Z", "created_at": "2022-11-15T10:50:16.000000Z", "id": 77 }, { "product_id": "138", "seller_id": "4", "sale_status": "1", "external_id": "967427", "store_id": "1", "qty": "35", "storage_address": "", "base_price": "137.62", "updated_at": "2022-11-15T10:50:18.000000Z", "created_at": "2022-11-15T10:50:18.000000Z", "id": 78 }, { "product_id": "138", "seller_id": "5", "sale_status": "2", "external_id": "209466", "store_id": "1", "qty": "45", "storage_address": "", "base_price": "187.03", "updated_at": "2022-11-15T10:50:19.000000Z", "created_at": "2022-11-15T10:50:19.000000Z", "id": 79 }, { "product_id": "138", "seller_id": "6", "sale_status": "1", "external_id": "522912", "store_id": "1", "qty": "61", "storage_address": "", "base_price": "306.39", "updated_at": "2022-11-15T10:50:20.000000Z", "created_at": "2022-11-15T10:50:20.000000Z", "id": 80 } ] }, "inner_hits": { "offers": { "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 1.540445, "hits": [ { "_index": "idx_nested", "_id": "kYyYf4QBgXg8h_rctd1z", "_nested": { "field": "offers", "offset": 4 }, "_score": 1.540445, "_source": { "store_id": "1", "updated_at": "2022-11-15T10:50:19.000000Z", "storage_address": "", "product_id": "138", "qty": "45", "base_price": "187.03", "sale_status": "2", "created_at": "2022-11-15T10:50:19.000000Z", "external_id": "209466", "id": 79, "seller_id": "5" } } ] } } } } ] } }
Color the area formed between Line Chart and Threshold line
I am referring to below link: [https://stackoverflow.com/questions/25469434/finding-threshold-intersection-in-a-d3-chart][1] I need to achieve similar thing but I need to color the area formed by intersection of horizontal line and the line Can somebody help me
You can do it fairly easily with a gradient. Here's how you would do that. Note that you'd want to replace the offset %'s in the gradient definition with appropriately calculated numbers. var data = [{ "time": "2014-02-25T19:00:00Z", "temp": "39.08" }, { "time": "2014-02-25T21:00:00Z", "temp": "39.51" }, { "time": "2014-02-25T23:00:00Z", "temp": "39.14" }, { "time": "2014-02-26T01:00:00Z", "temp": "40.79" }, { "time": "2014-02-26T03:00:00Z", "temp": "41.17" }, { "time": "2014-02-26T05:00:00Z", "temp": "40.39" }, { "time": "2014-02-26T07:00:00Z", "temp": "40.49" }, { "time": "2014-02-26T09:00:00Z", "temp": "40.29" }, { "time": "2014-02-26T11:00:00Z", "temp": "39.90" }, { "time": "2014-02-26T13:00:00Z", "temp": "39.66" }, { "time": "2014-02-26T15:00:00Z", "temp": "39.01" }, { "time": "2014-02-26T17:00:00Z", "temp": "37.91" }, { "time": "2014-02-26T19:00:00Z", "temp": "39.64" }, { "time": "2014-02-26T21:00:00Z", "temp": "38.21" }, { "time": "2014-02-26T23:00:00Z", "temp": "39.60" }, { "time": "2014-02-27T01:00:00Z", "temp": "40.13" }, { "time": "2014-02-27T03:00:00Z", "temp": "40.51" }, { "time": "2014-02-27T05:00:00Z", "temp": "40.78" }, { "time": "2014-02-27T07:00:00Z", "temp": "40.54" }, { "time": "2014-02-27T09:00:00Z", "temp": "40.29" }, { "time": "2014-02-27T11:00:00Z", "temp": "40.24" }, { "time": "2014-02-27T13:00:00Z", "temp": "40.00" }, { "time": "2014-02-27T15:00:00Z", "temp": "40.01" }, { "time": "2014-02-27T17:00:00Z", "temp": "38.96" }, { "time": "2014-02-27T19:00:00Z", "temp": "39.20" }, { "time": "2014-02-27T21:00:00Z", "temp": "40.14" }, { "time": "2014-02-27T23:00:00Z", "temp": "38.71" }, { "time": "2014-02-28T01:00:00Z", "temp": "40.88" }, { "time": "2014-02-28T03:00:00Z", "temp": "40.98" }, { "time": "2014-02-28T05:00:00Z", "temp": "41.05" }, { "time": "2014-02-28T07:00:00Z", "temp": "40.60" }, { "time": "2014-02-28T09:00:00Z", "temp": "40.47" }, { "time": "2014-02-28T11:00:00Z", "temp": "40.39" }, { "time": "2014-02-28T13:00:00Z", "temp": "40.44" }, { "time": "2014-02-28T15:00:00Z", "temp": "37.58" }, { "time": "2014-02-28T17:00:00Z", "temp": "38.26" }, { "time": "2014-02-28T19:00:00Z", "temp": "37.83" }, { "time": "2014-02-28T21:00:00Z", "temp": "39.26" }, { "time": "2014-02-28T23:00:00Z", "temp": "38.25" }, { "time": "2014-03-01T01:00:00Z", "temp": "39.60" }, { "time": "2014-03-01T03:00:00Z", "temp": "40.09" }, { "time": "2014-03-01T05:00:00Z", "temp": "39.92" }, { "time": "2014-03-01T07:00:00Z", "temp": "39.67" }, { "time": "2014-03-01T09:00:00Z", "temp": "39.73" }, { "time": "2014-03-01T11:00:00Z", "temp": "39.93" }, { "time": "2014-03-01T13:00:00Z", "temp": "39.90" }, { "time": "2014-03-01T15:00:00Z", "temp": "39.82" }, { "time": "2014-03-01T17:00:00Z", "temp": "37.47" }, { "time": "2014-03-01T19:00:00Z", "temp": "38.30" }, { "time": "2014-03-01T21:00:00Z", "temp": "39.17" }, { "time": "2014-03-01T23:00:00Z", "temp": "38.87" }, { "time": "2014-03-02T01:00:00Z", "temp": "40.01" }, { "time": "2014-03-02T03:00:00Z", "temp": "40.31" }, { "time": "2014-03-02T05:00:00Z", "temp": "39.31" }, { "time": "2014-03-02T07:00:00Z", "temp": "39.78" }, { "time": "2014-03-02T09:00:00Z", "temp": "40.32" }, { "time": "2014-03-02T11:00:00Z", "temp": "40.48" }, { "time": "2014-03-02T13:00:00Z", "temp": "39.94" }, { "time": "2014-03-02T15:00:00Z", "temp": "38.42" }, { "time": "2014-03-02T17:00:00Z", "temp": "39.41" }, { "time": "2014-03-02T19:00:00Z", "temp": "39.56" }, { "time": "2014-03-02T21:00:00Z", "temp": "36.89" }, { "time": "2014-03-02T23:00:00Z", "temp": "39.53" }, { "time": "2014-03-03T01:00:00Z", "temp": "40.97" }, { "time": "2014-03-03T03:00:00Z", "temp": "40.58" }, { "time": "2014-03-03T05:00:00Z", "temp": "38.17" }, { "time": "2014-03-03T07:00:00Z", "temp": "39.50" }, { "time": "2014-03-03T09:00:00Z", "temp": "40.47" }, { "time": "2014-03-03T11:00:00Z", "temp": "40.28" }, { "time": "2014-03-03T13:00:00Z", "temp": "37.48" }, { "time": "2014-03-03T15:00:00Z", "temp": "38.13" }, { "time": "2014-03-03T17:00:00Z", "temp": "39.17" }, { "time": "2014-03-03T19:00:00Z", "temp": "39.27" }, { "time": "2014-03-03T21:00:00Z", "temp": "38.65" }, { "time": "2014-03-03T23:00:00Z", "temp": "39.78" }, { "time": "2014-03-04T01:00:00Z", "temp": "39.62" }, { "time": "2014-03-04T03:00:00Z", "temp": "39.49" }, { "time": "2014-03-04T05:00:00Z", "temp": "39.65" }, { "time": "2014-03-04T07:00:00Z", "temp": "40.07" }, { "time": "2014-03-04T09:00:00Z", "temp": "40.72" }, { "time": "2014-03-04T11:00:00Z", "temp": "40.46" }, { "time": "2014-03-04T13:00:00Z", "temp": "38.86" }, { "time": "2014-03-04T15:00:00Z", "temp": "39.40" }, { "time": "2014-03-04T17:00:00Z", "temp": "40.39" }, { "time": "2014-03-04T19:00:00Z", "temp": "39.61" }, { "time": "2014-03-04T21:00:00Z", "temp": "38.94" }, { "time": "2014-03-04T23:00:00Z", "temp": "40.43" }, { "time": "2014-03-05T01:00:00Z", "temp": "40.17" }, { "time": "2014-03-05T03:00:00Z", "temp": "39.81" }, { "time": "2014-03-05T05:00:00Z", "temp": "40.68" }, { "time": "2014-03-05T07:00:00Z", "temp": "39.80" }, { "time": "2014-03-05T09:00:00Z", "temp": "40.38" }, { "time": "2014-03-05T11:00:00Z", "temp": "39.05" }, { "time": "2014-03-05T13:00:00Z", "temp": "37.91" }, { "time": "2014-03-05T15:00:00Z", "temp": "39.28" }, { "time": "2014-03-05T17:00:00Z", "temp": "39.72" }, { "time": "2014-03-05T19:00:00Z", "temp": "38.84" }, { "time": "2014-03-05T21:00:00Z", "temp": "39.74" }, { "time": "2014-03-05T23:00:00Z", "temp": "40.63" }, { "time": "2014-03-06T01:00:00Z", "temp": "39.66" }, { "time": "2014-03-06T03:00:00Z", "temp": "40.71" }, { "time": "2014-03-06T05:00:00Z", "temp": "40.67" }, { "time": "2014-03-06T07:00:00Z", "temp": "40.93" }, { "time": "2014-03-06T09:00:00Z", "temp": "40.48" }, { "time": "2014-03-06T11:00:00Z", "temp": "39.54" }, { "time": "2014-03-06T13:00:00Z", "temp": "40.54" }, { "time": "2014-03-06T15:00:00Z", "temp": "39.90" }, { "time": "2014-03-06T17:00:00Z", "temp": "39.85" }, { "time": "2014-03-06T19:00:00Z", "temp": "39.37" }, { "time": "2014-03-06T21:00:00Z", "temp": "40.58" }, { "time": "2014-03-06T23:00:00Z", "temp": "39.72" }, { "time": "2014-03-07T01:00:00Z", "temp": "40.40" }, { "time": "2014-03-07T03:00:00Z", "temp": "40.68" }, { "time": "2014-03-07T05:00:00Z", "temp": "40.72" }, { "time": "2014-03-07T07:00:00Z", "temp": "41.08" }, { "time": "2014-03-07T09:00:00Z", "temp": "38.06" }, { "time": "2014-03-07T11:00:00Z", "temp": "39.39" }, { "time": "2014-03-07T13:00:00Z", "temp": "39.83" }, { "time": "2014-03-07T15:00:00Z", "temp": "40.51" }, { "time": "2014-03-07T17:00:00Z", "temp": "40.21" }, { "time": "2014-03-07T19:00:00Z", "temp": "38.25" }, { "time": "2014-03-07T21:00:00Z", "temp": "40.39" }, { "time": "2014-03-07T23:00:00Z", "temp": "40.54" }, { "time": "2014-03-08T01:00:00Z", "temp": "39.31" }, { "time": "2014-03-08T03:00:00Z", "temp": "40.29" }, { "time": "2014-03-08T05:00:00Z", "temp": "40.94" }, { "time": "2014-03-08T07:00:00Z", "temp": "41.05" }, { "time": "2014-03-08T09:00:00Z", "temp": "39.82" }, { "time": "2014-03-08T11:00:00Z", "temp": "39.14" }, { "time": "2014-03-08T13:00:00Z", "temp": "36.90" }, { "time": "2014-03-08T15:00:00Z", "temp": "39.69" }, { "time": "2014-03-08T17:00:00Z", "temp": "39.61" }, { "time": "2014-03-08T19:00:00Z", "temp": "38.97" }, { "time": "2014-03-08T21:00:00Z", "temp": "39.58" }, { "time": "2014-03-08T23:00:00Z", "temp": "40.39" }, { "time": "2014-03-09T01:00:00Z", "temp": "40.85" }, { "time": "2014-03-09T03:00:00Z", "temp": "40.66" }, { "time": "2014-03-09T05:00:00Z", "temp": "40.91" }, { "time": "2014-03-09T07:00:00Z", "temp": "40.83" }, { "time": "2014-03-09T09:00:00Z", "temp": "37.44" }, { "time": "2014-03-09T11:00:00Z", "temp": "39.01" }, { "time": "2014-03-09T13:00:00Z", "temp": "37.28" }, { "time": "2014-03-09T15:00:00Z", "temp": "38.47" }, { "time": "2014-03-09T17:00:00Z", "temp": "39.60" }, { "time": "2014-03-09T19:00:00Z", "temp": "39.15" }, { "time": "2014-03-09T21:00:00Z", "temp": "40.64" }, { "time": "2014-03-09T23:00:00Z", "temp": "37.76" }]; var parseDate = d3.time.format("%Y-%m-%dT%H:%M:%SZ").parse; data.forEach(function (d) { d.time = parseDate(d.time); }); var chart = d3.select("#chart"); var padding = 40, width = 950, height = 300, xTicks = 10, yTicks = 8; var threshold = 40.5; var svg = chart.append("svg") .attr("width", width + padding * 2) .attr("height", height + padding * 2) .append("g") .attr("transform", "translate(" + padding + "," + padding + ")"); var myDefs = svg.append("defs"); var myGradient = myDefs.append("linearGradient") .attr("id", "myGradient") .attr("gradientUnits", "userSpaceOnUse") .attr("x1", "0") .attr("x2", "0") .attr("y1", "0") .attr("y2", height); myGradient.append("stop") .attr("stop-color", "blue") .attr("offset", "0%"); myGradient.append("stop") .attr("stop-color", "blue") .attr("offset", "25%"); myGradient.append("stop") .attr("stop-color", "rgba(0,0,0,0)") .attr("offset", "25%"); var x = d3.time.scale().range([0, width]); var y = d3.scale.linear().range([height, 0]); var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(xTicks); var yAxis = d3.svg.axis().scale(y).orient("left").ticks(yTicks); var valueLine = d3.svg.line() .interpolate("basis") .x(function (d) { return x(d.time); }) .y(function (d) { return y(d.temp); }); x.domain(d3.extent(data, function (d) { return d.time; })); y.domain([33, 43]); var mainLine = svg.append("path") .attr({ "class": "line", stroke: "steelblue", d: valueLine(data) }); svg.append("line").attr("stroke", "#F00").attr("x1", 0).attr("y1", y(threshold)).attr("x2", width).attr("y2", y(threshold)).attr("class", "line"); path.line { stroke-width: 2; fill: url(#myGradient); } <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script> <div id="chart"></div>
jqgrid treeGrid Cannot read property 'rowIndex' of undefined
I try to use local data with treeGrid, when i click the unfold button . I get the tips "Cannot read property 'rowIndex' of undefined"
<!DOCTYPE html> <html lang="en"> <head> <!-- The jQuery library is a prerequisite for all jqSuite products --> <script type="text/ecmascript" src="./js/jquery.min.js"></script> <!-- This is the Javascript file of jqGrid --> <script type="text/ecmascript" src="./js/jquery.jqGrid.min.js"></script> <!-- This is the localization file of the grid controlling messages, labels, etc. <!-- We support more than 40 localizations --> <script type="text/ecmascript" src="./js/i18n/grid.locale-en.js"></script> <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom --> <link rel="stylesheet" type="text/css" media="screen" href="./css/jquery-ui-1.10.4.custom.min.css" /> <!-- The link to the CSS that the grid needs --> <link rel="stylesheet" type="text/css" media="screen" href="./css/ui.jqgrid.css" /> <meta charset="utf-8" /> <title>jqTreeGrid - Load On Demand - Load all Rows at once collapsed</title> </head> <body> <table id="tree"></table> <div id="pager"></div> <script type="text/javascript"> var rows = [ { "category_id": "1", "name": "ELECTRONICS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "1", "rgt": "44", "level": "0", "uiicon": "" }, { "category_id": "2", "name": "TELEVISIONS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "2", "rgt": "19", "level": "1", "uiicon": "" }, { "category_id": "3", "name": "TUBE", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "3", "rgt": "8", "level": "2", "uiicon": "" }, { "category_id": "11", "name": "26 \" TV", "price": "200.00", "qty_onhand": "1", "color": "black", "lft": "4", "rgt": "5", "level": "3", "uiicon": "ui-icon-image" }, { "category_id": "12", "name": "30 \" TV", "price": "350.00", "qty_onhand": "2", "color": "black", "lft": "6", "rgt": "7", "level": "3", "uiicon": "ui-icon-document" }, { "category_id": "4", "name": "LCD", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "9", "rgt": "12", "level": "2", "uiicon": "" }, { "category_id": "13", "name": "Super-LCD 42\" ", "price": "400.00", "qty_onhand": "10", "color": "all", "lft": "10", "rgt": "11", "level": "3", "uiicon": "ui-icon-video" }, { "category_id": "5", "name": "PLASMA", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "13", "rgt": "18", "level": "2", "uiicon": "" }, { "category_id": "14", "name": "Ultra-Plasma 62\" ", "price": "440.00", "qty_onhand": "2", "color": "silver", "lft": "14", "rgt": "15", "level": "3", "uiicon": "ui-icon-clipboard" }, { "category_id": "15", "name": "Value Plasma 38\" ", "price": "312.00", "qty_onhand": "0", "color": "silver", "lft": "16", "rgt": "17", "level": "3", "uiicon": "ui-icon-clipboard" }, { "category_id": "6", "name": "PORTABLE ELECTRONICS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "20", "rgt": "43", "level": "1", "uiicon": "" }, { "category_id": "7", "name": "MP3 PLAYERS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "21", "rgt": "32", "level": "2", "uiicon": "" }, { "category_id": "8", "name": "FLASH", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "22", "rgt": "29", "level": "3", "uiicon": "" }, { "category_id": "17", "name": "Super-Shuffle 1gb", "price": "20.00", "qty_onhand": "11", "color": "all", "lft": "23", "rgt": "24", "level": "4", "uiicon": "ui-icon-note" }, { "category_id": "21", "name": "5Gb Flash", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "25", "rgt": "26", "level": "4", "uiicon": "ui-icon-comment" }, { "category_id": "22", "name": "10Gb flash ", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "27", "rgt": "28", "level": "4", "uiicon": "ui-icon-tag" }, { "category_id": "16", "name": " Power-MP3 128mb", "price": "123.00", "qty_onhand": "2", "color": "withe", "lft": "30", "rgt": "31", "level": "3", "uiicon": "ui-icon-signal-diag" }, { "category_id": "9", "name": "CD PLAYERS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "33", "rgt": "38", "level": "2", "uiicon": "" }, { "category_id": "18", "name": " Porta CD ", "price": "10.00", "qty_onhand": "0", "color": "", "lft": "34", "rgt": "35", "level": "3", "uiicon": "ui-icon-eject" }, { "category_id": "19", "name": "CD To go!", "price": "110.00", "qty_onhand": "11", "color": "", "lft": "36", "rgt": "37", "level": "3", "uiicon": "ui-icon-power" }, { "category_id": "10", "name": "2 WAY RADIOS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "39", "rgt": "42", "level": "2", "uiicon": "" }, { "category_id": "20", "name": "Family Talk 360 ", "price": "200.00", "qty_onhand": "15", "color": "", "lft": "40", "rgt": "41", "level": "3", "uiicon": "ui-icon-volume-on" }, { "category_id": "23", "name": "COMPUTERS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "45", "rgt": "50", "level": "0", "uiicon": "" }, { "category_id": "25", "name": "DESKTOP ", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "46", "rgt": "47", "level": "1", "uiicon": "" }, { "category_id": "26", "name": "LAPTOPS", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "48", "rgt": "49", "level": "1", "uiicon": "" }, { "category_id": "24", "name": "APPLIANCES", "price": "0.00", "qty_onhand": "0", "color": "", "lft": "51", "rgt": "52", "level": "0", "uiicon": "" } ] jQuery(document).ready(function ($) { jQuery('#tree').jqGrid({ // "url":"data.json", "colModel": [ { "name": "category_id", "index": "accounts.account_id", "sorttype": "int", "key": true, "hidden": true, "width": 50 }, { "name": "name", "index": "name", "sorttype": "string", "label": "Name", "width": 170 }, { "name": "price", "index": "price", "sorttype": "numeric", "label": "Price", "width": 90, "align": "right" }, { "name": "qty_onhand", "index": "qty_onhand", "sorttype": "int", "label": "Qty", "width": 90, "align": "right" }, { "name": "color", "index": "color", "sorttype": "string", "label": "Color", "width": 100 }, { "name": "lft", "hidden": true }, { "name": "rgt", "hidden": true }, { "name": "level", "hidden": true }, { "name": "uiicon", "hidden": true } ], "width": "780", "hoverrows": false, "viewrecords": false, "gridview": true, "height": "auto", "sortname": "lft", "loadonce": true, "rowNum": 100, "scrollrows": true, // enable tree grid "treeGrid": true, // which column is expandable "ExpandColumn": "name", // datatype "treedatatype": "json", // the model used "treeGridModel": "nested", // configuration of the data comming from server "treeReader": { "left_field": "lft", "right_field": "rgt", "level_field": "level", "leaf_field": "isLeaf", "expanded_field": "expanded", "loaded": "loaded", "icon_field": "icon" }, // "sortorder": "asc", "datatype": "local", "data": rows, "pager": "#pager" }); }); </script> </body> </html>
For localdata type, you must configure the localReader parameter: localReader: { repeatitems: true, // cell: "", id: "category_id" }
elastic search query not returning results when the field has double quotes
I execute this query POST /_search { "query":{ "filtered":{ "filter":{ "bool":{ "must":[ { "term":{ "tpid":3 } }, { "term":{ "eapid":0 } } ] } } } } } I get result like this { "took": 2, "timed_out": false, "_shards": { "total": 20, "successful": 20, "failed": 0 }, "hits": { "total": 10633, "max_score": 1, "hits": [ { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "v63uksmIRgG9bI5hgS5DIQ", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OVB", "arrivalAirport": "KRR", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 3, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.426Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "bu7I38_CRDG17sXVq3IR-g", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSL", "arrivalAirport": "OSA", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 149, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.486Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "wWb9xFpuRASTWyaqm-q9Kw", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSL", "arrivalAirport": "NYC", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 49, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.491Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "c1ULKWyhR0iYmaZ5unafKA", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSL", "arrivalAirport": "MOW", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 16, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.495Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "BGuGnuXsSne6jB7_ith5Lg", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSL", "arrivalAirport": "MEL", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 10, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 2, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.505Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "lHXm68TTTPG44dIskGCr-w", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSA", "arrivalAirport": "STO", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 12, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.606Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "DewbkMq0Q22IsReLTRIXww", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSA", "arrivalAirport": "NYC", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 3, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.623Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "tuCl1rEcT4W3dJ9Am-XvSw", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OSA", "arrivalAirport": "MEL", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 9, "LengthOfStay": 30 }, "blacklistAggregatedValue": { "searchCount": 25, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.625Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "6-O9T3HuRYuSVD68_cVeCg", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "OKC", "arrivalAirport": "PHX", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 126, "LengthOfStay": 7 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.787Z", "type": "gss.aggregated.se" } }, { "_index": "gss.aggregated.se.logstash-2014.11.04", "_type": "gss.aggregated.se", "_id": "5_bGAZxdRIy5kAR5XuV70A", "_score": 1, "_source": { "blacklistAggregatedKey": { "utcTimestamp": "2014-10-28T09:00", "departureAirport": "NYC", "arrivalAirport": "QLA", "tpid": 3, "eapid": 0, "AdvancePurchaseWindow": 11, "LengthOfStay": -1 }, "blacklistAggregatedValue": { "searchCount": 1, "blackListed": 0 }, "#version": "1", "#timestamp": "2014-11-04T19:30:16.862Z", "type": "gss.aggregated.se" } } ] } } I want to filter this further by departure airport. when I try POST /_search { "query": { "filtered": { "filter": { "bool": { "must": [ { "term": { "tpid": 3 } }, { "term": { "eapid": 0 } }, { "term": { "departureAirport": "\"OVB\"" } } ] } } } } } I don't get results back.
Mention the mapping that you used? Run GET _mapping to get that. That will help debug the issue. But my hunch is that this is an analyzer issue. The field departureAirport must have been analyzed such that the double inverted quotes in its values got stripped off during indexing. This is the default behaviour. What I mean to say is, the field departureAirport has value "OVB" (without the quotes) indexed and not "\"OVB\"" (with the quotes). That is why you do not get results with the value having quotes.