@opendata-ai/openchart-engine 7.9.3 → 7.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +20 -1
- package/dist/index.js +49 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/axes.test.ts +165 -0
- package/src/__tests__/dimensions.test.ts +49 -4
- package/src/__tests__/legend.test.ts +51 -0
- package/src/compile.ts +5 -0
- package/src/index.ts +8 -0
- package/src/layout/axes/ticks.ts +20 -5
- package/src/layout/axes.ts +40 -15
- package/src/layout/dimensions.ts +39 -12
- package/src/layout/plan.ts +3 -2
- package/src/legend/compute.ts +7 -1
- package/src/legend/wrap.ts +8 -0
package/src/legend/compute.ts
CHANGED
|
@@ -494,6 +494,11 @@ export function computeLegendContent(
|
|
|
494
494
|
* @param containerWidth - Full container width, used for responsive legend gap.
|
|
495
495
|
* @param _theme - Resolved theme (reserved for future use).
|
|
496
496
|
* @param xAxisHeight - Height of the x-axis, used for bottom legend positioning.
|
|
497
|
+
* @param axisGapBelowLegend - The `effectiveAxisGap` the margin stack reserved
|
|
498
|
+
* between a top legend and the chart area (inline y-tick labels draw in that
|
|
499
|
+
* zone, above `chartArea.y`). The top legend is lifted above it so it
|
|
500
|
+
* occupies its reserved slot instead of colliding with the topmost tick
|
|
501
|
+
* label. Defaults to 0 so other callers/positions are unaffected.
|
|
497
502
|
* @returns Full LegendLayout with bounds.
|
|
498
503
|
*/
|
|
499
504
|
export function placeLegend(
|
|
@@ -502,6 +507,7 @@ export function placeLegend(
|
|
|
502
507
|
containerWidth: number,
|
|
503
508
|
_theme: ResolvedTheme,
|
|
504
509
|
xAxisHeight: number,
|
|
510
|
+
axisGapBelowLegend: number = 0,
|
|
505
511
|
): LegendLayout {
|
|
506
512
|
const { position, entries, labelStyle, legendWidth, height, offset } = content;
|
|
507
513
|
|
|
@@ -538,7 +544,7 @@ export function placeLegend(
|
|
|
538
544
|
} else {
|
|
539
545
|
// top
|
|
540
546
|
boundsX = chartArea.x + offsetDx;
|
|
541
|
-
boundsY = chartArea.y - gap - height + offsetDy;
|
|
547
|
+
boundsY = chartArea.y - axisGapBelowLegend - gap - height + offsetDy;
|
|
542
548
|
}
|
|
543
549
|
|
|
544
550
|
const bounds = { x: boundsX, y: boundsY, width: legendWidth, height };
|
package/src/legend/wrap.ts
CHANGED
|
@@ -34,6 +34,14 @@ export const ENTRY_GAP_COMPACT = 10;
|
|
|
34
34
|
/** Default gap between legend bounds and chart area. Zero on narrow viewports. */
|
|
35
35
|
export const LEGEND_GAP = 8;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Minimum gap between the chrome/metrics block above and a top legend.
|
|
39
|
+
* Without it the legend sits flush against the subtitle (compact widths)
|
|
40
|
+
* or the metric bar (all widths) once the inline-tick overhang is placed
|
|
41
|
+
* below the legend where it belongs.
|
|
42
|
+
*/
|
|
43
|
+
export const TOP_LEGEND_GAP_ABOVE = 6;
|
|
44
|
+
|
|
37
45
|
/** Gap between legend and chart area, responsive to container width. */
|
|
38
46
|
export function legendGap(width: number): number {
|
|
39
47
|
return width < COMPACT_WIDTH ? 0 : LEGEND_GAP;
|