- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是绘制平行四边形,将一家公司在一个业务季度的排名与其在下一业务季度的新排名联系起来。我正在使用 rects 来代表每个公司或 manager
。 (每列是一个商业季度)。我的步骤/进度:
.each()
通过检索每个矩形的 .attr()
来存储平行四边形的顶点 x
,y
和 高度
。Fidelity
在第一列后从 #1 变为 #2)。这就是问题开始的地方,基本上,我的 y1
和 y0
都停留在相同的值,我不确定为什么。
var margins = {top:20, bottom:300, left:30, right:100};
var height = 600;
var width = 900;
var totalWidth = width+margins.left+margins.right;
var totalHeight = height+margins.top+margins.bottom;
var outerRadius = (400 / 2);
var innerRadius = 15;
var svg = d3.select('body')
.append('svg')
.attr('width', totalWidth)
.attr('height', totalHeight);
var graphGroup = svg.append('g')
.attr('transform', "translate("+margins.left+","+margins.top+ ")");
var heightScale = d3.scaleLinear()
.domain([.01,.09])
.range([7,50]);
/*
var tsvData = d3.tsv('market-share-change.tsv');
tsvData.then(function(rawData) {
var data = rawData.map(function(d) {
return { manager:d.manager, t1:+d.t1, t2:+d.t2, t3:+d.t3}
});
})
*/
var data = [[{'manager': 'Mirae Asset', 'share': 0.016},
{'manager': 'Manulife', 'share': 0.015},
{'manager': 'ChinaAMC', 'share': 0.012},
{'manager': 'Principal', 'share': 0.015},
{'manager': 'Aberdeen Standard', 'share': 0.013},
{'manager': 'CSOP', 'share': 0.015},
{'manager': 'BOCI-Prudential', 'share': 0.019},
{'manager': 'Allianz', 'share': 0.016},
{'manager': 'HSBC', 'share': 0.027},
{'manager': 'Deutsche Bank', 'share': 0.014},
{'manager': 'Invesco', 'share': 0.025},
{'manager': 'First State', 'share': 0.033},
{'manager': 'JP Morgan', 'share': 0.041},
{'manager': 'Value Partners', 'share': 0.04},
{'manager': 'Schroders', 'share': 0.051},
{'manager': 'Hang Seng', 'share': 0.063},
{'manager': 'UBS', 'share': 0.056},
{'manager': 'SSgA', 'share': 0.066},
{'manager': 'Fidelity', 'share': 0.088},
{'manager': 'BlackRock', 'share': 0.084}],
[{'manager': 'Mirae Asset', 'share': 0.013},
{'manager': 'Manulife', 'share': 0.014},
{'manager': 'ChinaAMC', 'share': 0.013},
{'manager': 'Principal', 'share': 0.018},
{'manager': 'Aberdeen Standard', 'share': 0.014},
{'manager': 'CSOP', 'share': 0.019},
{'manager': 'BOCI-Prudential', 'share': 0.02},
{'manager': 'Allianz', 'share': 0.015},
{'manager': 'HSBC', 'share': 0.023},
{'manager': 'Deutsche Bank', 'share': 0.02},
{'manager': 'Invesco', 'share': 0.02},
{'manager': 'First State', 'share': 0.029},
{'manager': 'JP Morgan', 'share': 0.04},
{'manager': 'Value Partners', 'share': 0.039},
{'manager': 'Schroders', 'share': 0.051},
{'manager': 'Hang Seng', 'share': 0.063},
{'manager': 'UBS', 'share': 0.055},
{'manager': 'SSgA', 'share': 0.065},
{'manager': 'Fidelity', 'share': 0.088},
{'manager': 'BlackRock', 'share': 0.101}],
[{'manager': 'Mirae Asset', 'share': 0.012},
{'manager': 'Manulife', 'share': 0.014},
{'manager': 'ChinaAMC', 'share': 0.014},
{'manager': 'Principal', 'share': 0.017},
{'manager': 'Aberdeen Standard', 'share': 0.017},
{'manager': 'CSOP', 'share': 0.018},
{'manager': 'BOCI-Prudential', 'share': 0.018},
{'manager': 'Allianz', 'share': 0.018},
{'manager': 'HSBC', 'share': 0.023},
{'manager': 'Deutsche Bank', 'share': 0.023},
{'manager': 'Invesco', 'share': 0.023},
{'manager': 'First State', 'share': 0.029},
{'manager': 'JP Morgan', 'share': 0.041},
{'manager': 'Value Partners', 'share': 0.044},
{'manager': 'Schroders', 'share': 0.048},
{'manager': 'Hang Seng', 'share': 0.056},
{'manager': 'UBS', 'share': 0.061},
{'manager': 'SSgA', 'share': 0.062},
{'manager': 'Fidelity', 'share': 0.087},
{'manager': 'BlackRock', 'share': 0.096}]];
var poly = [
{'x':0,'y':0},
{'x':0,'y':0}
];
var multiPoly1 = d3.range(20).map(()=>JSON.parse(JSON.stringify(poly)));
var multiPoly2 = d3.range(20).map(()=>JSON.parse(JSON.stringify(poly)));
/*
for (var k=0; k <(data[0].length); k++) {
polyMaster[0][k].push({'manager':data[0][k].manager})
};
*/
var colorMap = {
'Fidelity':"#003366",
'BlackRock':"#366092",
'SSgA':"#4f81b9",
'Hang Seng':"#95b3d7",
'UBS':"#b8cce4",
'Schroders':"#e7eef8",
'JP Morgan':"#a6a6a6",
'Value Partners':"#d9d9d9",
'Yuanta':"#ffffcc",
'First State':"#ffffcc",
'HSBC':'#f6d18b',
'Invesco':'#e4a733',
'BOCI-Prudential':"#b29866",
'Allianz':'#a6a6a6',
'Mirae Asset':'#d9d9d9',
'Manulife':'#e7eef8',
'CSOP':'#b8cce4',
'Principal':'#95b3d7',
'Deutsche Bank':'#4f81b9',
'Aberdeen Standard':'#366092',
'ChinaAMC':'#003366'
};
for (var j=0; j <(data.length); j++) {
var className = "column"+String(j);
let counterRect = 0,
counterText = 0;
var spacing = 170;
var sortedData = data[j].sort(function(a,b) {
return b.share - a.share;
});
var column = graphGroup.selectAll(className)
.data(sortedData)
.attr('class', className)
.enter().append("g");
column.append("rect")
.attr('class','rect'+String(j))
.attr("width", 120)
.attr("height", function(d) {
return heightScale(d.share)
})
.attr('x', function(d) {return j*spacing})
.attr('y', function(d, i) {
let previous = counterRect;
return (counterRect += heightScale(d.share)+2, previous)
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][0].x = 120;
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][0].y = parseFloat(d3.select(this).attr('y'));
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][1].x = 120;
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][1].y = parseFloat(d3.select(this).attr('y'))+parseFloat(d3.select(this).attr('height'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][1].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][1].y = parseFloat(d3.select(this).attr('y'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][0].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][0].y = parseFloat(d3.select(this).attr('y'))+parseFloat(d3.select(this).attr('height'));
}
})
.style('fill',function(d,i) {return colorMap[d.manager]});
column.append("text")
.attr('x', function(d) {return j*spacing+60})
.attr('y', function(d, i) {
let previous = counterText;
return (counterText += heightScale(d.share)+2, previous + (heightScale(d.share)/2))
})
.attr("dominant-baseline", "central")
.attr('text-anchor', 'middle')
.text(function(d) {
return d.manager;
});
var managerList = [];
for (var k = 0; k < sortedData.length; k++)
managerList.push({'manager':sortedData[k].manager});
var tempList1 = [];
for (var k = 0; k < managerList.length; k++)
tempList1.push({'manager': managerList[k], 'x1': multiPoly1[k][0].x, 'y1':multiPoly1[k][0].y, 'x2':multiPoly1[k][1].x, 'y2':multiPoly1[k][1].y });
var tempList2 = [];
for (var k = 0; k < managerList.length; k++)
tempList2.push({'manager': managerList[k], 'x3': multiPoly2[k][1].x, 'y3':multiPoly2[k][1].y, 'x4':multiPoly2[k][0].x, 'y4':multiPoly2[k][0].y });
var combinedList = [];
const list1ByManager = tempList1.reduce((a, item) => {
a[item.manager] = item;
return a;
}, {});
var combinedList = tempList2.map((item2) => ({
...list1ByManager[item2.manager],
...item2
}));
console.log(combinedList)
var polyMaster = [];
for (var k = 0; k < managerList.length; k++) {
var tempItem = [
{'x':combinedList[k].x1, 'y':combinedList[k].y1},
{'x':combinedList[k].x2, 'y':combinedList[k].y2},
{'x':combinedList[k].x3, 'y':combinedList[k].y3},
{'x':combinedList[k].x4, 'y':combinedList[k].y4},
];
polyMaster.push(tempItem);
}
console.log(polyMaster)
};
graphGroup.selectAll("polygon")
.data(polyMaster)
.enter().append("polygon")
.attr("points",function(d) {
return d.map(function(d) { return [d.x,d.y].join(","); }).join(" ");})
.attr("stroke","black")
.attr("stroke-width",2);
<script src="https://d3js.org/d3.v5.min.js"></script>
检查控制台日志中的 tempList1
和 tempList2
确认我确实正确存储了所有值,但出于某种原因,当我尝试将这两个数组合并到 combinedList
y
未正确合并。相关代码:
var combinedList = [];
const list1ByManager = tempList1.reduce((a, item) => {
a[item.manager] = item;
return a;
}, {});
var combinedList = tempList2.map((item2) => ({
...list1ByManager[item2.manager],
...item2
}));
我是否错误地合并了 tempList1
和 tempList2
?为什么 y
未如代码段所示保留?
(换句话说,平行四边形(黑色)不应该都画在第一列的底部,它们应该完美地连接到相应的公司——如果你愿意的话,可以形成一座桥,让眼睛容易看到通过跟踪公司在第一列中的位置到其在第二列中的新位置,查看任何一家公司的排名变化)
注意:我现在只关心第一列和第二列之间的平行四边形。在弄清楚这么多之前,我不会尝试使用第三列。
最佳答案
我找到了一个解决方案,但它很丑陋,一点也不简洁。为了节省时间,我不得不接受它。我可能很快会重新访问这段代码,我很想看看其他人是否有改进的想法。
最明显的异端代码是通过蛮力填充对象。我一直遇到无法使用理解或 for 循环创建对象的错误。
即使您没有耐心浏览我所有糟糕的代码,您至少可以看到完成的结果——它看起来很酷(如果我这么说的话)。
var margins = {top:20, bottom:300, left:30, right:100};
var height = 600;
var width = 900;
var totalWidth = width+margins.left+margins.right;
var totalHeight = height+margins.top+margins.bottom;
var outerRadius = (400 / 2);
var innerRadius = 15;
var svg = d3.select('body')
.append('svg')
.attr('width', totalWidth)
.attr('height', totalHeight);
var graphGroup = svg.append('g')
.attr('transform', "translate("+margins.left+","+margins.top+ ")");
var heightScale = d3.scaleLinear()
.domain([.01,.09])
.range([7,50]);
/*
var tsvData = d3.tsv('market-share-change.tsv');
tsvData.then(function(rawData) {
var data = rawData.map(function(d) {
return { manager:d.manager, t1:+d.t1, t2:+d.t2, t3:+d.t3}
});
})
*/
var data = [[{'manager': 'Mirae Asset', 'share': 0.016},
{'manager': 'Manulife', 'share': 0.015},
{'manager': 'ChinaAMC', 'share': 0.012},
{'manager': 'Principal', 'share': 0.015},
{'manager': 'Aberdeen Standard', 'share': 0.013},
{'manager': 'CSOP', 'share': 0.015},
{'manager': 'BOCI-Prudential', 'share': 0.019},
{'manager': 'Allianz', 'share': 0.016},
{'manager': 'HSBC', 'share': 0.027},
{'manager': 'DWS', 'share': 0.014},
{'manager': 'Invesco', 'share': 0.025},
{'manager': 'First State', 'share': 0.033},
{'manager': 'JP Morgan', 'share': 0.041},
{'manager': 'Value Partners', 'share': 0.04},
{'manager': 'Schroders', 'share': 0.051},
{'manager': 'Hang Seng', 'share': 0.063},
{'manager': 'UBS', 'share': 0.056},
{'manager': 'SSgA', 'share': 0.066},
{'manager': 'Fidelity', 'share': 0.088},
{'manager': 'BlackRock', 'share': 0.084}],
[{'manager': 'Mirae Asset', 'share': 0.013},
{'manager': 'Manulife', 'share': 0.014},
{'manager': 'ChinaAMC', 'share': 0.013},
{'manager': 'Principal', 'share': 0.018},
{'manager': 'Aberdeen Standard', 'share': 0.014},
{'manager': 'CSOP', 'share': 0.019},
{'manager': 'BOCI-Prudential', 'share': 0.02},
{'manager': 'Allianz', 'share': 0.015},
{'manager': 'HSBC', 'share': 0.023},
{'manager': 'DWS', 'share': 0.02},
{'manager': 'Invesco', 'share': 0.02},
{'manager': 'First State', 'share': 0.029},
{'manager': 'JP Morgan', 'share': 0.04},
{'manager': 'Value Partners', 'share': 0.039},
{'manager': 'Schroders', 'share': 0.051},
{'manager': 'Hang Seng', 'share': 0.063},
{'manager': 'UBS', 'share': 0.055},
{'manager': 'SSgA', 'share': 0.065},
{'manager': 'Fidelity', 'share': 0.088},
{'manager': 'BlackRock', 'share': 0.101}],
[{'manager': 'Mirae Asset', 'share': 0.012},
{'manager': 'Manulife', 'share': 0.014},
{'manager': 'ChinaAMC', 'share': 0.014},
{'manager': 'Principal', 'share': 0.017},
{'manager': 'Aberdeen Standard', 'share': 0.017},
{'manager': 'CSOP', 'share': 0.018},
{'manager': 'BOCI-Prudential', 'share': 0.018},
{'manager': 'Allianz', 'share': 0.018},
{'manager': 'HSBC', 'share': 0.023},
{'manager': 'DWS', 'share': 0.023},
{'manager': 'Invesco', 'share': 0.023},
{'manager': 'First State', 'share': 0.029},
{'manager': 'JP Morgan', 'share': 0.041},
{'manager': 'Value Partners', 'share': 0.044},
{'manager': 'Schroders', 'share': 0.048},
{'manager': 'Hang Seng', 'share': 0.056},
{'manager': 'UBS', 'share': 0.061},
{'manager': 'SSgA', 'share': 0.062},
{'manager': 'Fidelity', 'share': 0.087},
{'manager': 'BlackRock', 'share': 0.096}]];
var poly = [
{'x':0,'y':0},
{'x':0,'y':0}
];
var multiPoly1 = d3.range(20).map(()=>JSON.parse(JSON.stringify(poly)));
var multiPoly2 = d3.range(20).map(()=>JSON.parse(JSON.stringify(poly)));
var multiPoly3 = d3.range(20).map(()=>JSON.parse(JSON.stringify(poly)));
/*
for (var k=0; k <(data[0].length); k++) {
polyMaster[0][k].push({'manager':data[0][k].manager})
};
*/
var colorMap = {
'Fidelity':"#003366",
'BlackRock':"#366092",
'SSgA':"#4f81b9",
'Hang Seng':"#95b3d7",
'UBS':"#b8cce4",
'Schroders':"#e7eef8",
'JP Morgan':"#a6a6a6",
'Value Partners':"#d9d9d9",
'Yuanta':"#ffffcc",
'First State':"#ffffcc",
'HSBC':'#f6d18b',
'Invesco':'#e4a733',
'BOCI-Prudential':"#b29866",
'Allianz':'#a6a6a6',
'Mirae Asset':'#d9d9d9',
'Manulife':'#e7eef8',
'CSOP':'#b8cce4',
'Principal':'#95b3d7',
'DWS':'#4f81b9',
'Aberdeen Standard':'#366092',
'ChinaAMC':'#003366'
};
for (var j=0; j <(data.length); j++) {
var className = "column"+String(j);
let counterRect = 0,
counterText = 0;
var spacing = 170;
var sortedData = data[j].sort(function(a,b) {
return b.share - a.share;
});
var column = graphGroup.selectAll(className)
.data(sortedData)
.attr('class', className)
.enter().append("g");
column.append("rect")
.attr('class','rect'+String(j))
.attr("width", 120)
.attr("height", function(d) {
return heightScale(d.share)
})
.attr('x', function(d) {return j*spacing})
.attr('y', function(d, i) {
let previous = counterRect;
return (counterRect += heightScale(d.share)+2, previous)
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][0].x = 120;
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][0].y = parseFloat(d3.select(this).attr('y'));
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][1].x = 120;
}
})
.each(function(d,i) {
if (j==0) {
multiPoly1[i][1].y = parseFloat(d3.select(this).attr('y'))+parseFloat(d3.select(this).attr('height'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][1].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][1].y = parseFloat(d3.select(this).attr('y'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][0].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==1) {
multiPoly2[i][0].y = parseFloat(d3.select(this).attr('y'))+parseFloat(d3.select(this).attr('height'));
}
})
.each(function(d,i) {
if (j==2) {
multiPoly3[i][1].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==2) {
multiPoly3[i][1].y = parseFloat(d3.select(this).attr('y'));
}
})
.each(function(d,i) {
if (j==2) {
multiPoly3[i][0].x = parseFloat(d3.select(this).attr('x'));
}
})
.each(function(d,i) {
if (j==2) {
multiPoly3[i][0].y = parseFloat(d3.select(this).attr('y'))+parseFloat(d3.select(this).attr('height'));
}
})
.style('fill',function(d,i) {return colorMap[d.manager]});
column.append("text")
.attr('x', function(d) {return j*spacing+60})
.attr('y', function(d, i) {
let previous = counterText;
return (counterText += heightScale(d.share)+2, previous + (heightScale(d.share)/2))
})
.attr("dominant-baseline", "central")
.attr('text-anchor', 'middle')
.text(function(d) {
return d.manager;
});
if (j==0) {
var managerList = [];
for (var k = 0; k < sortedData.length; k++)
managerList.push({'manager':sortedData[k].manager});
}
if (j==0) {
var tempList1 = [];
for (var k = 0; k < managerList.length; k++)
tempList1.push({'manager': managerList[k], 'x1': multiPoly1[k][0].x, 'y1':multiPoly1[k][0].y, 'x2':multiPoly1[k][1].x, 'y2':multiPoly1[k][1].y });
}
var tempList2 = [];
for (var k = 0; k < managerList.length; k++)
tempList2.push({'manager': managerList[k], 'x3': multiPoly2[k][1].x, 'y3':multiPoly2[k][1].y, 'x4':multiPoly2[k][0].x, 'y4':multiPoly2[k][0].y });
if (j==2) {
var tempList3 = [];
for (var k = 0; k < managerList.length; k++) {
tempList3.push({'manager': managerList[k], 'x3': multiPoly3[k][1].x, 'y3':multiPoly3[k][1].y, 'x4':multiPoly3[k][0].x, 'y4':multiPoly3[k][0].y });
}
}
//var combinedList = [];
};
var list1Index = {};
var list2Index = {};
var list3Index = {};
var list2Index2 = {};
/*
for (var k = 0; k < managerList.length; k++) {
list1Index[managerList[k]] = {'x1': tempList1[k].x1, 'y1':tempList1[k].y1, 'x2':tempList1[k].x2, 'y2':tempList1[k].y2}
};
*/
list1Index['Fidelity'] = {'x1': tempList1[0].x1, 'y1':tempList1[0].y2, 'x2':tempList1[0].x2, 'y2':tempList1[0].y1};
list1Index['BlackRock'] = {'x1': tempList1[1].x1, 'y1':tempList1[1].y2, 'x2':tempList1[1].x2, 'y2':tempList1[1].y1};
list1Index['SSgA'] = {'x1': tempList1[2].x1, 'y1':tempList1[2].y2, 'x2':tempList1[2].x2, 'y2':tempList1[2].y1};
list1Index['Hang Seng'] = {'x1': tempList1[3].x1, 'y1':tempList1[3].y2, 'x2':tempList1[3].x2, 'y2':tempList1[3].y1};
list1Index['UBS'] = {'x1': tempList1[4].x1, 'y1':tempList1[4].y2, 'x2':tempList1[4].x2, 'y2':tempList1[4].y1};
list1Index['Schroders'] = {'x1': tempList1[5].x1, 'y1':tempList1[5].y2, 'x2':tempList1[5].x2, 'y2':tempList1[5].y1};
list1Index['JP Morgan'] = {'x1': tempList1[6].x1, 'y1':tempList1[6].y2, 'x2':tempList1[6].x2, 'y2':tempList1[6].y1};
list1Index['Value Partners'] = {'x1': tempList1[7].x1, 'y1':tempList1[7].y2, 'x2':tempList1[7].x2, 'y2':tempList1[7].y1};
list1Index['First State'] = {'x1': tempList1[8].x1, 'y1':tempList1[8].y2, 'x2':tempList1[8].x2, 'y2':tempList1[8].y1};
list1Index['HSBC'] = {'x1': tempList1[9].x1, 'y1':tempList1[9].y2, 'x2':tempList1[9].x2, 'y2':tempList1[9].y1};
list1Index['Invesco'] = {'x1': tempList1[10].x1, 'y1':tempList1[10].y2, 'x2':tempList1[10].x2, 'y2':tempList1[10].y1};
list1Index['BOCI-Prudential'] = {'x1': tempList1[11].x1, 'y1':tempList1[11].y2, 'x2':tempList1[11].x2, 'y2':tempList1[11].y1};
list1Index['Allianz'] = {'x1': tempList1[12].x1, 'y1':tempList1[12].y2, 'x2':tempList1[12].x2, 'y2':tempList1[12].y1};
list1Index['Mirae Asset'] = {'x1': tempList1[13].x1, 'y1':tempList1[13].y2, 'x2':tempList1[13].x2, 'y2':tempList1[13].y1};
list1Index['Manulife'] = {'x1': tempList1[14].x1, 'y1':tempList1[14].y2, 'x2':tempList1[14].x2, 'y2':tempList1[14].y1};
list1Index['CSOP'] = {'x1': tempList1[15].x1, 'y1':tempList1[15].y2, 'x2':tempList1[15].x2, 'y2':tempList1[15].y1};
list1Index['Principal'] = {'x1': tempList1[16].x1, 'y1':tempList1[16].y2, 'x2':tempList1[16].x2, 'y2':tempList1[16].y1};
list1Index['DWS'] = {'x1': tempList1[17].x1, 'y1':tempList1[17].y2, 'x2':tempList1[17].x2, 'y2':tempList1[17].y1};
list1Index['Aberdeen Standard'] = {'x1': tempList1[18].x1, 'y1':tempList1[18].y2, 'x2':tempList1[18].x2, 'y2':tempList1[18].y1};
list1Index['ChinaAMC'] = {'x1': tempList1[19].x1, 'y1':tempList1[19].y2, 'x2':tempList1[19].x2, 'y2':tempList1[19].y1};
list2Index['BlackRock'] = {'x3': tempList2[0].x3, 'y3':tempList2[0].y3, 'x4':tempList2[0].x4, 'y4':tempList2[0].y4};
list2Index['Fidelity'] = {'x3': tempList2[1].x3, 'y3':tempList2[1].y3, 'x4':tempList2[1].x4, 'y4':tempList2[1].y4};
list2Index['SSgA'] = {'x3': tempList2[2].x3, 'y3':tempList2[2].y3, 'x4':tempList2[2].x4, 'y4':tempList2[2].y4};
list2Index['Hang Seng'] = {'x3': tempList2[3].x3, 'y3':tempList2[3].y3, 'x4':tempList2[3].x4, 'y4':tempList2[3].y4};
list2Index['UBS'] = {'x3': tempList2[4].x3, 'y3':tempList2[4].y3, 'x4':tempList2[4].x4, 'y4':tempList2[4].y4};
list2Index['Schroders'] = {'x3': tempList2[5].x3, 'y3':tempList2[5].y3, 'x4':tempList2[5].x4, 'y4':tempList2[5].y4};
list2Index['JP Morgan'] = {'x3': tempList2[6].x3, 'y3':tempList2[6].y3, 'x4':tempList2[6].x4, 'y4':tempList2[6].y4};
list2Index['Value Partners'] = {'x3': tempList2[7].x3, 'y3':tempList2[7].y3, 'x4':tempList2[7].x4, 'y4':tempList2[7].y4};
list2Index['First State'] = {'x3': tempList2[8].x3, 'y3':tempList2[8].y3, 'x4':tempList2[8].x4, 'y4':tempList2[8].y4};
list2Index['HSBC'] = {'x3': tempList2[9].x3, 'y3':tempList2[9].y3, 'x4':tempList2[9].x4, 'y4':tempList2[9].y4};
list2Index['Invesco'] = {'x3': tempList2[10].x3, 'y3':tempList2[10].y3, 'x4':tempList2[10].x4, 'y4':tempList2[10].y4};
list2Index['BOCI-Prudential'] = {'x3': tempList2[11].x3, 'y3':tempList2[11].y3, 'x4':tempList2[11].x4, 'y4':tempList2[11].y4};
list2Index['DWS'] = {'x3': tempList2[12].x3, 'y3':tempList2[12].y3, 'x4':tempList2[12].x4, 'y4':tempList2[12].y4};
list2Index['CSOP'] = {'x3': tempList2[13].x3, 'y3':tempList2[13].y3, 'x4':tempList2[13].x4, 'y4':tempList2[13].y4};
list2Index['Principal'] = {'x3': tempList2[14].x3, 'y3':tempList2[14].y3, 'x4':tempList2[14].x4, 'y4':tempList2[14].y4};
list2Index['Allianz'] = {'x3': tempList2[15].x3, 'y3':tempList2[15].y3, 'x4':tempList2[15].x4, 'y4':tempList2[15].y4};
list2Index['Manulife'] = {'x3': tempList2[16].x3, 'y3':tempList2[16].y3, 'x4':tempList2[16].x4, 'y4':tempList2[16].y4};
list2Index['Aberdeen Standard'] = {'x3': tempList2[17].x3, 'y3':tempList2[17].y3, 'x4':tempList2[17].x4, 'y4':tempList2[17].y4};
list2Index['ChinaAMC'] = {'x3': tempList2[18].x3, 'y3':tempList2[18].y3, 'x4':tempList2[18].x4, 'y4':tempList2[18].y4};
list2Index['Mirae Asset'] = {'x3': tempList2[19].x3, 'y3':tempList2[19].y3, 'x4':tempList2[19].x4, 'y4':tempList2[19].y4};
list2Index2['BlackRock'] = {'x1': tempList2[0].x3, 'y1':tempList2[0].y3, 'x2':tempList2[0].x4, 'y2':tempList2[0].y4};
list2Index2['Fidelity'] = {'x1': tempList2[1].x3, 'y1':tempList2[1].y3, 'x2':tempList2[1].x4, 'y2':tempList2[1].y4};
list2Index2['SSgA'] = {'x1': tempList2[2].x3, 'y1':tempList2[2].y3, 'x2':tempList2[2].x4, 'y2':tempList2[2].y4};
list2Index2['Hang Seng'] = {'x1': tempList2[3].x3, 'y1':tempList2[3].y3, 'x2':tempList2[3].x4, 'y2':tempList2[3].y4};
list2Index2['UBS'] = {'x1': tempList2[4].x3, 'y1':tempList2[4].y3, 'x2':tempList2[4].x4, 'y2':tempList2[4].y4};
list2Index2['Schroders'] = {'x1': tempList2[5].x3, 'y1':tempList2[5].y3, 'x2':tempList2[5].x4, 'y2':tempList2[5].y4};
list2Index2['JP Morgan'] = {'x1': tempList2[6].x3, 'y1':tempList2[6].y3, 'x2':tempList2[6].x4, 'y2':tempList2[6].y4};
list2Index2['Value Partners'] = {'x1': tempList2[7].x3, 'y1':tempList2[7].y3, 'x2':tempList2[7].x4, 'y2':tempList2[7].y4};
list2Index2['First State'] = {'x1': tempList2[8].x3, 'y1':tempList2[8].y3, 'x2':tempList2[8].x4, 'y2':tempList2[8].y4};
list2Index2['HSBC'] = {'x1': tempList2[9].x3, 'y1':tempList2[9].y3, 'x2':tempList2[9].x4, 'y2':tempList2[9].y4};
list2Index2['Invesco'] = {'x1': tempList2[10].x3, 'y1':tempList2[10].y3, 'x2':tempList2[10].x4, 'y2':tempList2[10].y4};
list2Index2['BOCI-Prudential'] = {'x1': tempList2[11].x3, 'y1':tempList2[11].y3, 'x2':tempList2[11].x4, 'y2':tempList2[11].y4};
list2Index2['DWS'] = {'x1': tempList2[12].x3, 'y1':tempList2[12].y3, 'x2':tempList2[12].x4, 'y2':tempList2[12].y4};
list2Index2['CSOP'] = {'x1': tempList2[13].x3, 'y1':tempList2[13].y3, 'x2':tempList2[13].x4, 'y2':tempList2[13].y4};
list2Index2['Principal'] = {'x1': tempList2[14].x3, 'y1':tempList2[14].y3, 'x2':tempList2[14].x4, 'y2':tempList2[14].y4};
list2Index2['Allianz'] = {'x1': tempList2[15].x3, 'y1':tempList2[15].y3, 'x2':tempList2[15].x4, 'y2':tempList2[15].y4};
list2Index2['Manulife'] = {'x1': tempList2[16].x3, 'y1':tempList2[16].y3, 'x2':tempList2[16].x4, 'y2':tempList2[16].y4};
list2Index2['Aberdeen Standard'] = {'x1': tempList2[17].x3, 'y1':tempList2[17].y3, 'x2':tempList2[17].x4, 'y2':tempList2[17].y4};
list2Index2['ChinaAMC'] = {'x1': tempList2[18].x3, 'y1':tempList2[18].y3, 'x2':tempList2[18].x4, 'y2':tempList2[18].y4};
list2Index2['Mirae Asset'] = {'x1': tempList2[19].x3, 'y1':tempList2[19].y3, 'x2':tempList2[19].x4, 'y2':tempList2[19].y4};
list3Index['BlackRock'] = {'x3': tempList3[0].x3, 'y3':tempList3[0].y3, 'x4':tempList3[0].x4, 'y4':tempList3[0].y4};
list3Index['Fidelity'] = {'x3': tempList3[1].x3, 'y3':tempList3[1].y3, 'x4':tempList3[1].x4, 'y4':tempList3[1].y4};
list3Index['SSgA'] = {'x3': tempList3[2].x3, 'y3':tempList3[2].y3, 'x4':tempList3[2].x4, 'y4':tempList3[2].y4};
list3Index['UBS'] = {'x3': tempList3[3].x3, 'y3':tempList3[3].y3, 'x4':tempList3[3].x4, 'y4':tempList3[3].y4};
list3Index['Hang Seng'] = {'x3': tempList3[4].x3, 'y3':tempList3[4].y3, 'x4':tempList3[4].x4, 'y4':tempList3[4].y4};
list3Index['Schroders'] = {'x3': tempList3[5].x3, 'y3':tempList3[5].y3, 'x4':tempList3[5].x4, 'y4':tempList3[5].y4};
list3Index['Value Partners'] = {'x3': tempList3[6].x3, 'y3':tempList3[6].y3, 'x4':tempList3[6].x4, 'y4':tempList3[6].y4};
list3Index['JP Morgan'] = {'x3': tempList3[7].x3, 'y3':tempList3[7].y3, 'x4':tempList3[7].x4, 'y4':tempList3[7].y4};
list3Index['First State'] = {'x3': tempList3[8].x3, 'y3':tempList3[8].y3, 'x4':tempList3[8].x4, 'y4':tempList3[8].y4};
list3Index['DWS'] = {'x3': tempList3[9].x3, 'y3':tempList3[9].y3, 'x4':tempList3[9].x4, 'y4':tempList3[9].y4};
list3Index['Invesco'] = {'x3': tempList3[10].x3, 'y3':tempList3[10].y3, 'x4':tempList3[10].x4, 'y4':tempList3[10].y4};
list3Index['HSBC'] = {'x3': tempList3[11].x3, 'y3':tempList3[11].y3, 'x4':tempList3[11].x4, 'y4':tempList3[11].y4};
list3Index['Allianz'] = {'x3': tempList3[12].x3, 'y3':tempList3[12].y3, 'x4':tempList3[12].x4, 'y4':tempList3[12].y4};
list3Index['BOCI-Prudential'] = {'x3': tempList3[13].x3, 'y3':tempList3[13].y3, 'x4':tempList3[13].x4, 'y4':tempList3[13].y4};
list3Index['CSOP'] = {'x3': tempList3[14].x3, 'y3':tempList3[14].y3, 'x4':tempList3[14].x4, 'y4':tempList3[14].y4};
list3Index['Aberdeen Standard'] = {'x3': tempList3[15].x3, 'y3':tempList3[15].y3, 'x4':tempList3[15].x4, 'y4':tempList3[15].y4};
list3Index['Principal'] = {'x3': tempList3[16].x3, 'y3':tempList3[16].y3, 'x4':tempList3[16].x4, 'y4':tempList3[16].y4};
list3Index['Manulife'] = {'x3': tempList3[17].x3, 'y3':tempList3[17].y3, 'x4':tempList3[17].x4, 'y4':tempList3[17].y4};
list3Index['ChinaAMC'] = {'x3': tempList3[18].x3, 'y3':tempList3[18].y3, 'x4':tempList3[18].x4, 'y4':tempList3[18].y4};
list3Index['Mirae Asset'] = {'x3': tempList3[19].x3, 'y3':tempList3[19].y3, 'x4':tempList3[19].x4, 'y4':tempList3[19].y4};
var bigList = [];
for (var k = 0; k <20; k++) {
var thisManager = managerList[k].manager;
let merged = {...list1Index[thisManager], ...list2Index[thisManager]};
bigList.push(merged);
};
var bigList2 = [];
for (var k = 0; k <20; k++) {
var thisManager = managerList[k].manager;
let merged2 = {...list2Index2[thisManager], ...list3Index[thisManager]};
bigList2.push(merged2);
};
var polyMaster = [];
for (var k = 0; k < bigList.length; k++) {
var tempItem = [
{'x':bigList[k].x1+4, 'y':bigList[k].y1},
{'x':bigList[k].x2+4, 'y':bigList[k].y2+2},
{'x':bigList[k].x3-4, 'y':bigList[k].y3+1},
{'x':bigList[k].x4-4, 'y':bigList[k].y4-2},
];
polyMaster.push(tempItem);
}
var polyMaster2 = [];
for (var k = 0; k < bigList2.length; k++) {
var tempItem = [
{'x':bigList2[k].x1+4+120, 'y':bigList2[k].y2},
{'x':bigList2[k].x2+4+120, 'y':bigList2[k].y1+2},
{'x':bigList2[k].x3-4, 'y':bigList2[k].y3+1},
{'x':bigList2[k].x4-4, 'y':bigList2[k].y4-2},
];
polyMaster2.push(tempItem);
}
graphGroup.selectAll(".poly1")
.data(polyMaster)
.enter().append("polygon")
.attr('class','poly1')
.attr("points",function(d) {
return d.map(function(d) { return [d.x,d.y].join(","); }).join(" ");})
.style('fill', function(d,i) {return colorMap[managerList[i].manager]})
.style('opacity', .6);
graphGroup.selectAll(".poly2")
.data(polyMaster2)
.enter().append("polygon")
.attr('class','poly2')
.attr("points",function(d) {
return d.map(function(d) { return [d.x,d.y].join(","); }).join(" ");})
.style('fill', function(d,i) {return colorMap[managerList[i].manager]})
.style('opacity', .6);
<script src="https://d3js.org/d3.v5.min.js"></script>
关于javascript - D3 检索矩形顶点以附加平行四边形(多边形),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57386189/
我想使用图中所示的迷宫,使用迭代深度优先搜索找到从起始节点到目标的路径。它是一个仅包含一对数字的文本文件,例如成对连接,又称边/弧。像这样: 11 3 2 3 0 3 1 4 5 4 5 7 6 7
问题:您有一个无向图 G = (V, E)(V = 顶点,E = 边),您必须访问每个顶点并在两个方向上通过每个边。 我所知道的图算法只有 DFS、BFS 和一些 MST(Kruskal 等)不幸的是
枚举任意图中两个顶点之间的所有简单路径通常需要指数时间,因为顶点之间可能存在指数数量的简单路径。但是,如果我们只对位于两个末端顶点之间的至少一条简单路径上的顶点怎么办? 即:给定一个无向图和两个不同的
我正在开发一个简单的 opengl 游戏以了解更多相关信息。但是由于某种原因,当我尝试随时间旋转我的立方体时,它会被拉伸(stretch)。你可以在照片中看到它: 我认为这与我的模型矩阵有关,但我不确
我已经在谷歌上搜索了很长一段时间,但我找不到任何东西。如何使用 Graphviz 绘制没有连接顶点的图形? 最佳答案 像这样: digraph g { SingleNode; } 简单地不定义
我目前正在使用 R 中的“igraph”包进行一些社交网络分析,我想知道是否有一种方法可以个性化社交网络中节点的放置。 例如,使用以下玩具代码: library(igraph) edg
我在 Box2D 中有一个多边形形状。形状是一个三角形,我希望有 3 个顶点。事实上,我创建的所有形状都会输出 8 个顶点。为什么是这样?如果我输出顶点数,那总是正确的数量。我不想渲染不必要的线条,但
来自user manual CGAL Surface_mesh 类: the data structure uses integer indices as descriptors for vertic
我正在尝试找到引用 ARFaceGeometry 网格索引的方法为了使用 ARKit 将图形放置在面部的特定部位。 我见过很多例子,其中功能与一些索引号,但我找不到对此列表的任何引用。它似乎有超过12
Apache TomCat(版本未知) 业务对象 4.1 顶点 4.4.3 在一台服务器上,我们拥有 TomCat 和 Business Objects。 APEX 也使用 TomCat。 在对我们的
我正在使用 MX Graph 进行一些工作,以帮助识别网站中的关键内容路径。我将其设置为每个顶点代表网站上的一个页面,每条边代表一组从页面 A 访问页面 B 的访问者。 一切都运行良好,除了边太多,我
我正在尝试使用三角形 strip 绘制一个平面。我了解如何手动执行此操作,但我真的很难使用 for 循环来执行此操作。到目前为止,下面的代码绘制了两个三角形。 //vertices for trian
如果我想通过 id 顶点获取名称,我可以使用这个函数:VAS(g, "name",id)但是如果我想要相反的方式,通过名称获取 id,我该怎么做呢? 最佳答案 igraph 本身不提供按名称查找顶点的
我有一个三角形,其任意顶点位于 3D 空间中。 我知道通过以下操作很容易找到这种三角形的质心: float centroid[3] = { 0, 0, 0 }; for (int i = 0; i =
我有一个点数组。每个点都有位置(x, y, z) 和法 vector (xn, yn, zn) ,一共6个 double 。考虑到浮点容差,我需要在此数组中找到唯一元素并删除重复条目。 实现它的简单有
我有一个相互连接的边列表 (E),如何找到从一个顶点连接到另一个顶点的最短路径? 我正在考虑使用 lowest common ancestors ,但边缘没有明确定义的根,所以我认为该解决方案不起作用
我现在正在使用计算着色器开发粒子系统。我将所有粒子都放在着色器存储缓冲区中。一个粒子包含两个顶点,当前位置和先前位置。 struct Particle{ glm::vec4 _currPo
我将我的顶点剪裁在边缘上,如这张专辑所示: http://imgur.com/a/VkCrJ 当我的地形大小为 400 x 400 时,我得到裁剪,但在 40x40 或更小时,我没有得到任何裁剪。这是
总是在顶点着色器中而不是在片段着色器中更好地进行硬计算吗?即使是具有超过 100.000 个多边形的高网格模型(假设有一堆独特的顶点)? 最佳答案 不,它并不总是更好。 选择合适的计算位置的最佳方法是
我想编辑一个立方体上的 1 个顶点,但我不知道该怎么做。我试过到处寻找此功能,但找不到解决方案。 这是我想要实现的目标的图像: 最佳答案 http://answers.unity3d.com/ques
我是一名优秀的程序员,十分优秀!