"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderWrappedPartitionCanvas2d = renderWrappedPartitionCanvas2d;
const color_library_wrappers_1 = require("../../../../common/color_library_wrappers");
const common_1 = require("../../../../utils/common");
const dimmed_colors_1 = require("../../../../utils/themes/dimmed_colors");
const highlighted_geoms_1 = require("../../layout/utils/highlighted_geoms");
const MAX_PADDING_RATIO = 0.25;
function renderWrappedPartitionCanvas2d(ctx, dpr, { style: { sectorLineWidth: padding }, quadViewModel, diskCenter, width: panelWidth, height: panelHeight, chartDimensions: { width: containerWidth, height: containerHeight }, }, highlightedLegendPath, legendStrategy, flatLegend, partitionStyle) {
    const width = containerWidth * panelWidth;
    const height = containerHeight * panelHeight;
    const cornerRatio = 0.2;
    const highlightedQuadSet = new Set();
    if (highlightedLegendPath.length > 0) {
        const highlighted = (0, highlighted_geoms_1.highlightedGeoms)(legendStrategy, flatLegend, quadViewModel, highlightedLegendPath);
        highlighted.forEach((quad) => highlightedQuadSet.add(quad));
    }
    ctx.save();
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.lineCap = 'round';
    ctx.lineJoin = 'round';
    ctx.scale(dpr, dpr);
    ctx.translate(diskCenter.x, diskCenter.y);
    ctx.clearRect(0, 0, width, height);
    quadViewModel.forEach((quad) => {
        const { x0, x1, y0px: y0, y1px: y1 } = quad;
        if (y1 - y0 <= padding)
            return;
        const fWidth = x1 - x0;
        const fPadding = Math.min(padding, MAX_PADDING_RATIO * fWidth);
        const w = fWidth - fPadding;
        const h = y1 - y0 - padding;
        const x = x0 + fPadding;
        const y = y0 + padding / 2;
        const r = cornerRatio * Math.min(w, h);
        const isDimmed = highlightedQuadSet.size > 0 && !highlightedQuadSet.has(quad);
        const baseFillColor = (0, common_1.getColorFromVariant)(quad.fillColor, (0, dimmed_colors_1.getDimmedColor)(isDimmed, partitionStyle.dimmed, 'fill', quad.fillColor));
        const fillColor = isDimmed && 'opacity' in partitionStyle.dimmed
            ? (0, color_library_wrappers_1.multiplyColorOpacity)(baseFillColor, partitionStyle.dimmed.opacity)
            : baseFillColor;
        ctx.fillStyle = fillColor;
        ctx.beginPath();
        ctx.moveTo(x + r, y);
        ctx.arcTo(x + w, y, x + w, y + h, r);
        ctx.arcTo(x + w, y + h, x, y + h, r);
        ctx.arcTo(x, y + h, x, y, r);
        ctx.arcTo(x, y, x + w, y, r);
        ctx.closePath();
        ctx.fill();
    });
    ctx.restore();
}
//# sourceMappingURL=canvas_wrapped_renderers.js.map