Commit 9b7af3ff authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Handle color with d3-scale-chromatic

parent 3e3594c5
import { GeneData, GenomeBrowserData, State } from "./types"; import { GeneData, GenomeBrowserData, State } from "./types";
import { select, event } from "d3-selection"; import { select, event } from "d3-selection";
import { scaleLinear } from "d3-scale"; import { scaleOrdinal } from "d3-scale";
import GenomeBrowser from "./component/genome-browser"; import GenomeBrowser from "./component/genome-browser";
import { color } from "d3"; import { color } from "d3";
import { schemeSet1 } from "d3-scale-chromatic"; import { schemeSet1, schemeDark2, schemeCategory10 } from "d3-scale-chromatic";
const width = 1500; const width = 1500;
const height = 300; const height = 300;
const genomeBrowserComponent = GenomeBrowser(); const genomeBrowserComponent = GenomeBrowser();
const geneColor = scaleOrdinal(
// schemeDark2
// schemeCategory10
schemeSet1
);
const geneData: GeneData[] = [ const geneData: GeneData[] = [
{ {
name: "gene 1", name: "gene 1",
...@@ -35,7 +41,14 @@ const geneData: GeneData[] = [ ...@@ -35,7 +41,14 @@ const geneData: GeneData[] = [
name: "gene 4", name: "gene 4",
strand: "+", strand: "+",
begin: 22391, begin: 22391,
end: 25207, end: 23207,
gene: "ileS"
},
{
name: "gene 4",
strand: "+",
begin: 23391,
end: 24207,
gene: "ileS" gene: "ileS"
}, },
{ {
...@@ -156,8 +169,8 @@ function getGenomeBrowserData(state: State) { ...@@ -156,8 +169,8 @@ function getGenomeBrowserData(state: State) {
genes: genes.filter( genes: genes.filter(
(gene: GeneData) => gene.end > window[0] && gene.begin < window[1] (gene: GeneData) => gene.end > window[0] && gene.begin < window[1]
).map(function (gene) { ).map(function (gene) {
const fill = gene.strand === "+" ? color("darkred") : color("darkblue"); const fill = color(geneColor(gene.strand));
const stroke = (fill) ? fill.darker(1).toString() : "lighgray" const stroke = (fill) ? fill.darker(1).toString() : "lighgray";
return { return {
...gene, ...gene,
eventHandler: { eventHandler: {
...@@ -173,9 +186,6 @@ function getGenomeBrowserData(state: State) { ...@@ -173,9 +186,6 @@ function getGenomeBrowserData(state: State) {
interval: window interval: window
} }
}, },
// eventHandler: {
// }
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment