@blueprint-chart/lib 0.2.0 → 0.4.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/README.md CHANGED
@@ -10,6 +10,25 @@ npm install @blueprint-chart/lib
10
10
 
11
11
  ## Quick start
12
12
 
13
+ ### Node — write SVG and PNG to disk
14
+
15
+ ```ts
16
+ import { render } from '@blueprint-chart/lib'
17
+ import { writeFile } from 'node:fs/promises'
18
+
19
+ const chart = await render(bpc)
20
+ await writeFile('chart.svg', await chart.toSvg())
21
+ await writeFile('chart.png', await chart.toPng({ width: 1200 }))
22
+ ```
23
+
24
+ ### Browser — mount and step scenes
25
+
26
+ ```ts
27
+ const { mount, scene } = await render(bpc)
28
+ mount('#chart') // element or selector
29
+ scene(2) // advance to scene index 2
30
+ ```
31
+
13
32
  The simplest way to render a chart is the IIFE runtime, which auto-scans the document for embedded chart definitions and renders each one inline (inside a sandboxed iframe inserted before the script tag):
14
33
 
15
34
  ```html
@@ -1,3 +1,12 @@
1
+ /**
2
+ * @deprecated As of the Scene Transition Orchestrator, mark rendering has fully
3
+ * migrated to `packages/lib/src/transitions/` (SceneTransition + featureJoin +
4
+ * tweenFrameGeometry): the legacy `reinsertWithOffset` mark-translate wrapper is
5
+ * gone. What remains here is the cross-type fade path and the transition-duration
6
+ * flag: every renderer and the axis subsystem still call `setRenderTransition` /
7
+ * `getDefaultTransitionMs`, and cross-type transitions use `snapshotForFadeOut` /
8
+ * `commitFadeOut` / `fadeIn`. This file can be deleted once those move too.
9
+ */
1
10
  /**
2
11
  * Returns 0 when the user prefers reduced motion, otherwise returns the input duration.
3
12
  */
@@ -13,15 +22,6 @@ export declare function setRenderTransition(enabled: boolean): void;
13
22
  * Returns 0 when not in a scene transition (i.e. setRenderTransition(false) was last called).
14
23
  */
15
24
  export declare function getDefaultTransitionMs(): number;
16
- /**
17
- * Reinsert prior elements into a parent, wrapping them in a compensating
18
- * `<g translate(dx,dy)>` that transitions to identity over the default
19
- * duration. This corrects for chartArea origin shifts (e.g. when legend
20
- * toggles change margins) so that prior elements don't visually jump.
21
- *
22
- * When dx/dy are both 0, elements are appended directly without a wrapper.
23
- */
24
- export declare function reinsertWithOffset(parent: Element, elements: Element[], dx: number, dy: number): void;
25
25
  /**
26
26
  * Fade an element in using the Web Animations API.
27
27
  * Respects `prefers-reduced-motion` via `getTransitionDuration`.
@@ -0,0 +1,16 @@
1
+ import { D3Blueprint } from 'd3-blueprint';
2
+ import * as d3 from 'd3';
3
+ /**
4
+ * Minimal D3Blueprint host whose only job is to carry the legacy plugins
5
+ * (tooltip, crosshair, annotations) that consume the `.use()` / `.draw()` API.
6
+ *
7
+ * Marks are rendered through the SceneTransition orchestrator's featureJoin, not
8
+ * this class — so `initialize` defines no layers. Renderers that have migrated
9
+ * their marks but still host plugins use `createPluginHost` instead of declaring
10
+ * a per-file empty subclass.
11
+ */
12
+ declare class PluginHost extends D3Blueprint<unknown> {
13
+ initialize(): void;
14
+ }
15
+ export declare function createPluginHost(selection: d3.Selection<SVGGElement, unknown, null, undefined>): PluginHost;
16
+ export {};
@@ -2,6 +2,17 @@ import { Margin } from './types';
2
2
  export interface CachedChart {
3
3
  chartType: string;
4
4
  margin?: Margin;
5
+ /**
6
+ * The plot rect (origin + size) this render used for its marks/clip, so the
7
+ * next same-type transition can ease the frame geometry from the exact prior
8
+ * rect instead of reconstructing it from margins. Shape matches `PlotRect`.
9
+ */
10
+ plotRect?: {
11
+ left: number;
12
+ top: number;
13
+ width: number;
14
+ height: number;
15
+ };
5
16
  }
6
17
  export declare function getCachedChart(container: HTMLElement): CachedChart | undefined;
7
18
  export declare function setCachedChart(container: HTMLElement, entry: CachedChart): void;
@@ -0,0 +1,11 @@
1
+ export interface ValueLabelFitInput {
2
+ text: string;
3
+ placement: 'inside' | 'outside';
4
+ orientation: 'vertical' | 'horizontal';
5
+ /** px extent along x (vertical bar: thickness; horizontal bar: length) */
6
+ barWidth: number;
7
+ /** px extent along y (vertical bar: length; horizontal bar: thickness) */
8
+ barHeight: number;
9
+ }
10
+ export declare function estimateLabelWidth(text: string): number;
11
+ export declare function shouldRenderValueLabel(input: ValueLabelFitInput): boolean;
@@ -1,3 +1,4 @@
1
1
  import { ChartNode } from './types';
2
2
  export declare function serialize(ast: ChartNode): string;
3
+ export declare function compactSerializeDeep(ast: ChartNode): string;
3
4
  export declare function compactSerialize(ast: ChartNode): string;
package/dist/index.d.ts CHANGED
@@ -25,14 +25,15 @@ export { getCachedChart } from './charts/transition-cache';
25
25
  export { getCvdFilterId, createCvdSvgFilter, simulateCvdColor, checkCvdColors } from './charts/colorblind';
26
26
  export type { CvdType, CvdIssue } from './charts/colorblind';
27
27
  export { parse } from './dsl/parser';
28
- export { serialize, compactSerialize } from './dsl/serializer';
28
+ export { serialize, compactSerialize, compactSerializeDeep } from './dsl/serializer';
29
29
  export { propertyMap, extractChartTypeOptions, dataEntriesToString, extractSceneOverrides, convertColorizes, convertHighlights, convertAreaFills, convertAnnotations, convertSeriesOverrides } from './dsl/converter';
30
30
  export type { AnnotationNode, AnnotationVisibilityNode, PointAnnotationNode, RangeAnnotationNode, FreeAnnotationNode, AreaFillNode, ChartNode, DataNode, ColorizeNode, HighlightNode, PropertyNode, SceneNode, SeriesNode, TransformNode } from './dsl/types';
31
31
  export { validateChart } from './dsl/validate';
32
32
  export type { ValidationIssue, ValidationResult } from './dsl/validate';
33
33
  export { samples } from './samples';
34
34
  export type { ChartSample } from './samples';
35
- export { renderBpc, renderChart, astToDefinition, resolveScene } from './render';
36
- export type { ChartDefinition, RenderOptions, ResolvedChartState } from './render';
35
+ export { renderBpc, renderChart, astToDefinition, resolveScene, render } from './render';
36
+ export type { ChartDefinition, RenderOptions, ResolvedChartState, ChartHandle, RenderApiOptions, OutputOptions } from './render';
37
+ export { ChartParseError, PngBrowserUnsupportedError, MissingNodeRenderDepsError } from './render';
37
38
  export { SceneTransition, getSceneTransition, featureJoin, snapshotLiveAttrs, BC_TRANSITION_NAME, } from './transitions';
38
39
  export type { CommitOptions, TransitionMode, SceneTransitionState, FeatureRole, FeatureJoinConfig, AttrMap, AttrValue, } from './transitions';