dotplot 1

This commit is contained in:
Colin Megill
2021-07-23 13:28:17 -07:00
parent 5f9d0a6b34
commit 11570273e0
+47 -48
View File
@@ -3,6 +3,7 @@ import { connect, shallowEqual } from "react-redux";
// import _regl from "regl"; // import _regl from "regl";
import Async from "react-async"; import Async from "react-async";
import memoize from "memoize-one"; import memoize from "memoize-one";
// import * as d3 from "d3";
import * as globals from "../../globals"; import * as globals from "../../globals";
import { createCategorySummaryFromDfCol } from "../../util/stateManager/controlsHelpers"; import { createCategorySummaryFromDfCol } from "../../util/stateManager/controlsHelpers";
@@ -30,6 +31,8 @@ class Dotplot extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
const viewport = this.getViewportDimensions(); const viewport = this.getViewportDimensions();
this.dotplotTopPadding = 150;
this.dotplotLeftPadding = 200;
this.state = { this.state = {
viewport, viewport,
@@ -54,54 +57,45 @@ class Dotplot extends React.Component {
}; };
}; };
createDot = ( createRow = (
metadataField, metadataField,
categoryData, categoryData,
// colorAccessor, colorAccessor,
colorData, colorData,
categoryValue
// width,
// height
) => {
/*
Knowing that colorScale is based off continuous data,
createHistogramBins fetches the continuous data in relation to the cells relevant to the category value.
It then separates that data into 50 bins for drawing the mini-histogram
*/
// const groupBy = categoryData.col(metadataField);
const col = colorData.icol(0);
const mean = this.average(col.asArray());
console.log(
categoryValue, categoryValue,
mean width,
); /* height,
index,
histogramMap
) => {
const bins = histogramMap.has(categoryValue)
? histogramMap.get(categoryValue)
: new Array(100).fill(0);
// const histogramMap = col.histogram( const zeros = bins.shift(); /* MUTATES, REMOVES FIRST ELEMENT */
// 50, const rest = bins.reduce(
// [range.min, range.max], (acc, current) => acc + current
// groupBy ); /* SUM REMAINING ELEMENTS */
// ); /* Because the signature changes we really need different names for histogram to differentiate signatures */
// const bins = histogramMap.has(categoryValue) return (
// ? histogramMap.get(categoryValue) <g
// : new Array(50).fill(0); key={`${index}_${categoryValue}`}
transform={`translate(${this.dotplotLeftPadding}, ${
// const xScale = d3.scaleLinear().domain([0, bins.length]).range([0, width]); index * 15 + this.dotplotTopPadding
})`}
// const largestBin = Math.max(...bins); >
<text textAnchor="end">{categoryValue}</text>
// const yScale = d3.scaleLinear().domain([0, largestBin]).range([0, height]); <circle
r={(rest / zeros) * 10}
// return { cx="11"
// xScale, cy="-4"
// yScale, style={{ fill: "rgba(70,130,180,.3)", stroke: "none" }}
// bins, />
// }; </g>
return null; );
}; };
createDots = ( dotplot = (
metadataField, metadataField,
categoryData, categoryData,
categorySummary, categorySummary,
@@ -110,23 +104,29 @@ class Dotplot extends React.Component {
width, width,
height height
) => { ) => {
if (!colorData) return null; if (!colorAccessor || !colorData) return null;
return categorySummary.categoryValues.map((val) => { const groupBy = categoryData.col(metadataField);
return this.createDot( const col = colorData.icol(0);
const range = col.summarize();
const histogramMap = col.histogram(100, [range.min, range.max], groupBy);
return categorySummary.categoryValues.map((val, index) => {
return this.createRow(
metadataField, metadataField,
categoryData, categoryData,
colorAccessor, colorAccessor,
colorData, colorData,
val, val,
width, width,
height height,
index,
histogramMap
); );
}); });
}; };
average = (array) => array.reduce((a, b) => a + b) / array.length;
fetchAsyncProps = async (props) => { fetchAsyncProps = async (props) => {
const { viewport, annoMatrix, colors } = props.watchProps; const { viewport, annoMatrix, colors } = props.watchProps;
@@ -276,8 +276,7 @@ class Dotplot extends React.Component {
width={viewport.width} width={viewport.width}
height={viewport.height} height={viewport.height}
> >
<circle r="5" cx="20" cy="20" /> {this.dotplot(
{this.createDots(
"tissue", "tissue",
categoryData, categoryData,
categorySummary, categorySummary,