@blueprint-chart/lib 0.3.0 → 1.0.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
@@ -72,7 +72,10 @@ export interface AnnotationLineConfig {
72
72
  circleColor?: string;
73
73
  }
74
74
  interface AnnotationBase {
75
- id?: string;
75
+ /** Internal transition-matching key, assigned during scene resolution. Never author-supplied. */
76
+ key?: string;
77
+ /** How many scenes this annotation lives for: a positive integer count, or 'always'. Defaults to 1. */
78
+ repeat?: number | 'always';
76
79
  text?: string;
77
80
  textColor?: string;
78
81
  textOutline?: boolean;
@@ -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;
@@ -24,7 +24,6 @@ export declare function extractSceneOverrides(scene: SceneNode, chartType: strin
24
24
  highlights: SceneNode['highlights'];
25
25
  areaFills: SceneNode['areaFills'];
26
26
  annotations: SceneNode['annotations'];
27
- annotationVisibility: SceneNode['annotationVisibility'];
28
27
  series: SceneNode['series'];
29
28
  transforms: SceneNode['transforms'];
30
29
  };
@@ -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;
@@ -1,4 +1,4 @@
1
- import { DslNodeType, AnnotationKind, AnnotationAction } from '../enums';
1
+ import { DslNodeType, AnnotationKind } from '../enums';
2
2
  export interface PropertyNode {
3
3
  type: DslNodeType.Property;
4
4
  key: string;
@@ -73,14 +73,6 @@ export interface SeriesNode {
73
73
  /** `//` comment lines authored immediately above this node, text only (no `//`). */
74
74
  leadingComments?: string[];
75
75
  }
76
- export interface AnnotationVisibilityNode {
77
- type: DslNodeType.AnnotationVisibility;
78
- action: AnnotationAction;
79
- kind: AnnotationKind;
80
- id: string;
81
- /** `//` comment lines authored immediately above this node, text only (no `//`). */
82
- leadingComments?: string[];
83
- }
84
76
  export interface SceneNode {
85
77
  type: DslNodeType.Scene;
86
78
  name: string | null;
@@ -90,7 +82,6 @@ export interface SceneNode {
90
82
  highlights: HighlightNode[];
91
83
  areaFills: AreaFillNode[];
92
84
  annotations: AnnotationNode[];
93
- annotationVisibility: AnnotationVisibilityNode[];
94
85
  series: SeriesNode[];
95
86
  transforms: TransformNode[];
96
87
  /** `//` comment lines authored immediately above this node, text only (no `//`). */
@@ -112,7 +103,6 @@ export interface ChartNode {
112
103
  highlights: HighlightNode[];
113
104
  areaFills: AreaFillNode[];
114
105
  annotations: AnnotationNode[];
115
- annotationVisibility: AnnotationVisibilityNode[];
116
106
  series: SeriesNode[];
117
107
  scenes: SceneNode[];
118
108
  transforms: TransformNode[];
package/dist/enums.d.ts CHANGED
@@ -82,10 +82,6 @@ export declare enum AnnotationKind {
82
82
  * (e.g. `point` -> `annotation`, not the enum's raw value).
83
83
  */
84
84
  export declare const ANNOTATION_KIND_KEYWORD: Record<AnnotationKind, string>;
85
- export declare enum AnnotationAction {
86
- Hide = "hide",
87
- Show = "show"
88
- }
89
85
  export declare enum RangeAnchor {
90
86
  Start = "start",
91
87
  Center = "center",
@@ -192,7 +188,6 @@ export declare enum DslNodeType {
192
188
  AreaFill = "area-fill",
193
189
  Annotation = "annotation",
194
190
  Series = "series",
195
- AnnotationVisibility = "annotation-visibility",
196
191
  Scene = "scene",
197
192
  Transform = "transform",
198
193
  Chart = "chart"
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ChartType, AxisDirection, ScaleType, GridStyle, LabelPosition, LabelRotation, TickPosition, FrameSizing, CompassDirection, AnnotationLineStyle, StrokeStyle, AnnotationKind, AnnotationAction, RangeAnchor, Orientation, SymbolShape, SymbolShowOn, SymbolStyle, SortDirection, SortMode, LegendPosition, Anchor, ValueLabelPosition, CrosshairDirection, CrosshairStyle, StackMode, LineStyle, ChartOptionType, DirectLabelMode, Interpolation, DslNodeType, } from './enums';
1
+ export { ChartType, AxisDirection, ScaleType, GridStyle, LabelPosition, LabelRotation, TickPosition, FrameSizing, CompassDirection, AnnotationLineStyle, StrokeStyle, AnnotationKind, RangeAnchor, Orientation, SymbolShape, SymbolShowOn, SymbolStyle, SortDirection, SortMode, LegendPosition, Anchor, ValueLabelPosition, CrosshairDirection, CrosshairStyle, StackMode, LineStyle, ChartOptionType, DirectLabelMode, Interpolation, DslNodeType, } from './enums';
2
2
  export { ANNOTATION_KIND_KEYWORD } from './enums';
3
3
  export type { ChartData, ChartOptions, ChartRenderer, ChartOptionDef, ChartTypeOptions, ChartTypeOptionKey, ColorizeConfig, HighlightConfig, AxisOptions, FrameOptions, AreaFillConfig, AnnotationConfig, PointAnnotationConfig, RangeAnnotationConfig, FreeAnnotationConfig, AnnotationLineConfig, LineSymbolConfig, SeriesOverride, Margin, } from './charts/types';
4
4
  export { createFrame } from './charts/frame/frame';
@@ -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
- export type { AnnotationNode, AnnotationVisibilityNode, PointAnnotationNode, RangeAnnotationNode, FreeAnnotationNode, AreaFillNode, ChartNode, DataNode, ColorizeNode, HighlightNode, PropertyNode, SceneNode, SeriesNode, TransformNode } from './dsl/types';
30
+ export type { AnnotationNode, 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';