score:2
I couldn't get this working with animated transitions, because there is something I am missing about how to interrupt transitions, and the original dc.scatterPlot
is already applying opacity transitions.
So, to start off, let's turn transitions on the original scatter plot:
chart1
.transitionDuration(0)
We also need to add Z to the input data for the scatter plot. Although it would make more sense to add it to the value, it's easy to add it to the key (and the scatter plot will ignore extra elements in the key):
dim1 = ndx.dimension(function (d) {
return [d.x, d.y, d.z];
}),
Then we can add a handler to to the scatter plot to apply opacity to the dots, based on the range of the filter in the bar chart:
chart1.on('pretransition', function(chart) {
var range = chart2.filter(); // 1
console.assert(!range || range.filterType==='RangedFilter'); // 2
var mid, div; // 3
if(range) {
mid = (range[0] + range[1])/2;
div = (range[1] - range[0])/2;
}
chart1.selectAll('path.symbol') // 4
.attr('opacity', function(d) {
if(range) { // 5
if(d.key[2] < range[0] || range[1] < d.key[2])
op = 0; // 6
else
op = 1 - Math.abs(d.key[2] - mid)/div; // 7
//console.log(mid, div, d.key[2], op);
return op;
}
else return 1;
})
});
- Get the current brush/filter from the bar chart
- It should either be
null
or it should be a RangedFilter - Find the midpoint and the distance from the midpoint to the edges of the brush
- Now apply opacity to all symbols in the scatter plot
- If there is an active brush, apply opacity (otherwise 1)
- If the symbol is outside the brush, opacity is 0
- Otherwise the opacity is linear based on the distance from the midpoint
You could probably use d3.ease to map the distance [0,1] to opacity [0,1] using a curve instead of linearly. This might be nice so that it emphasizes the points closer to the midpoint
This demo is not all that cool because the data is purely random, but it shows the idea: https://jsfiddle.net/gordonwoodhull/qq31xcoj/64/
EDIT: alright, it's a total abuse of dc.js, but if you really want to use it without filtering, and displaying the excluded points in grey, you can do that too.
This will disable filtering on the bar chart:
chart2.filterHandler(function(_, filters) { return filters; });
Then apply opacity and color to the scatter plot like this instead:
chart1.selectAll('path.symbol')
.attr('opacity', function(d) {
if(range && range.isFiltered(d.key[2]))
return 1 - Math.abs(d.key[2] - mid)/div;
else return 1;
})
.attr('fill', function(d) {
if(!range || range.isFiltered(d.key[2]))
return chart1.getColor(d);
else return '#ccc';
})
With this data it's tricky to see the difference between the light blue dots and the grey dots. Maybe it will work better with non-random data, maybe not. Maybe another color will help.
Again, you might as well use straight D3, since this disables most of what dc.js and crossfilter do. But you'd have to start from scratch to ask that question.
EDIT 2: sort the dots by filteredness like this:
.sort(function(d) {
return range && range.isFiltered(d.key[2]) ? 1 : 0;
})
Source: stackoverflow.com
Related Query
- How to filter views with an opacity range in d3/dc.js?
- How to Filter Data with D3.js?
- dimple.js filter x axis with date range
- How To Filter Data by Date Range on D3.js Line Chart?
- How to use the filter method with the update pattern?
- How to scale an integer to date with range and domain
- How to filter a featurecollection to an object that can be used with path.bounds()
- How to add the filter or ScaleExtent in d3 v4 in Timeline with Zoom functionality
- How to omit a data range with no filtering
- How to plot points on a map projection in D3.js and filter the data using range sliders?
- How to draw bar chart with range x-axis?
- Highlighting nodes and its neighbors not working in sync with another opacity filter
- D3 - How do I filter the right values with opacity?
- d3js - how to filter the array with values and pass in to data?
- How to use custom Angular filter inside directive with D3
- How to make X axis timescale with equal interval between elements on chart independent of time range
- How to filter out nodes with the same parent as the current node in d3.js
- How can create a table with using filter on csv data
- How do I create a border with gradiant opacity in CSS ?
- How to filter a range of elements in d3js?
- How do I remove all children elements from a node and then apply them again with different color and size?
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- How can I bring a circle to the front with d3?
- d3.js & nvd3.js -- How to set y-axis range
- How to set multiple attributes with one value function?
- How to select multiple selectors with selectAll?
- How to use D3 selectAll with multiple class names
- D3 - how to deal with JSON data structures?
- D3: How to refresh a chart with new data?
- How do I show a bootstrap tooltip with an SVG object?
More Query from same tag
- D3 x-Axis not showing correctly
- Starting Transitions and Animations With Area Graph in D3.JS
- d3 example does not work on a html page
- Summing arrays in JavaScript using d3.nest() Part II
- Strange "initial" values in d3.js
- Initial zoom not working in d3 v4
- Center the curved textPath inside an arc
- forceManyBody filtered in d3
- How to catch pinch and stretch gesture events in d3.zoom (d3v4/v5)
- dc.js/crossfilter.js brushon filter - selected filtering not updating in other charts
- Odd JavaScript Syntax that looks like a Python tuple
- Tooltip always displaying the same value
- D3 scatterplot using time scale on x-axis -- not working in Firefox
- d3 keeping text from extending outside of SVG
- Angular2 and D3.js Gantt chart
- D3--How to iterate through an array of colors
- How to specify x-axis and y-axis input data in dc.js time series graph?
- d3 line chart not getting terminated
- web2py and d3.js compatibility
- How to specify timeout in d3 xhr send request
- NVD3.js multiChart x-axis labels is aligned to lines, but not bars
- D3 Map - feeding data to tootip
- d3.js tree structure text links
- Get attribute x for axis' text element
- How to get coordinates of slices along the edge of a pie chart?
- Add small rectangles inside BIG rectangles with unique Ids and links in D3? after an specific ID
- Filtering CSV records in d3.js enter/update based on user input
- What is a "context" in this context: "symbol.context([context])"
- limit a voronoi diagram within country border in d3.js
- SVG text elements piling on top of one another at the 0,0 position - D3