{
let currentViewBox = '0 0 918 130'
const buttonExpand = html`<button>Expand/Collapse</button>`
const allSizes = [...aobData.sell.map(priceData => parseInt(priceData.size)), ...aobData.sell.map(priceData => parseInt(priceData.size))];
const xScaleLeft = d3.scaleBand()
.domain(aobData.buy.map(priceData => priceData.level))
.range([0, 434])
.paddingInner(0.14);
const xScaleRight = d3.scaleBand()
.domain(aobData.sell.map(priceData => priceData.level))
.range([484, 918])
.paddingInner(0.14);
const yScale = d3.scaleLinear()
.domain(d3.extent(allSizes, d => d))
.range([15, chartDimensions.height])
const svg = html`<svg width=${chartDimensions.expandedWidth} height=${chartDimensions.height} viewBox='${currentViewBox}' style="border:
1px dashed darkolivegreen"></svg>`;
const buySelection = d3.select(svg)
.selectAll('rect.buy')
.data(aobData.buy)
.join('rect')
.attr('x', (d, i) => xScaleLeft(d.level))
.attr('y', d => chartDimensions.height - yScale(d.size))
.attr('width', xScaleLeft.bandwidth())
.attr('height', d => yScale(d.size))
.attr('stroke', '#3896E3')
.attr('stroke-width', 1)
.attr('stroke-dasharray', '15, 2, 4, 2')
.attr('stroke-dashoffset', '-3')
.attr('fill', 'none')
const sellSelection = d3.select(svg)
.selectAll('rect.sell')
.data(aobData.sell)
.join('rect')
.attr('x', (d, i) => xScaleRight(d.level))
.attr('y', d => chartDimensions.height - yScale(d.size))
.attr('width', xScaleRight.bandwidth())
.attr('height', d => yScale(d.size))
.attr('stroke', '#F76054')
.attr('stroke-width', 1)
.attr('fill', '#F76054')
d3.select(svg).selectAll('rect')
.style('cursor', 'pointer')
.on('mouseenter', (e, d) => d3.select(e.target).attr('fill-opacity', 0.4))
.on('mouseleave', (e, d) => d3.select(e.target).attr('fill-opacity', 1))
.on('click', (e, d) => d3.select(e.target).attr('fill', 'darkolivegreen'))
d3.select(buttonExpand).on('click', ()=>{
currentViewBox = currentViewBox === '0 0 918 130' ? '220 0 478 130' : '0 0 918 130';
console.log({ currentViewBox});
d3.select(svg)
.attr('viewBox', currentViewBox)
.attr('width', currentViewBox === '0 0 918 130' ? '918' : '478')
});
return html`
${svg}
${buttonExpand}
`;
}