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 categoryValue,
// width, width,
// height height,
index,
histogramMap
) => { ) => {
/* const bins = histogramMap.has(categoryValue)
Knowing that colorScale is based off continuous data, ? histogramMap.get(categoryValue)
createHistogramBins fetches the continuous data in relation to the cells relevant to the category value. : new Array(100).fill(0);
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( const zeros = bins.shift(); /* MUTATES, REMOVES FIRST ELEMENT */
categoryValue, const rest = bins.reduce(
mean (acc, current) => acc + current
); /* ); /* SUM REMAINING ELEMENTS */
// const histogramMap = col.histogram( return (
// 50, <g
// [range.min, range.max], key={`${index}_${categoryValue}`}
// groupBy transform={`translate(${this.dotplotLeftPadding}, ${
// ); /* Because the signature changes we really need different names for histogram to differentiate signatures */ index * 15 + this.dotplotTopPadding
})`}
// const bins = histogramMap.has(categoryValue) >
// ? histogramMap.get(categoryValue) <text textAnchor="end">{categoryValue}</text>
// : new Array(50).fill(0); <circle
r={(rest / zeros) * 10}
// const xScale = d3.scaleLinear().domain([0, bins.length]).range([0, width]); cx="11"
cy="-4"
// const largestBin = Math.max(...bins); style={{ fill: "rgba(70,130,180,.3)", stroke: "none" }}
/>
// const yScale = d3.scaleLinear().domain([0, largestBin]).range([0, height]); </g>
);
// return {
// xScale,
// yScale,
// bins,
// };
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,