@blueprint-chart/lib 2.0.0 → 2.1.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.
@@ -14,6 +14,15 @@ export interface AxisServiceConfig {
14
14
  };
15
15
  order?: 'vertical-first' | 'horizontal-first';
16
16
  }
17
+ /**
18
+ * Drop the cached AxisService when a container switches chart type.
19
+ *
20
+ * The cache is keyed per container only, so the next type inherits the previous
21
+ * one's axis DOM, and d3-axis's tick data-join reuses ticks that match by
22
+ * value, so a type that stripped its tick labels (`labelPosition = off`) leaves
23
+ * the next type's ticks permanently text-less.
24
+ */
25
+ export declare function resetAxesOnChartTypeChange(container: HTMLElement, chartType: string): void;
17
26
  export declare class AxisService {
18
27
  private vGroup;
19
28
  private hGroup;
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Legend item text and the px advance to the next item. `maxWidth` is the row
3
+ * width: a single item wider than the row is truncated with an ellipsis, since
4
+ * nothing downstream clips it and the text otherwise runs past the frame edge.
5
+ * The suffix carries the value, so it survives and the label absorbs the cut.
6
+ */
7
+ export declare function fitLegendItem(label: string, suffix?: string, maxWidth?: number): {
8
+ label: string;
9
+ suffix: string;
10
+ width: number;
11
+ };
12
+ /** Width a vertical legend column needs for `texts`. */
13
+ export declare function legendColumnWidth(texts: string[]): number;
1
14
  export declare function estimateLegendSize(labels: string[], position: string, availableWidth?: number): {
2
15
  width: number;
3
16
  height: number;
@@ -22,6 +22,11 @@ export declare function bboxEdgeToward(bbox: {
22
22
  y: number;
23
23
  };
24
24
  export declare function ensureArrowMarker(svg: SVGElement | null, color?: string): string;
25
+ /**
26
+ * A non-positive radius paints nothing — SVG rejects a negative `r` outright —
27
+ * so an unusable size resolves to the documented default instead.
28
+ */
29
+ export declare function resolveCircleRadius(size?: number): number;
25
30
  export declare function renderTargetCircle(g: d3.Selection<SVGGElement, unknown, null, undefined>, cx: number, cy: number, opts?: {
26
31
  size?: number;
27
32
  style?: StrokeStyle;
@@ -53,5 +58,11 @@ export declare function renderAnnotationText(g: d3.Selection<SVGGElement, unknow
53
58
  backgroundColor?: string;
54
59
  textOutline?: boolean;
55
60
  }): void;
56
- export declare function resolveXPosition(value: number | string, scaleX: AnnotationContext['scaleX'], anchor?: RangeAnchor): number;
57
- export declare function resolveYPosition(value: number | string, scaleY: d3.ScaleLinear<number, number> | d3.ScaleSymLog<number, number>): number;
61
+ /**
62
+ * Position of a range endpoint on the category axis, or `null` when the endpoint
63
+ * does not resolve. Anchoring an unresolved endpoint at the plot origin would
64
+ * silently highlight a category the author never named.
65
+ */
66
+ export declare function resolveXPosition(value: number | string, scaleX: AnnotationContext['scaleX'], anchor?: RangeAnchor): number | null;
67
+ /** Position of a range endpoint on the value axis, or `null` when it does not resolve. */
68
+ export declare function resolveYPosition(value: number | string, scaleY: d3.ScaleLinear<number, number> | d3.ScaleSymLog<number, number>): number | null;
@@ -44,8 +44,16 @@ export declare function renderAutoArcLabels(parent: d3.Selection<SVGGElement, un
44
44
  * Estimate extra margins needed for arc labels beyond what the arc already
45
45
  * occupies. The text column sits at outerRadius + STUB_LENGTH + HORIZONTAL_SEG + 6
46
46
  * from centre; we need room for the text itself beyond that.
47
+ *
48
+ * `available` is the box the arc has to fit in. The margins are capped against
49
+ * it, because they are subtracted from the canvas with no other lower bound:
50
+ * one long label, a phone-width container or twenty slices otherwise leave a
51
+ * radius of zero and no arcs are painted.
47
52
  */
48
- export declare function estimateArcLabelMargins(labels: string[], outerRadius: number): {
53
+ export declare function estimateArcLabelMargins(labels: string[], outerRadius: number, available?: {
54
+ width: number;
55
+ height: number;
56
+ }): {
49
57
  left: number;
50
58
  right: number;
51
59
  top: number;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Shared text measurement for the layout estimators: axis tick density, legend
3
+ * item advance, arc label margins and annotation wrapping all need to know how
4
+ * wide a string will actually render.
5
+ *
6
+ * Three sources, first available wins:
7
+ * 1. an offscreen 2D canvas — the browser and the editor;
8
+ * 2. a detached SVG `<text>` and `getComputedTextLength()` — what the Node
9
+ * backend has, through the jsdom shim in `render/backends/text-shim.ts`;
10
+ * 3. the per-glyph estimate below, when a render environment offers neither.
11
+ *
12
+ * The result is never below the estimate. The font the Node backend bundles
13
+ * (DejaVu Sans) has no CJK glyphs, so measuring Japanese text there returns the
14
+ * width of the notdef box (~0.6em) rather than the ~1em a CJK face advances;
15
+ * without the floor, wide scripts would be under-reserved headlessly.
16
+ */
17
+ /** Rendered width of `text` in px at `fontSizePx`, in the chart font. */
18
+ export declare function measureTextWidth(text: string, fontSizePx: number): number;
19
+ /** Rendered width of the widest of `texts`, or 0 when there are none. */
20
+ export declare function measureMaxTextWidth(texts: string[], fontSizePx: number): number;
21
+ /**
22
+ * Longest prefix of `text` that fits in `maxWidth`, with `suffix` appended when
23
+ * anything had to be dropped. Returns `text` unchanged when it already fits.
24
+ */
25
+ export declare function truncateToWidth(text: string, maxWidth: number, fontSizePx: number, suffix?: string): string;