This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const svgChartParent = d3.select('svg'); | |
const zoomButton = toolsList.select('#zoom').on('click', () => { | |
toolsList.selectAll('.active').classed('active', false); | |
zoomButton.classed('active', true); | |
canvasChart.style('z-index', 1); | |
svgChartParent.style('z-index', 0); | |
}); | |
const brushButton = toolsList.select('#brush').on('click', () => { | |
toolsList.selectAll('.active').classed('active', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tools button { | |
background-color: #e7e7e7; | |
border: none; | |
color: #000000; | |
cursor: pointer; | |
display: block; | |
margin-bottom: 5px; | |
padding: 5px 10px; | |
outline: 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="tools"> | |
<button id="reset">Reset</button> | |
<button id="zoom" class="active">Zoom</button> | |
<button id="brush">Brush</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toolsList = container.select('.tools') | |
.style('margin-top', margin.top + 'px') | |
.style('visibility', 'visible'); | |
toolsList.select('#reset').on('click', () => { | |
const t = d3.zoomIdentity.translate(0, 0).scale(1); | |
canvasChart.transition() | |
.duration(200) | |
.ease(d3.easeLinear) | |
.call(zoom_function.transform, t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tools { | |
position: absolute; | |
left: calc(50% + 400px); | |
visibility: hidden; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tools { | |
position: absolute; | |
left: calc(50% + 400px); | |
visibility: hidden; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="scatter-container"> | |
<div class="tools"> | |
<button id="reset">Reset</button> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zoom_function = d3.zoom().scaleExtent([1, 1000]) | |
.on('zoom', () => { | |
const transform = d3.event.transform; | |
context.save(); | |
draw(transform); | |
context.restore(); | |
}); | |
canvasChart.call(zoom_function); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw(d3.zoomIdentity), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawPoint(scaleX, scaleY, point, k) { | |
context.beginPath(); | |
context.fillStyle = pointColor; | |
const px = scaleX(point[0]); | |
const py = scaleY(point[1]); | |
context.arc(px, py, 1.2 * k, 0, 2 * Math.PI, true); | |
context.fill(); | |
} |