colorscales working in continuous metadata

This commit is contained in:
Colin Megill
2017-11-23 01:55:59 -08:00
parent 42bef3d6cd
commit abf14cf159
2 changed files with 46 additions and 19 deletions
+14 -12
View File
@@ -36,6 +36,7 @@ import {
initializeRanges, initializeRanges,
initializeMetadata, initializeMetadata,
colorAccessor: state.controls.colorAccessor, colorAccessor: state.controls.colorAccessor,
colorScale: state.controls.colorScale,
graphBrushSelection: state.controls.graphBrushSelection, graphBrushSelection: state.controls.graphBrushSelection,
continuousSelection: state.controls.continuousSelection, continuousSelection: state.controls.continuousSelection,
axesHaveBeenDrawn: state.controls.axesHaveBeenDrawn, axesHaveBeenDrawn: state.controls.axesHaveBeenDrawn,
@@ -66,7 +67,7 @@ class Continuous extends React.Component {
maybeDrawAxes(nextProps) { maybeDrawAxes(nextProps) {
if ( if (
!this.state.axes && !this.state.axes &&
nextProps.initializeRanges /* we assume if this is present, everything else is too */ nextProps.initializeRanges /* axes are created on full range of data */
) { ) {
const dimensions = createDimensions(nextProps.initializeRanges); const dimensions = createDimensions(nextProps.initializeRanges);
const xscale = d3.scalePoint() const xscale = d3.scalePoint()
@@ -109,29 +110,30 @@ class Continuous extends React.Component {
if ( if (
nextProps.ranges && nextProps.ranges &&
nextProps.continuousSelection && nextProps.continuousSelection &&
nextProps.axesHaveBeenDrawn /* this may cause things to never render :/ forceUpdate? */ nextProps.axesHaveBeenDrawn
) { ) {
if (this.state._drawLinesCanvas) { // if (this.state._drawLinesCanvas) {
this.state._drawLinesCanvas.invalidate(); // this.state._drawLinesCanvas.invalidate(); /* this is only necessary if the internals of drawLinesCanvas are using the render queue */
} // }
this.state.ctx.clearRect(0,0,width,height); this.state.ctx.clearRect(0, 0, width, height);
const _drawLinesCanvas = drawLinesCanvas( const _drawLinesCanvas = drawLinesCanvas(
_.filter(this.state.processedMetadata, (d) => { _.filter(this.state.processedMetadata, (d) => {
return nextProps.continuousSelection.indexOf(d.CellName) > -1 return nextProps.continuousSelection.indexOf(d.CellName) > -1 /* perf */
}), }),
this.state.processedDimensions, this.state.processedDimensions,
this.state.xscale, this.state.xscale,
this.state.ctx, this.state.ctx,
this.props.colorAccessor, nextProps.colorAccessor,
nextProps.colorScale,
); );
this.setState({ // this.setState({
// dimensions, // // dimensions,
_drawLinesCanvas, // _drawLinesCanvas, /* this will only exist if the internals of drawLinesCanvas are using the render queue */
}) // })
} }
} }
+32 -7
View File
@@ -1,3 +1,4 @@
import _ from "lodash";
import { import {
project project
} from "./util"; } from "./util";
@@ -14,12 +15,15 @@ const drawLinesCanvas = (
ctx, ctx,
dimensions, dimensions,
xscale, xscale,
color, colorAccessor,
colorScale,
) => { ) => {
return (d) => { return (d) => {
if (colorAccessor && colorScale) {
// ctx.strokeStyle = d["Sample.name.color"]; ctx.strokeStyle = d3.interpolateViridis(colorScale(d[colorAccessor]));
ctx.strokeStyle = "rgba(0,0,0,1)"; } else {
ctx.strokeStyle = "rgba(0,0,0,1)";
}
ctx.beginPath(); ctx.beginPath();
var coords = project(d, dimensions, xscale); var coords = project(d, dimensions, xscale);
coords.forEach((p,i) => { coords.forEach((p,i) => {
@@ -59,7 +63,8 @@ const drawCellLinesUsingRenderQueue = (
dimensions, dimensions,
xscale, xscale,
ctx, ctx,
color, colorAccessor,
colorScale,
) => { ) => {
const _renderLinesWithQueue = renderQueue( const _renderLinesWithQueue = renderQueue(
@@ -67,7 +72,8 @@ const drawCellLinesUsingRenderQueue = (
ctx, ctx,
dimensions, dimensions,
xscale, xscale,
color colorAccessor,
colorScale,
) )
).rate(50); ).rate(50);
@@ -77,4 +83,23 @@ const drawCellLinesUsingRenderQueue = (
} }
export default drawCellLinesUsingRenderQueue; const drawCellLinesSync = (
metadata,
dimensions,
xscale,
ctx,
colorAccessor,
colorScale,
) => {
const _draw = drawLinesCanvas(
ctx,
dimensions,
xscale,
colorAccessor,
colorScale,
)
_.each(metadata, _draw)
}
export default _.debounce(drawCellLinesSync, 100);
// export default drawCellLinesUsingRenderQueue;