提交 ce04e1f5 authored 作者: 祖铭松's avatar 祖铭松

fix: 完善聚类热图

上级 db3a435b
...@@ -17,10 +17,10 @@ import { ...@@ -17,10 +17,10 @@ import {
setMaxMinNumber, setMaxMinNumber,
setHeatmap, setHeatmap,
setLegend, setLegend,
setBasisLegend, setConsensusLegend,
setAxisTitle, setAxisTitle,
setLabel, setLabel,
setBasisHeatmap setConsensusHeatmap
} from '../utils/index'; } from '../utils/index';
const chartRef = ref(null); const chartRef = ref(null);
...@@ -44,6 +44,8 @@ const generateChart = () => { ...@@ -44,6 +44,8 @@ const generateChart = () => {
let margin = 50; let margin = 50;
let radius = 3; let radius = 3;
let dendWidth = 0; let dendWidth = 0;
let xRatio = 330;
let yRatio = 500;
let xAxisLength = chartData[0].values.length; let xAxisLength = chartData[0].values.length;
const heatWidth = 2 * radius * xAxisLength; const heatWidth = 2 * radius * xAxisLength;
...@@ -75,6 +77,8 @@ const generateChart = () => { ...@@ -75,6 +77,8 @@ const generateChart = () => {
xAxisLength, xAxisLength,
heatWidth, heatWidth,
heatHeight, heatHeight,
xRatio,
yRatio,
...ret ...ret
}; };
...@@ -88,6 +92,7 @@ const generateChart = () => { ...@@ -88,6 +92,7 @@ const generateChart = () => {
for (let i = 0; i < chartDataArr.length; i++) { for (let i = 0; i < chartDataArr.length; i++) {
setRankChart(configObj, chartDataArr[i], i); setRankChart(configObj, chartDataArr[i], i);
setConsensus(configObj, chartDataArr[i], i);
} }
svgInstance.value = svg.node(); svgInstance.value = svg.node();
...@@ -98,8 +103,8 @@ const generateChart = () => { ...@@ -98,8 +103,8 @@ const generateChart = () => {
const setRankChart = (config, chartData, index) => { const setRankChart = (config, chartData, index) => {
const title = `rank = ${index + 2}`; const title = `rank = ${index + 2}`;
let xRatio = 350; let xRatio = config.xRatio;
let yRatio = 500; let yRatio = config.yRatio;
if (index <= 2) { if (index <= 2) {
xRatio = index * xRatio; xRatio = index * xRatio;
yRatio = 0; yRatio = 0;
...@@ -109,7 +114,7 @@ const setRankChart = (config, chartData, index) => { ...@@ -109,7 +114,7 @@ const setRankChart = (config, chartData, index) => {
let xAxisLength = chartData[0].values.length; let xAxisLength = chartData[0].values.length;
// 位置 // 位置
const position = { const position = {
title: [config.margin + xRatio, 0 + yRatio], title: [config.margin + xRatio, yRatio],
heatmap: [10 + xRatio, config.margin + yRatio], heatmap: [10 + xRatio, config.margin + yRatio],
legend: [xAxisLength * (config.radius * 2) + 70 + xRatio, config.margin + yRatio], legend: [xAxisLength * (config.radius * 2) + 70 + xRatio, config.margin + yRatio],
axisLabel: [xAxisLength * (config.radius * 2) + 12 + xRatio, config.margin + yRatio] axisLabel: [xAxisLength * (config.radius * 2) + 12 + xRatio, config.margin + yRatio]
...@@ -146,8 +151,25 @@ const setRankChart = (config, chartData, index) => { ...@@ -146,8 +151,25 @@ const setRankChart = (config, chartData, index) => {
setLabel(configObj); setLabel(configObj);
}; };
const setConsensus = (config) => { const setConsensus = (config, data, index) => {
const chartData = chartMockData.slice(0, 2); const chartData = data.slice(0, 2);
const title = 'consensus';
let xRatio = config.xRatio;
let yRatio = config.yRatio;
if (index <= 2) {
xRatio = index * xRatio;
yRatio = 0;
} else if (index == 3) {
xRatio = 0;
}
let xAxisLength = chartData[0].values.length;
// 位置
const position = {
title: [xAxisLength * (config.radius * 2) + 170 + xRatio, 60 + yRatio],
heatmap: [10 + xRatio, config.margin - 20 + yRatio],
legend: [xAxisLength * (config.radius * 2) + 120 + xRatio, config.margin + 20 + yRatio],
axisLabel: [xAxisLength * (config.radius * 2) + 12 + xRatio, config.margin + yRatio]
};
// max/min number // max/min number
const { maxNumber, minNumber } = setMaxMinNumber(chartData); const { maxNumber, minNumber } = setMaxMinNumber(chartData);
// root config // root config
...@@ -155,12 +177,12 @@ const setConsensus = (config) => { ...@@ -155,12 +177,12 @@ const setConsensus = (config) => {
// color config // color config
const colors = ['#9D9FFF', '#F57BFF', '#3AB1FF', '#D38BFF', '#00C745', '#F4952C']; const colors = ['#9D9FFF', '#F57BFF', '#3AB1FF', '#D38BFF', '#00C745', '#F4952C'];
const color = setColor(minNumber, maxNumber, colors); const color = setColor(minNumber, maxNumber, colors);
const configObj = { ...config, root, orderingx, maxNumber, minNumber, color }; const configObj = { ...config, root, orderingx, maxNumber, minNumber, color, title, position };
const heatmapRect = setBasisHeatmap(configObj); const heatmapRect = setConsensusHeatmap(configObj);
// tips // tips
setTips(heatmapRect); setTips(heatmapRect);
// legend // legend
config.show_legend && setBasisLegend(configObj); config.show_legend && setConsensusLegend(configObj);
}; };
onMounted(() => { onMounted(() => {
......
...@@ -142,15 +142,15 @@ export const setHeatmap = (config) => { ...@@ -142,15 +142,15 @@ export const setHeatmap = (config) => {
.attr('fill', config.color()); .attr('fill', config.color());
}; };
// Basis heatmap // Consensus heatmap
export const setBasisHeatmap = (config) => { export const setConsensusHeatmap = (config) => {
return config.svg return config.svg
.append('g') .append('g')
.attr('transform', `translate(${config.margin + 0}, ${config.margin})`) .attr('transform', `translate(${config.position.heatmap[0]}, ${config.position.heatmap[1]})`)
.selectAll('g') .selectAll('g')
.data(config.root.leaves()) .data(config.root.leaves())
.join('g') .join('g')
.attr('transform', (d, i) => `translate(0, ${130 + config.radius * 2 * i})`) .attr('transform', (d, i) => `translate(0, ${config.radius * 2 * i})`)
.selectAll('rect') .selectAll('rect')
.data((d) => d.data.values.map((e, i) => d.data.values[config.orderingx[i]])) .data((d) => d.data.values.map((e, i) => d.data.values[config.orderingx[i]]))
.join('rect') .join('rect')
...@@ -161,7 +161,6 @@ export const setBasisHeatmap = (config) => { ...@@ -161,7 +161,6 @@ export const setBasisHeatmap = (config) => {
.attr('fill', config.color()); .attr('fill', config.color());
}; };
// legend // legend
export const setLegend = (config) => { export const setLegend = (config) => {
const legendData = [...Array.from({ length: config.maxNumber }, (item, i) => i)]; const legendData = [...Array.from({ length: config.maxNumber }, (item, i) => i)];
...@@ -184,28 +183,28 @@ export const setLegend = (config) => { ...@@ -184,28 +183,28 @@ export const setLegend = (config) => {
); );
}; };
// Basis legend // Consensus legend
export const setBasisLegend = (config) => { export const setConsensusLegend = (config) => {
const legendData = [...Array.from({ length: config.maxNumber }, (item, i) => i)]; const legendData = [...Array.from({ length: config.maxNumber }, (item, i) => i)];
const textX = 0 + config.xAxisLength * (config.radius * 2) + 180
config.svg.append('text') config.svg.append('text')
.attr('x', textX) .attr('x', config.position.title[0])
.attr('y', config.height / 3 - 110) .attr('y', config.position.title[1])
.attr('fill', '#333333') .attr('fill', '#333333')
.attr('font-size', '20px') .attr('fill', config.titleConfig.color)
.attr('font-size', `${config.titleConfig.fontSize}px`)
.attr('font-family', `${config.titleConfig.fontFamily}`) .attr('font-family', `${config.titleConfig.fontFamily}`)
.attr('font-style', 'normal') .attr('font-style', `${config.titleConfig.fontStyle}`)
.attr('font-weight', 'bold') .attr('font-weight', `${config.titleConfig.fontWeight}`)
.style('text-anchor', 'middle') .style('text-anchor', 'middle')
.text('basis'); .text('consensus');
config.svg.append('g') config.svg.append('g')
.attr('transform', `translate(${config.position.legend[0]}, ${config.position.legend[1]})`)
.selectAll() .selectAll()
.data(legendData) .data(legendData)
.join('g') .join('g')
.attr('transform', (d, i, nodes) => `translate(${0 + config.xAxisLength * (config.radius * 2) + 160}, ${config.height / 3 + (nodes.length / 2 - i - 1) * 21 - 50})`) .attr('transform', (d, i, nodes) => `translate(0, ${i * 21})`)
.call((g) => g.append('rect').attr('width', 15).attr('height', 15).attr('fill', config.color())) .call((g) => g.append('rect').attr('width', 15).attr('height', 15).attr('fill', config.color()))
.call((g) => .call((g) =>
g g
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论