mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 03:18:12 +08:00
Change color scales to rainbow (#449)
* rainbow * eslint * remove comments
This commit is contained in:
@@ -34,7 +34,8 @@ module.exports = {
|
|||||||
"object-curly-newline": ["error", { consistent: true }],
|
"object-curly-newline": ["error", { consistent: true }],
|
||||||
"react/prop-types": [0],
|
"react/prop-types": [0],
|
||||||
"space-before-function-paren": "off",
|
"space-before-function-paren": "off",
|
||||||
"function-paren-newline": "off"
|
"function-paren-newline": "off",
|
||||||
|
"prefer-destructuring": ["error", { object: true, array: false }]
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
// jshint esversion: 6
|
// jshint esversion: 6
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
@connect(state => ({
|
@connect(state => ({
|
||||||
categoricalAsBooleansMap: state.controls.categoricalAsBooleansMap,
|
categoricalAsBooleansMap: state.controls.categoricalAsBooleansMap,
|
||||||
colorScale: state.controls.colorScale,
|
colorScale: state.controls.colorScale,
|
||||||
colorAccessor: state.controls.colorAccessor
|
colorAccessor: state.controls.colorAccessor,
|
||||||
|
schema: _.get(state.controls.world, "schema", null)
|
||||||
}))
|
}))
|
||||||
class CategoryValue extends React.Component {
|
class CategoryValue extends React.Component {
|
||||||
toggleOff() {
|
toggleOff() {
|
||||||
@@ -34,7 +36,8 @@ class CategoryValue extends React.Component {
|
|||||||
value,
|
value,
|
||||||
colorAccessor,
|
colorAccessor,
|
||||||
colorScale,
|
colorScale,
|
||||||
i
|
i,
|
||||||
|
schema
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (!categoricalAsBooleansMap) return null;
|
if (!categoricalAsBooleansMap) return null;
|
||||||
@@ -42,6 +45,13 @@ class CategoryValue extends React.Component {
|
|||||||
const selected = categoricalAsBooleansMap[metadataField][value];
|
const selected = categoricalAsBooleansMap[metadataField][value];
|
||||||
/* this is the color scale, so add swatches below */
|
/* this is the color scale, so add swatches below */
|
||||||
const c = metadataField === colorAccessor;
|
const c = metadataField === colorAccessor;
|
||||||
|
let categories = null;
|
||||||
|
|
||||||
|
if (c && schema) {
|
||||||
|
categories = _.filter(schema.annotations.obs, {
|
||||||
|
name: colorAccessor
|
||||||
|
})[0].categories;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -78,7 +88,10 @@ class CategoryValue extends React.Component {
|
|||||||
marginLeft: 5,
|
marginLeft: 5,
|
||||||
width: 11,
|
width: 11,
|
||||||
height: 11,
|
height: 11,
|
||||||
backgroundColor: c ? colorScale(value) : "inherit"
|
backgroundColor:
|
||||||
|
c && categories
|
||||||
|
? colorScale(categories.indexOf(value))
|
||||||
|
: "inherit"
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
import { interpolateViridis } from "d3-scale-chromatic";
|
import { interpolateViridis, interpolateWarm } from "d3-scale-chromatic";
|
||||||
|
|
||||||
// create continuous color legend
|
// create continuous color legend
|
||||||
// http://bl.ocks.org/syntagmatic/e8ccca52559796be775553b467593a9f
|
// http://bl.ocks.org/syntagmatic/e8ccca52559796be775553b467593a9f
|
||||||
@@ -121,12 +121,12 @@ class ContinuousLegend extends React.Component {
|
|||||||
.remove();
|
.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorAccessor && colorScale) {
|
if (colorAccessor && colorScale && colorScale.range) {
|
||||||
/* fragile! continuous range is 0 to 1, not [#fa4b2c, ...], make this a flag? */
|
/* fragile! continuous range is 0 to 1, not [#fa4b2c, ...], make this a flag? */
|
||||||
if (colorScale.range()[0][0] !== "#") {
|
if (colorScale.range()[0][0] !== "#") {
|
||||||
continuous(
|
continuous(
|
||||||
"#continuous_legend",
|
"#continuous_legend",
|
||||||
d3.scaleSequential(interpolateViridis).domain(colorScale.domain()),
|
d3.scaleSequential(interpolateWarm).domain(colorScale.domain()),
|
||||||
colorAccessor
|
colorAccessor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
// jshint esversion: 6
|
// jshint esversion: 6
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
import { interpolateViridis } from "d3-scale-chromatic";
|
import {
|
||||||
|
interpolateViridis,
|
||||||
|
interpolateSpectral,
|
||||||
|
interpolateRainbow,
|
||||||
|
interpolateBlues,
|
||||||
|
interpolateWarm
|
||||||
|
} from "d3-scale-chromatic";
|
||||||
import * as globals from "../globals";
|
import * as globals from "../globals";
|
||||||
import parseRGB from "../util/parseRGB";
|
import parseRGB from "../util/parseRGB";
|
||||||
|
|
||||||
@@ -59,11 +65,17 @@ const updateCellColorsMiddleware = store => next => action => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (action.type === "color by categorical metadata") {
|
if (action.type === "color by categorical metadata") {
|
||||||
colorScale = d3.scaleOrdinal().range(globals.ordinalColors);
|
const categories = _.filter(s.controls.world.schema.annotations.obs, {
|
||||||
|
name: action.colorAccessor
|
||||||
|
})[0].categories;
|
||||||
|
|
||||||
|
colorScale = d3
|
||||||
|
.scaleSequential(interpolateRainbow)
|
||||||
|
.domain([0, categories.length]);
|
||||||
|
|
||||||
for (let i = 0; i < obsAnnotations.length; i += 1) {
|
for (let i = 0; i < obsAnnotations.length; i += 1) {
|
||||||
const obs = obsAnnotations[i];
|
const obs = obsAnnotations[i];
|
||||||
const c = colorScale(obs[action.colorAccessor]);
|
const c = colorScale(categories.indexOf(obs[action.colorAccessor]));
|
||||||
colorsByName[i] = c;
|
colorsByName[i] = c;
|
||||||
colorsByRGB[i] = parseRGB(c);
|
colorsByRGB[i] = parseRGB(c);
|
||||||
}
|
}
|
||||||
@@ -77,7 +89,7 @@ const updateCellColorsMiddleware = store => next => action => {
|
|||||||
|
|
||||||
for (let i = 0; i < obsAnnotations.length; i += 1) {
|
for (let i = 0; i < obsAnnotations.length; i += 1) {
|
||||||
const obs = obsAnnotations[i];
|
const obs = obsAnnotations[i];
|
||||||
const c = interpolateViridis(colorScale(obs[action.colorAccessor]));
|
const c = interpolateWarm(colorScale(obs[action.colorAccessor]));
|
||||||
colorsByName[i] = c;
|
colorsByName[i] = c;
|
||||||
colorsByRGB[i] = parseRGB(c);
|
colorsByRGB[i] = parseRGB(c);
|
||||||
}
|
}
|
||||||
@@ -95,7 +107,7 @@ const updateCellColorsMiddleware = store => next => action => {
|
|||||||
]); /* invert viridis... probably pass this scale through to others */
|
]); /* invert viridis... probably pass this scale through to others */
|
||||||
|
|
||||||
for (let i = 0, len = expression.length; i < len; i += 1) {
|
for (let i = 0, len = expression.length; i < len; i += 1) {
|
||||||
const c = interpolateViridis(colorScale(expression[i]));
|
const c = interpolateWarm(colorScale(expression[i]));
|
||||||
colorsByName[i] = c;
|
colorsByName[i] = c;
|
||||||
colorsByRGB[i] = parseRGB(c);
|
colorsByRGB[i] = parseRGB(c);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user