기본적으로 선택 문제입니다.범례 마우스 오버를 기준으로 불투명도를 변경하는 경로 선택
여기 내 semi-working Plunker입니다.
경로 범례의 차트 요소 (원)에 마우스를 올리면 차트 내의 모든 경로의 불투명도가 이 아닌으로 변경됩니다.
나는 mouseover에서 활성화 된 원과 동일한 ID를 가질 경로의 ID를 설정했습니다. 또한 불투명도를 변경하기 위해 마우스를 올리면 선택되지 않은 서클을 얻었습니다. (그러나 현재 모든 차트에서 모든 범례에있는 선택되지 않은 모든 서클이 불투명도를 변경합니다. 마우스 오버 투명도 변경은 관련 차트만으로 제한하려고합니다.)
달성하려고하는 것 :
주어진 차트의 범례에서 원을 마우스로 움직이면 경로 자체에 마우스 포인터를 대고있는 것처럼 동일한 불투명도 변경이 해당 차트의 경로에 적용되어야합니다. 문제가 올바르게 이해되면 서클 및 해당 경로의 선택/선택 취소를 정의하는 데 문제가 있으며 해당 선택 사항을 페이지의 여러 차트 중 하나의 차트로만 제한합니다. 여기
이 경로 '그룹과 ID를 정의하는 방법은 다음과 같습니다
var pathGroup = main.append('g').classed('paths', true);
var paths = pathGroup.selectAll("path")
.data(dataset)
.enter()
.append("path")
.attr("id", function(d) {
return d.record
})
.attr("data-legend", function(d) {
return d.record
})
그리고 여기에 문제가있는 코드입니다, 내 생각 :
여기li.selectAll("circle")
.attr("id",function (d) {return d.key})
.style("fill",function(d) { return d.value.color})
.on("mouseover", function(d) {
// need to define "circleGroup" and "circles" (as is done for "pathGroup" and "paths") so that the legend's non-selected circles are the ones that fade)
// also need to find a way of limiting "circles" to a circle group within only that state's chart
// circles
d3.selectAll('circle:not(this)')
.style('opacity', 0.4)
.style('transition', "opacity 0.1s")
d3.select(this)
.classed('hover', true)
.style('opacity', 0.9)
.style('transition', "opacity 0.1s")
d3.select('path:not(this)')
.style('opacity', 0.4)
.style('transition', "opacity 0.1s")
// d3.select('path data-legend', function(d) { return d.key})
d3.select('path id', function(d) { return d.key})
.classed('hover', true)
.style('opacity', 0.9)
.style('transition', "opacity 0.1s")
})
.on('mouseout', function(d) {
d3.selectAll('circle')
.style('opacity', 0.9)
.style('transition', "opacity 0.1s")
})
다시 내 반 작업 Plunker입니다 : http://plnkr.co/edit/mvdqBPMymCt9VAKAPKD1?p=preview
미리 권한을 설정해 주셔서 감사합니다. 코드와
그것은 아름답습니다! 고맙습니다. 나는 전설을 완전히 다시 쓰려고했으나 이것은 우아한 해결책이다. – LaissezPasser
코딩을 재미있게 즐기십시오! 도와 줘서 기뻐요! :) – Shashank