@blueprint-chart/lib 0.3.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
@@ -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';