@opendata-ai/openchart-core 6.1.1 → 6.1.3
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 +5 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/layout/__tests__/chrome.test.ts +28 -1
- package/src/layout/chrome.ts +38 -3
- package/src/layout/index.ts +2 -0
- package/src/layout/text-measure.ts +6 -0
- package/src/theme/defaults.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2301,6 +2301,10 @@ declare function estimateTextWidth(text: string, fontSize: number, fontWeight?:
|
|
|
2301
2301
|
* overlapping the brand.
|
|
2302
2302
|
*/
|
|
2303
2303
|
declare const BRAND_RESERVE_WIDTH = 110;
|
|
2304
|
+
/** Font size of the brand watermark (px). Shared between layout and renderer. */
|
|
2305
|
+
declare const BRAND_FONT_SIZE = 20;
|
|
2306
|
+
/** Minimum chart width to render the brand watermark (px). */
|
|
2307
|
+
declare const BRAND_MIN_WIDTH = 120;
|
|
2304
2308
|
|
|
2305
2309
|
/**
|
|
2306
2310
|
* Label collision detection and resolution.
|
|
@@ -2601,4 +2605,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
|
|
|
2601
2605
|
*/
|
|
2602
2606
|
declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
|
|
2603
2607
|
|
|
2604
|
-
export { type A11yMetadata, type AggregateOp, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, type ElementEdit, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, GRAPH_ENCODING_RULES, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, type PaginationState, type Point, type PointMark, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness };
|
|
2608
|
+
export { type A11yMetadata, type AggregateOp, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_FONT_SIZE, BRAND_MIN_WIDTH, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, type ElementEdit, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, GRAPH_ENCODING_RULES, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, type PaginationState, type Point, type PointMark, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness };
|
package/dist/index.js
CHANGED
|
@@ -842,7 +842,7 @@ var DEFAULT_THEME = {
|
|
|
842
842
|
}
|
|
843
843
|
},
|
|
844
844
|
spacing: {
|
|
845
|
-
padding:
|
|
845
|
+
padding: 20,
|
|
846
846
|
chromeGap: 4,
|
|
847
847
|
chromeToChart: 8,
|
|
848
848
|
chartToFooter: 8,
|
|
@@ -1014,6 +1014,8 @@ function estimateTextWidth(text, fontSize, fontWeight = 400) {
|
|
|
1014
1014
|
return text.length * estimateCharWidth(fontSize, fontWeight);
|
|
1015
1015
|
}
|
|
1016
1016
|
var BRAND_RESERVE_WIDTH = 110;
|
|
1017
|
+
var BRAND_FONT_SIZE = 20;
|
|
1018
|
+
var BRAND_MIN_WIDTH = 120;
|
|
1017
1019
|
function estimateTextHeight(fontSize, lineCount = 1, lineHeight = 1.3) {
|
|
1018
1020
|
return fontSize * lineHeight * lineCount;
|
|
1019
1021
|
}
|
|
@@ -1116,9 +1118,14 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
1116
1118
|
const hasTopChrome = titleNorm || subtitleNorm;
|
|
1117
1119
|
const topHeight = hasTopChrome ? topY - pad2 + theme.spacing.chromeToChart - chromeGap : 0;
|
|
1118
1120
|
if (chromeMode === "compact") {
|
|
1121
|
+
let compactBottom = 0;
|
|
1122
|
+
if (width >= BRAND_MIN_WIDTH) {
|
|
1123
|
+
const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
1124
|
+
compactBottom = theme.spacing.chartToFooter + brandHeight + pad2;
|
|
1125
|
+
}
|
|
1119
1126
|
return {
|
|
1120
1127
|
topHeight,
|
|
1121
|
-
bottomHeight:
|
|
1128
|
+
bottomHeight: compactBottom,
|
|
1122
1129
|
...topElements
|
|
1123
1130
|
};
|
|
1124
1131
|
}
|
|
@@ -1173,7 +1180,17 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
1173
1180
|
bottomHeight += height + chromeGap;
|
|
1174
1181
|
}
|
|
1175
1182
|
bottomHeight -= chromeGap;
|
|
1183
|
+
if (width >= BRAND_MIN_WIDTH) {
|
|
1184
|
+
const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
1185
|
+
const contentBelowFirstItem = bottomHeight - theme.spacing.chartToFooter;
|
|
1186
|
+
if (brandHeight > contentBelowFirstItem) {
|
|
1187
|
+
bottomHeight += brandHeight - contentBelowFirstItem;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1176
1190
|
bottomHeight += pad2;
|
|
1191
|
+
} else if (width >= BRAND_MIN_WIDTH) {
|
|
1192
|
+
const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
1193
|
+
bottomHeight = theme.spacing.chartToFooter + brandHeight + pad2;
|
|
1177
1194
|
}
|
|
1178
1195
|
return {
|
|
1179
1196
|
topHeight,
|
|
@@ -2660,6 +2677,8 @@ function dataTable(data, options) {
|
|
|
2660
2677
|
return spec;
|
|
2661
2678
|
}
|
|
2662
2679
|
export {
|
|
2680
|
+
BRAND_FONT_SIZE,
|
|
2681
|
+
BRAND_MIN_WIDTH,
|
|
2663
2682
|
BRAND_RESERVE_WIDTH,
|
|
2664
2683
|
CATEGORICAL_PALETTE,
|
|
2665
2684
|
CHART_ENCODING_RULES,
|