make_scatter_instanced = (
d3,
deck,
luma,
point_radius,
data,
apply_map_morph,
get_color_function,
map_type,
transitions,
) => {
var getModel = make_model(deck, luma)
const {Layer} = deck;
class ScatterplotLayer extends Layer {
initializeState() {
const {gl} = this.context;
this.getAttributeManager().addInstanced({
instancePositions: {
size: 3,
type: gl.DOUBLE,
accessor: 'getPosition'
},
instanceRadius: {
size: 1,
accessor: 'getRadius',
defaultValue: 1
},
instanceColors: {
size: 4,
normalized: true,
type: gl.UNSIGNED_BYTE,
accessor: 'getColor',
defaultValue: [0, 0, 0, 255]
},
// createing a picking color attribute
customPickingColors: {
size: 3,
type: gl.UNSIGNED_BYTE,
update: this.calculatePickingColors
// update: calculatePickingColors
}
});
// Save the model in layer state
this.setState({
model: getModel(gl)
});
}
// updateState() {
// }
//////////////////////////////////////////////////
calculatePickingColors(attribute) {
const {data} = this.props;
const {value, size} = attribute;
let i = 0;
let index = 0;
for (const object of data) {
// console.log(index)
// Use the index index instead of object.id
const pickingColor = this.encodePickingColor(index);
value[index * 3] = pickingColor[0];
value[index * 3 + 1] = pickingColor[1];
value[index * 3 + 2] = pickingColor[2];
index++;
}
}
//////////////////////////////////////////////////
}
ScatterplotLayer.layerName = 'ScatterplotLayer';
ScatterplotLayer.defaultProps = defaultProps;
const layer = new ScatterplotLayer({
id: `scatterplot-${Date.now()}`,
data,
// getPosition: d => d.position,
getPosition: apply_map_morph,
getRadius: d => point_radius, // d.radius,
// getColor: d => d.color,
getColor: get_color_function,
pickable: true,
// required for tooltip
updateTriggers: {
// getFillColor: [select_meta, selected_clusters],
getPosition: map_type,
},
transitions: transitions,
onClick: (info, event) => {
console.log('clicking!!!')
// if (mutable selected_clusters[0] !== info.object[cluster_name]){
// mutable select_meta = cluster_name
// mutable selected_clusters = [info.object[cluster_name]]
// d3.select('#meta_dropdown').select('select').node().value = 'none'
// } else {
// mutable select_meta = cluster_name
// mutable selected_clusters = []
// d3.select('#meta_dropdown').select('select').node().value = cluster_name
// }
}
});
return layer;
}