minerva-design 1.1.0 → 1.2.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/CHANGELOG.md +8 -0
- package/dist/charts/canvas.d.cts +7 -0
- package/dist/charts/canvas.d.ts +7 -0
- package/dist/charts/core.cjs +1 -1
- package/dist/charts/core.d.cts +5 -1
- package/dist/charts/core.d.ts +5 -1
- package/dist/charts/core.js +4 -1
- package/dist/charts/engine/canvas.cjs +2 -0
- package/dist/charts/engine/canvas.cjs.map +1 -0
- package/dist/charts/engine/canvas.d.cts +85 -0
- package/dist/charts/engine/canvas.d.ts +85 -0
- package/dist/charts/engine/canvas.js +165 -0
- package/dist/charts/engine/canvas.js.map +1 -0
- package/dist/charts/engine/chart.cjs +2 -2
- package/dist/charts/engine/chart.cjs.map +1 -1
- package/dist/charts/engine/chart.js +382 -440
- package/dist/charts/engine/chart.js.map +1 -1
- package/dist/charts/engine/color.cjs +1 -1
- package/dist/charts/engine/color.cjs.map +1 -1
- package/dist/charts/engine/color.d.cts +10 -0
- package/dist/charts/engine/color.d.ts +10 -0
- package/dist/charts/engine/color.js +75 -3
- package/dist/charts/engine/color.js.map +1 -1
- package/dist/charts/engine/controller.cjs +3 -0
- package/dist/charts/engine/controller.cjs.map +1 -0
- package/dist/charts/engine/controller.d.cts +182 -0
- package/dist/charts/engine/controller.d.ts +182 -0
- package/dist/charts/engine/controller.js +528 -0
- package/dist/charts/engine/controller.js.map +1 -0
- package/dist/charts/engine/model.cjs +1 -1
- package/dist/charts/engine/model.cjs.map +1 -1
- package/dist/charts/engine/model.d.cts +2 -2
- package/dist/charts/engine/model.d.ts +2 -2
- package/dist/charts/engine/model.js +72 -72
- package/dist/charts/engine/model.js.map +1 -1
- package/dist/charts/engine/overlay.cjs +1 -1
- package/dist/charts/engine/overlay.cjs.map +1 -1
- package/dist/charts/engine/overlay.d.cts +17 -1
- package/dist/charts/engine/overlay.d.ts +17 -1
- package/dist/charts/engine/overlay.js +63 -49
- package/dist/charts/engine/overlay.js.map +1 -1
- package/dist/charts/engine/presets.cjs +3 -0
- package/dist/charts/engine/presets.cjs.map +1 -0
- package/dist/charts/engine/presets.d.cts +103 -0
- package/dist/charts/engine/presets.d.ts +103 -0
- package/dist/charts/engine/presets.js +153 -0
- package/dist/charts/engine/presets.js.map +1 -0
- package/dist/charts/engine/renderers/canvas2d.cjs +1 -1
- package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -1
- package/dist/charts/engine/renderers/canvas2d.d.cts +17 -1
- package/dist/charts/engine/renderers/canvas2d.d.ts +17 -1
- package/dist/charts/engine/renderers/canvas2d.js +88 -51
- package/dist/charts/engine/renderers/canvas2d.js.map +1 -1
- package/dist/charts/engine/scene.cjs +2 -0
- package/dist/charts/engine/scene.cjs.map +1 -0
- package/dist/charts/engine/scene.d.cts +89 -0
- package/dist/charts/engine/scene.d.ts +89 -0
- package/dist/charts/engine/scene.js +241 -0
- package/dist/charts/engine/scene.js.map +1 -0
- package/dist/charts/engine/theme.cjs +1 -1
- package/dist/charts/engine/theme.cjs.map +1 -1
- package/dist/charts/engine/theme.d.cts +25 -1
- package/dist/charts/engine/theme.d.ts +25 -1
- package/dist/charts/engine/theme.js +42 -26
- package/dist/charts/engine/theme.js.map +1 -1
- package/dist/charts/engine/types.d.cts +69 -2
- package/dist/charts/engine/types.d.ts +69 -2
- package/dist/charts/index.cjs +1 -1
- package/dist/charts/index.d.cts +1 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.js +5 -2
- package/dist/charts/react/Chart.cjs +1 -1
- package/dist/charts/react/Chart.cjs.map +1 -1
- package/dist/charts/react/Chart.d.cts +11 -4
- package/dist/charts/react/Chart.d.ts +11 -4
- package/dist/charts/react/Chart.js +81 -39
- package/dist/charts/react/Chart.js.map +1 -1
- package/dist/charts/react/charts.cjs +1 -1
- package/dist/charts/react/charts.cjs.map +1 -1
- package/dist/charts/react/charts.d.cts +1 -1
- package/dist/charts/react/charts.d.ts +1 -1
- package/dist/charts/react/charts.js +99 -145
- package/dist/charts/react/charts.js.map +1 -1
- package/dist/charts/react/types.d.cts +29 -61
- package/dist/charts/react/types.d.ts +29 -61
- package/dist/native/charts/src/canvas.cjs +1 -0
- package/dist/native/charts/src/canvas.js +6 -0
- package/dist/native/charts/src/engine/axis.cjs +2 -0
- package/dist/native/charts/src/engine/axis.cjs.map +1 -0
- package/dist/native/charts/src/engine/axis.js +38 -0
- package/dist/native/charts/src/engine/axis.js.map +1 -0
- package/dist/native/charts/src/engine/canvas.cjs +1 -0
- package/dist/native/charts/src/engine/canvas.js +1 -0
- package/dist/native/charts/src/engine/color.cjs +2 -0
- package/dist/native/charts/src/engine/color.cjs.map +1 -0
- package/dist/native/charts/src/engine/color.js +130 -0
- package/dist/native/charts/src/engine/color.js.map +1 -0
- package/dist/native/charts/src/engine/controller.cjs +3 -0
- package/dist/native/charts/src/engine/controller.cjs.map +1 -0
- package/dist/native/charts/src/engine/controller.js +528 -0
- package/dist/native/charts/src/engine/controller.js.map +1 -0
- package/dist/native/charts/src/engine/data.cjs +2 -0
- package/dist/native/charts/src/engine/data.cjs.map +1 -0
- package/dist/native/charts/src/engine/data.js +104 -0
- package/dist/native/charts/src/engine/data.js.map +1 -0
- package/dist/native/charts/src/engine/decimate.cjs +2 -0
- package/dist/native/charts/src/engine/decimate.cjs.map +1 -0
- package/dist/native/charts/src/engine/decimate.js +28 -0
- package/dist/native/charts/src/engine/decimate.js.map +1 -0
- package/dist/native/charts/src/engine/format.cjs +2 -0
- package/dist/native/charts/src/engine/format.cjs.map +1 -0
- package/dist/native/charts/src/engine/format.js +34 -0
- package/dist/native/charts/src/engine/format.js.map +1 -0
- package/dist/native/charts/src/engine/layout.cjs +2 -0
- package/dist/native/charts/src/engine/layout.cjs.map +1 -0
- package/dist/native/charts/src/engine/layout.js +26 -0
- package/dist/native/charts/src/engine/layout.js.map +1 -0
- package/dist/native/charts/src/engine/model.cjs +2 -0
- package/dist/native/charts/src/engine/model.cjs.map +1 -0
- package/dist/native/charts/src/engine/model.js +175 -0
- package/dist/native/charts/src/engine/model.js.map +1 -0
- package/dist/native/charts/src/engine/overlay.cjs +2 -0
- package/dist/native/charts/src/engine/overlay.cjs.map +1 -0
- package/dist/native/charts/src/engine/overlay.js +49 -0
- package/dist/native/charts/src/engine/overlay.js.map +1 -0
- package/dist/native/charts/src/engine/presets.cjs +3 -0
- package/dist/native/charts/src/engine/presets.cjs.map +1 -0
- package/dist/native/charts/src/engine/presets.js +147 -0
- package/dist/native/charts/src/engine/presets.js.map +1 -0
- package/dist/native/charts/src/engine/scale.cjs +2 -0
- package/dist/native/charts/src/engine/scale.cjs.map +1 -0
- package/dist/native/charts/src/engine/scale.js +37 -0
- package/dist/native/charts/src/engine/scale.js.map +1 -0
- package/dist/native/charts/src/engine/scene.cjs +2 -0
- package/dist/native/charts/src/engine/scene.cjs.map +1 -0
- package/dist/native/charts/src/engine/scene.js +241 -0
- package/dist/native/charts/src/engine/scene.js.map +1 -0
- package/dist/native/charts/src/engine/spatial.cjs +2 -0
- package/dist/native/charts/src/engine/spatial.cjs.map +1 -0
- package/dist/native/charts/src/engine/spatial.js +53 -0
- package/dist/native/charts/src/engine/spatial.js.map +1 -0
- package/dist/native/charts/src/engine/theme.cjs +2 -0
- package/dist/native/charts/src/engine/theme.cjs.map +1 -0
- package/dist/native/charts/src/engine/theme.js +62 -0
- package/dist/native/charts/src/engine/theme.js.map +1 -0
- package/dist/native/charts/src/engine/time.cjs +2 -0
- package/dist/native/charts/src/engine/time.cjs.map +1 -0
- package/dist/native/charts/src/engine/time.js +189 -0
- package/dist/native/charts/src/engine/time.js.map +1 -0
- package/dist/native/charts/src/engine/viewport.cjs +2 -0
- package/dist/native/charts/src/engine/viewport.cjs.map +1 -0
- package/dist/native/charts/src/engine/viewport.js +12 -0
- package/dist/native/charts/src/engine/viewport.js.map +1 -0
- package/dist/native/components/Chart/ChartBase.cjs +2 -0
- package/dist/native/components/Chart/ChartBase.cjs.map +1 -0
- package/dist/native/components/Chart/ChartBase.d.cts +29 -0
- package/dist/native/components/Chart/ChartBase.d.ts +29 -0
- package/dist/native/components/Chart/ChartBase.js +287 -0
- package/dist/native/components/Chart/ChartBase.js.map +1 -0
- package/dist/native/components/Chart/charts.cjs +2 -0
- package/dist/native/components/Chart/charts.cjs.map +1 -0
- package/dist/native/components/Chart/charts.d.cts +19 -0
- package/dist/native/components/Chart/charts.d.ts +19 -0
- package/dist/native/components/Chart/charts.js +173 -0
- package/dist/native/components/Chart/charts.js.map +1 -0
- package/dist/native/components/Chart/index.cjs +1 -0
- package/dist/native/components/Chart/index.d.cts +2 -0
- package/dist/native/components/Chart/index.d.ts +2 -0
- package/dist/native/components/Chart/index.js +2 -0
- package/dist/native/components/Chart/measure.cjs +2 -0
- package/dist/native/components/Chart/measure.cjs.map +1 -0
- package/dist/native/components/Chart/measure.d.cts +5 -0
- package/dist/native/components/Chart/measure.d.ts +5 -0
- package/dist/native/components/Chart/measure.js +11 -0
- package/dist/native/components/Chart/measure.js.map +1 -0
- package/dist/native/components/Chart/scene.cjs +2 -0
- package/dist/native/components/Chart/scene.cjs.map +1 -0
- package/dist/native/components/Chart/scene.d.cts +41 -0
- package/dist/native/components/Chart/scene.d.ts +41 -0
- package/dist/native/components/Chart/scene.js +419 -0
- package/dist/native/components/Chart/scene.js.map +1 -0
- package/dist/native/components/Chart/theme.cjs +2 -0
- package/dist/native/components/Chart/theme.cjs.map +1 -0
- package/dist/native/components/Chart/theme.d.cts +10 -0
- package/dist/native/components/Chart/theme.d.ts +10 -0
- package/dist/native/components/Chart/theme.js +10 -0
- package/dist/native/components/Chart/theme.js.map +1 -0
- package/dist/native/components/Chart/types.d.cts +129 -0
- package/dist/native/components/Chart/types.d.ts +129 -0
- package/dist/native/index.cjs +1 -1
- package/dist/native/index.d.cts +1 -0
- package/dist/native/index.d.ts +1 -0
- package/dist/native/index.js +6 -4
- package/dist/native/manifest.d.cts +7 -0
- package/dist/native/manifest.d.ts +7 -0
- package/dist/native/source/components/Chart/ChartBase.tsx +545 -0
- package/dist/native/source/components/Chart/charts.tsx +291 -0
- package/dist/native/source/components/Chart/index.ts +8 -0
- package/dist/native/source/components/Chart/measure.ts +50 -0
- package/dist/native/source/components/Chart/scene.tsx +987 -0
- package/dist/native/source/components/Chart/theme.ts +16 -0
- package/dist/native/source/components/Chart/types.ts +194 -0
- package/dist/native/source/index.ts +1 -0
- package/dist/native/source/manifest.ts +14 -0
- package/dist/taro/charts.d.ts +144 -0
- package/dist/taro/index.d.ts +1 -0
- package/dist/taro/index.js +3064 -618
- package/dist/uni/BarChart.vue +75 -0
- package/dist/uni/BarChart.vue.d.ts +111 -0
- package/dist/uni/Chart.vue +68 -0
- package/dist/uni/Chart.vue.d.ts +100 -0
- package/dist/uni/LineChart.vue +75 -0
- package/dist/uni/LineChart.vue.d.ts +111 -0
- package/dist/uni/ProgressIndicator.vue.d.ts +1 -1
- package/dist/uni/QuadrantChart.vue +184 -0
- package/dist/uni/QuadrantChart.vue.d.ts +173 -0
- package/dist/uni/ScatterChart.vue +69 -0
- package/dist/uni/ScatterChart.vue.d.ts +100 -0
- package/dist/uni/chart-canvas.d.ts +68 -0
- package/dist/uni/chart-canvas.js +363 -0
- package/dist/uni/chart-types.d.ts +135 -0
- package/dist/uni/chart-types.js +84 -0
- package/dist/uni/charts-canvas.d.ts +1 -0
- package/dist/uni/charts-canvas.js +8 -0
- package/dist/uni/index.d.ts +6 -0
- package/dist/uni/index.js +6 -0
- package/dist/weapp/bar-chart/index.js +1 -0
- package/dist/weapp/bar-chart/index.json +1 -0
- package/dist/weapp/bar-chart/index.wxml +1 -0
- package/dist/weapp/bar-chart/index.wxss +1 -0
- package/dist/weapp/chart/index.js +1 -0
- package/dist/weapp/chart/index.json +1 -0
- package/dist/weapp/chart/index.wxml +1 -0
- package/dist/weapp/chart/index.wxss +1 -0
- package/dist/weapp/controls.js +4019 -266
- package/dist/weapp/line-chart/index.js +1 -0
- package/dist/weapp/line-chart/index.json +1 -0
- package/dist/weapp/line-chart/index.wxml +1 -0
- package/dist/weapp/line-chart/index.wxss +1 -0
- package/dist/weapp/quadrant-chart/index.js +1 -0
- package/dist/weapp/quadrant-chart/index.json +1 -0
- package/dist/weapp/quadrant-chart/index.wxml +1 -0
- package/dist/weapp/quadrant-chart/index.wxss +1 -0
- package/dist/weapp/scatter-chart/index.js +1 -0
- package/dist/weapp/scatter-chart/index.json +1 -0
- package/dist/weapp/scatter-chart/index.wxml +1 -0
- package/dist/weapp/scatter-chart/index.wxss +1 -0
- package/dist/weapp/types.d.ts +295 -0
- package/package.json +21 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene.js","names":["DEFAULT_PADDING","fallbackResolve","fallback","resolveAnnotations","resolve","theme","annotations","a","color","mix","layoutChart","input","yCount","model","height","yTicks","axisTicks","view","yLabelWidth","label","measure","categoryWidth","step","i","padding","plot","computePlot","xCount","xTicks","createScales","collectPointLabels","labels","series","texts","count","text","xi","x","yi","y","d","size","s","pointOf","xv","yv","sc","candidateOf","p","inside","half","base","px","py","dotSize","nearestScatter","radius","slop","rx","ry","best","bestDist","gridOf","nearestX","sorted","nearestIndex","bestD","hoverItemOf","pc","index","toCss","eventOf","candidates","b","items","c","hitTest","margin","scatter","others","all","bestDx","bandPx","aligned","first","event","sameHover","it","tooltipContent","yFormat","rows","hoverMarks","marks","cx","showsCrosshair","crosshair"],"sources":["../../../../charts/src/engine/scene.ts"],"sourcesContent":["// The DOM-free half of a chart: annotations, layout, point labels, hit\n// testing and tooltip content. Shared by createChart (DOM + GPU),\n// createCanvasChart (any 2D context) and the React Native views.\n\nimport { axisTicks, type AxisTicks } from \"./axis\";\nimport { mix, toCss, type Rgba } from \"./color\";\nimport { nearestIndex } from \"./data\";\nimport { computePlot, createScales, type Rect, type Scales } from \"./layout\";\nimport { gridOf, type ChartModel, type SeriesModel } from \"./model\";\nimport type { PointLabel, ResolvedAnnotation } from \"./overlay\";\nimport type { ChartTheme } from \"./theme\";\nimport type {\n ChartAnnotation,\n ChartHoverEvent,\n ChartHoverItem,\n ChartPadding,\n ChartView,\n} from \"./types\";\n\nexport const MAX_POINT_LABELS = 300;\nexport const DEFAULT_PADDING = { top: 12, right: 16, bottom: 4, left: 4 };\n\nexport const fallbackResolve = (_value: string, fallback: Rgba) => fallback;\n\n/** Annotation colors resolved against the theme */\nexport const resolveAnnotations = (\n annotations: readonly ChartAnnotation[] | undefined,\n theme: ChartTheme,\n): ResolvedAnnotation[] => {\n const resolve = theme.resolve ?? fallbackResolve;\n return (annotations ?? []).map((a) => {\n if (a.type === \"rect\") {\n const color = a.color ? resolve(a.color, theme.primary) : theme.primary;\n return {\n type: \"rect\",\n x0: a.x0,\n x1: a.x1,\n y0: a.y0,\n y1: a.y1,\n color,\n opacity: a.opacity ?? 0.08,\n label: a.label,\n labelPosition: a.labelPosition ?? \"top-left\",\n labelColor: a.labelColor\n ? resolve(a.labelColor, color)\n : mix(color, theme.text, 0.2),\n };\n }\n if (a.type === \"text\") {\n return {\n type: \"text\",\n x: a.x,\n y: a.y,\n text: a.text,\n anchor: a.anchor ?? \"center\",\n color: a.color ? resolve(a.color, theme.textMuted) : theme.textMuted,\n weight: a.weight ?? 500,\n };\n }\n return {\n type: \"line\",\n axis: a.axis,\n value: a.value,\n color: a.color ? resolve(a.color, theme.textMuted) : theme.textMuted,\n width: a.width ?? 1,\n dash: [...(a.dash ?? [4, 4])],\n label: a.label,\n };\n });\n};\n\nexport interface ChartLayout {\n plot: Rect;\n scales: Scales;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n}\n\nexport interface LayoutInput {\n model: ChartModel;\n view: ChartView;\n theme: ChartTheme;\n /** Size of the drawing area (legend excluded), CSS pixels */\n width: number;\n height: number;\n padding?: ChartPadding;\n /** Offset of the drawing area (e.g. below a legend) */\n top?: number;\n /** Width of a tick label in the theme font */\n measure: (text: string) => number;\n}\n\n/** Ticks, room for the axes and the plot rectangle */\nexport const layoutChart = (input: LayoutInput): ChartLayout => {\n const { model, view, theme, width, height, measure } = input;\n // same count as the nice range of the model (its ends are then ticks),\n // fewer on short charts\n const yCount =\n model.y.tickCount ??\n (height >= 220 ? 5 : Math.max(2, Math.round((height - 48) / 52)));\n const yTicks = axisTicks(model.y, view.y, yCount);\n let yLabelWidth = 0;\n if (model.y.visible) {\n for (const label of yTicks.labels)\n yLabelWidth = Math.max(yLabelWidth, measure(label));\n }\n let categoryWidth = 48;\n if (model.x.type === \"category\") {\n categoryWidth = 0;\n const step = Math.max(1, Math.floor(model.x.categories.length / 200));\n for (let i = 0; i < model.x.categories.length; i += step) {\n categoryWidth = Math.max(categoryWidth, measure(model.x.categories[i]));\n }\n }\n const padding = { ...DEFAULT_PADDING, ...input.padding };\n const plot = computePlot({\n width,\n height,\n padding,\n yLabelWidth: model.y.visible ? Math.ceil(yLabelWidth) : 0,\n xAxisVisible: model.x.visible,\n xTitle: !!model.x.title && model.x.visible,\n yTitle: !!model.y.title && model.y.visible,\n fontSize: theme.fontSize,\n });\n if (input.top) plot.y += input.top;\n const xCount =\n model.x.type === \"category\"\n ? Math.max(1, Math.floor(plot.width / (categoryWidth + 14)))\n : (model.x.tickCount ?? Math.max(2, Math.floor(plot.width / 96)));\n const xTicks = axisTicks(model.x, view.x, xCount);\n const scales = createScales(plot, view, model.x.reverse, model.y.reverse);\n return { plot, scales, xTicks, yTicks };\n};\n\n/** Labels of the visible scatter points (`showLabels`) */\nexport const collectPointLabels = (\n model: ChartModel,\n view: ChartView,\n s: Scales,\n): PointLabel[] => {\n const labels: PointLabel[] = [];\n for (const series of model.series) {\n if (series.hidden || series.type !== \"scatter\" || !series.showLabels)\n continue;\n const { x, y, count, labels: texts, size } = series.cols;\n if (!texts) continue;\n for (let i = 0; i < count && labels.length < MAX_POINT_LABELS; i++) {\n const text = texts[i];\n if (!text) continue;\n const xi = x[i];\n const yi = y[i];\n if (xi < view.x[0] || xi > view.x[1] || yi < view.y[0] || yi > view.y[1])\n continue;\n const d = size && size[i] > 0 ? size[i] : series.pointSize;\n labels.push({ x: s.xToPx(xi), y: s.yToPx(yi), r: d / 2, text });\n }\n }\n return labels;\n};\n\n// ---------------------------------------------------------------- hit tests\n\ninterface Candidate {\n series: SeriesModel;\n index: number;\n /** Pixel position of the point */\n px: number;\n py: number;\n dx: number;\n dist: number;\n inside: boolean;\n}\n\n/** Pixel position of a point (the top of a bar) */\nexport const pointOf = (s: SeriesModel, i: number, sc: Scales) => {\n const xv = s.cols.x[i] + (s.type === \"bar\" ? s.barOffset : 0);\n const yv = s.type === \"bar\" && s.barTop ? s.barTop[i] : s.cols.y[i];\n return { px: sc.xToPx(xv), py: sc.yToPx(yv) };\n};\n\nconst candidateOf = (\n s: SeriesModel,\n i: number,\n px: number,\n py: number,\n sc: Scales,\n): Candidate => {\n const p = pointOf(s, i, sc);\n let inside = false;\n if (s.type === \"bar\" && s.barBase) {\n const half = s.barHalfWidth / sc.xPerPx;\n const base = sc.yToPx(s.barBase[i]);\n inside =\n Math.abs(px - p.px) <= half &&\n py >= Math.min(base, p.py) - 2 &&\n py <= Math.max(base, p.py) + 2;\n }\n return {\n series: s,\n index: i,\n px: p.px,\n py: p.py,\n dx: Math.abs(sc.xToPx(s.cols.x[i]) - px),\n dist: inside ? 0 : Math.hypot(p.px - px, p.py - py),\n inside,\n };\n};\n\n/** Diameter of a scatter dot */\nexport const dotSize = (s: SeriesModel, i: number) =>\n s.cols.size && s.cols.size[i] > 0 ? s.cols.size[i] : s.pointSize;\n\nconst nearestScatter = (\n s: SeriesModel,\n px: number,\n py: number,\n sc: Scales,\n slop: number,\n) => {\n const radius = Math.max(s.pointSize / 2 + 6, 10) + slop;\n const xv = sc.pxToX(px);\n const yv = sc.pxToY(py);\n const rx = radius * sc.xPerPx;\n const ry = radius * sc.yPerPx;\n let best = -1;\n let bestDist = Infinity;\n const { x, y } = s.cols;\n gridOf(s).query(xv - rx, xv + rx, yv - ry, yv + ry, (i) => {\n const d = Math.hypot(sc.xToPx(x[i]) - px, sc.yToPx(y[i]) - py);\n const reach = Math.max(dotSize(s, i) / 2 + 4, 8) + slop;\n if (d <= reach && d <= bestDist) {\n bestDist = d;\n best = i;\n }\n });\n return best;\n};\n\nconst nearestX = (s: SeriesModel, xv: number) => {\n const { x, y, count, sorted } = s.cols;\n if (sorted) return nearestIndex(x, y, count, xv);\n let best = -1;\n let bestD = Infinity;\n for (let i = 0; i < count; i++) {\n if (!Number.isFinite(y[i])) continue;\n const d = Math.abs(x[i] - xv);\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n }\n return best;\n};\n\n/** Hover payload item of a point */\nexport const hoverItemOf = (s: SeriesModel, index: number): ChartHoverItem => {\n const pc = s.pointColors?.[index];\n const label = s.cols.labels?.[index];\n return {\n seriesIndex: s.index,\n seriesId: s.id,\n seriesName: s.name,\n index,\n x: s.cols.x[index],\n y: s.cols.y[index],\n color: pc ? toCss(pc) : s.colorCss,\n ...(label !== undefined ? { label } : {}),\n };\n};\n\nconst eventOf = (\n candidates: Candidate[],\n xTicks: AxisTicks | null,\n): ChartHoverEvent | null => {\n if (!candidates.length) return null;\n candidates.sort((a, b) => a.series.index - b.series.index);\n const items = candidates.map((c) => hoverItemOf(c.series, c.index));\n const x = items[0].x;\n return { items, x, xLabel: xTicks?.formatValue(x) ?? String(x) };\n};\n\n/**\n * Points under a pixel of the stage: the nearest point (scatter / `nearest`\n * tooltips) or every series at the nearest x (`axis` tooltips).\n * `slop` widens the reach of the dots (touch screens).\n */\nexport const hitTest = (\n model: ChartModel,\n sc: Scales,\n xTicks: AxisTicks | null,\n px: number,\n py: number,\n slop = 0,\n): ChartHoverEvent | null => {\n const { plot } = sc;\n const margin = 6 + slop;\n if (\n px < plot.x - margin ||\n px > plot.x + plot.width + margin ||\n py < plot.y - margin ||\n py > plot.y + plot.height + margin\n ) {\n return null;\n }\n const xv = sc.pxToX(px);\n const scatter: Candidate[] = [];\n const others: Candidate[] = [];\n for (const s of model.series) {\n if (s.hidden || s.cols.count === 0) continue;\n if (s.type === \"scatter\") {\n const i = nearestScatter(s, px, py, sc, slop);\n if (i >= 0) scatter.push(candidateOf(s, i, px, py, sc));\n } else {\n const i = nearestX(s, xv);\n if (i >= 0) others.push(candidateOf(s, i, px, py, sc));\n }\n }\n if (model.tooltipMode === \"nearest\") {\n const all = [...scatter, ...others].filter(\n (c) => c.inside || c.series.type === \"scatter\" || c.dist <= 32 + slop,\n );\n if (!all.length) return null;\n const best = all.reduce((a, b) => (b.dist <= a.dist ? b : a));\n return eventOf([best], xTicks);\n }\n if (!others.length) {\n if (!scatter.length) return null;\n return eventOf(\n [scatter.reduce((a, b) => (b.dist <= a.dist ? b : a))],\n xTicks,\n );\n }\n const bestDx = Math.min(...others.map((c) => c.dx));\n const bandPx = model.x.type === \"category\" ? 0.5 / sc.xPerPx : 0;\n const aligned = others.filter((c) => c.dx <= bestDx + Math.max(1, bandPx));\n const first = aligned.reduce((a, b) => (b.dx < a.dx ? b : a));\n const ordered = [first, ...aligned.filter((c) => c !== first), ...scatter];\n const event = eventOf(ordered, xTicks);\n if (event) {\n event.x = hoverItemOf(first.series, first.index).x;\n event.xLabel = xTicks?.formatValue(event.x) ?? String(event.x);\n }\n return event;\n};\n\n/** Whether two hover payloads point at the same points */\nexport const sameHover = (\n a: ChartHoverEvent | null,\n b: ChartHoverEvent | null,\n): boolean =>\n a === b ||\n (!!a &&\n !!b &&\n a.items.length === b.items.length &&\n a.items.every(\n (it, i) =>\n it.index === b.items[i].index &&\n it.seriesIndex === b.items[i].seriesIndex,\n ));\n\n// ------------------------------------------------------------------ tooltip\n\nexport interface TooltipRow {\n /** Swatch color (CSS) */\n color: string | null;\n name: string;\n value: string;\n}\n\nexport interface TooltipContent {\n title: string;\n /** Swatch of the title (single scatter point) */\n titleColor: string | null;\n rows: TooltipRow[];\n}\n\n/** Default tooltip content of a hover payload */\nexport const tooltipContent = (\n model: ChartModel,\n event: ChartHoverEvent,\n yTicks: AxisTicks | null,\n): TooltipContent => {\n const yFormat = yTicks?.formatValue ?? String;\n const scatterOnly = event.items.every(\n (it) => model.series[it.seriesIndex].type === \"scatter\",\n );\n if (scatterOnly && event.items.length === 1) {\n const it = event.items[0];\n const rows: TooltipRow[] = [\n { color: null, name: model.x.title ?? \"x\", value: event.xLabel },\n { color: null, name: model.y.title ?? \"y\", value: yFormat(it.y) },\n ];\n if (it.label !== undefined && model.series.length > 1)\n rows.push({ color: null, name: \"\", value: it.seriesName });\n return { title: it.label ?? it.seriesName, titleColor: it.color, rows };\n }\n return {\n title: event.xLabel,\n titleColor: null,\n rows: event.items.map((it) => ({\n color: it.color,\n name: it.label ? `${it.seriesName} · ${it.label}` : it.seriesName,\n value: yFormat(it.y),\n })),\n };\n};\n\n/** Shape of the hover marker of an item: a ring on a point, or a bar highlight */\nexport type HoverMark =\n | { kind: \"dot\"; x: number; y: number; size: number; color: string }\n | { kind: \"bar\"; x: number; y: number; width: number; height: number };\n\n/** Markers of the hovered points (pixels of the stage) */\nexport const hoverMarks = (\n model: ChartModel,\n sc: Scales,\n event: ChartHoverEvent,\n): HoverMark[] => {\n const marks: HoverMark[] = [];\n const { plot } = sc;\n for (const it of event.items) {\n const s = model.series[it.seriesIndex];\n if (s.type === \"bar\" && s.barBase && s.barTop) {\n const cx = sc.xToPx(it.x + s.barOffset);\n const half = Math.max(s.barHalfWidth / sc.xPerPx, 1);\n const a = sc.yToPx(s.barBase[it.index]);\n const b = sc.yToPx(s.barTop[it.index]);\n marks.push({\n kind: \"bar\",\n x: cx - half,\n y: Math.min(a, b),\n width: half * 2,\n height: Math.max(1, Math.abs(a - b)),\n });\n continue;\n }\n const px = sc.xToPx(it.x);\n const py = sc.yToPx(it.y);\n if (\n px < plot.x - 1 ||\n px > plot.x + plot.width + 1 ||\n py < plot.y - 1 ||\n py > plot.y + plot.height + 1\n ) {\n continue;\n }\n const size =\n s.type === \"scatter\"\n ? dotSize(s, it.index) + 6\n : Math.max(10, s.lineWidth * 2 + 6);\n marks.push({ kind: \"dot\", x: px, y: py, size, color: it.color });\n }\n return marks;\n};\n\n/** Whether the guide line follows the pointer */\nexport const showsCrosshair = (\n model: ChartModel,\n event: ChartHoverEvent,\n crosshair: boolean | undefined,\n) =>\n crosshair ??\n (model.tooltipMode === \"axis\" &&\n event.items.some((it) => model.series[it.seriesIndex].type !== \"scatter\"));\n"],"mappings":";;;;;AAoBA,IAAaA,IAAkB;CAAE,KAAK;CAAI,OAAO;CAAI,QAAQ;CAAG,MAAM;AAAE,GAE3DC,KAAmB,GAAgB,MAAmBC,GAGtDC,KACX,GACA,MACyB;CACzB,IAAMC,IAAUC,EAAM,WAAWJ;CACjC,QAAQK,KAAe,CAAC,EAAA,CAAG,KAAK,MAAM;EACpC,IAAIC,EAAE,SAAS,QAAQ;GACrB,IAAMC,IAAQD,EAAE,QAAQH,EAAQG,EAAE,OAAOF,EAAM,OAAO,IAAIA,EAAM;GAChE,OAAO;IACL,MAAM;IACN,IAAIE,EAAE;IACN,IAAIA,EAAE;IACN,IAAIA,EAAE;IACN,IAAIA,EAAE;IACN;IACA,SAASA,EAAE,WAAW;IACtB,OAAOA,EAAE;IACT,eAAeA,EAAE,iBAAiB;IAClC,YAAYA,EAAE,aACVH,EAAQG,EAAE,YAAYC,CAAK,IAC3BC,EAAID,GAAOH,EAAM,MAAM,EAAG;GAChC;EACF;EAYA,OAXIE,EAAE,SAAS,SACN;GACL,MAAM;GACN,GAAGA,EAAE;GACL,GAAGA,EAAE;GACL,MAAMA,EAAE;GACR,QAAQA,EAAE,UAAU;GACpB,OAAOA,EAAE,QAAQH,EAAQG,EAAE,OAAOF,EAAM,SAAS,IAAIA,EAAM;GAC3D,QAAQE,EAAE,UAAU;EACtB,IAEK;GACL,MAAM;GACN,MAAMA,EAAE;GACR,OAAOA,EAAE;GACT,OAAOA,EAAE,QAAQH,EAAQG,EAAE,OAAOF,EAAM,SAAS,IAAIA,EAAM;GAC3D,OAAOE,EAAE,SAAS;GAClB,MAAM,CAAC,GAAIA,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAE;GAC5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rB,IAAKN,EAAG,MAAMyC,EAAG,CAAC,GAClBlC,IAAKP,EAAG,MAAMyC,EAAG,CAAC;EACxB,IACEnC,IAAK3B,EAAK,IAAI,KACd2B,IAAK3B,EAAK,IAAIA,EAAK,QAAQ,KAC3B4B,IAAK5B,EAAK,IAAI,KACd4B,IAAK5B,EAAK,IAAIA,EAAK,SAAS,GAE5B;EAEF,IAAMgB,IACJC,EAAE,SAAS,YACPY,EAAQZ,GAAG6C,EAAG,KAAK,IAAI,IACvB,KAAK,IAAI,IAAI7C,EAAE,YAAY,IAAI,CAAC;EACtC,EAAM,KAAK;GAAE,MAAM;GAAO,GAAGU;GAAI,GAAGC;GAAI;GAAM,OAAOkC,EAAG;EAAM,CAAC;CACjE;CACA,OAAOK;AACT,GAGaE,KACX,GACA,GACA,MAEAC,MACClF,EAAM,gBAAgB,UACrBwE,EAAM,MAAM,MAAM,MAAOxE,EAAM,OAAO0E,EAAG,YAAY,CAAC,SAAS,SAAS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./color.cjs");var t=[`#4f46e5`,`#10b981`,`#f59e0b`,`#ef4444`,`#0ea5e9`,`#8b5cf6`,`#14b8a6`,`#f97316`],n=(e,t)=>e?.getPropertyValue(t).trim()??``,r=(r
|
|
1
|
+
const e=require("./color.cjs");var t=[`#4f46e5`,`#10b981`,`#f59e0b`,`#ef4444`,`#0ea5e9`,`#8b5cf6`,`#14b8a6`,`#f97316`],n=(e,t)=>e?.getPropertyValue(t).trim()??``,r=(t,r)=>{let i=t&&typeof getComputedStyle==`function`?getComputedStyle(t):null;return o(e=>n(i,e),e.domColorResolver(t),r,i?.fontFamily??``)},i=(e={},t)=>{let n=e.variables??{};return{...o(e=>n[e]?.trim()??``,a(n),t?.length?t:e.palette,``),...e.fontFamily?{fontFamily:e.fontFamily}:{},...e.fontSize?{fontSize:e.fontSize}:{}}},a=t=>(n,r)=>e.resolveStaticColor(n,t,r),o=(n,r,i,a)=>{let o=[.4,.4,.4,1],s=e=>r(e,o),c=(e,t)=>{for(let t of e)if(n(t))return s(`var(${t})`);return s(t)},l=c([`--surface-color`,`--background-color`],`#ffffff`),u=c([`--text-color`],`#1f2937`),d=c([`--text-secondary-color`,`--text-muted-color`],`#6b7280`),f=c([`--border-color`],`#e5e7eb`),p;if(i&&i.length)p=i.map(e=>s(e));else{let e=[];for(let t=1;t<=8;t++){let r=`--chart-series-${t}`;n(r)&&e.push(s(`var(${r})`))}p=e.length?e:[...[`--primary-color`,`--success-color`,`--warning-color`,`--danger-color`,`--info-color`].map((e,r)=>n(e)?s(`var(${e})`):s(t[r])),...t.slice(5).map(e=>s(e))]}let m=n(`--font-family-sans`)||a||`system-ui, -apple-system, 'Segoe UI', sans-serif`;return{palette:p,text:u,textMuted:d,grid:e.mix(l,f,.75),axis:f,background:l,surface:l,primary:p[0],fontFamily:m,fontSize:11,resolve:r}},s=e=>{if(typeof document>`u`)return()=>{};let t=[];if(typeof MutationObserver==`function`){let n=new MutationObserver(e);for(let e of[document.documentElement,document.body])e&&n.observe(e,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-mode`]});t.push(()=>n.disconnect())}if(typeof matchMedia==`function`){let n=matchMedia(`(prefers-color-scheme: dark)`);n.addEventListener?.(`change`,e),t.push(()=>n.removeEventListener?.(`change`,e))}return()=>t.forEach(e=>e())};exports.createTheme=i,exports.readTheme=r,exports.staticColorResolver=a,exports.watchTheme=s;
|
|
2
2
|
//# sourceMappingURL=theme.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.cjs","names":["
|
|
1
|
+
{"version":3,"file":"theme.cjs","names":["domColorResolver","resolveStaticColor","mix","require_color","DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","palette","createTheme","variables","input","staticColorResolver","value","fallback","fallbackGray","resolveColor","resolve","color","names","readVariable","background","text","textMuted","border","colors","c","custom","i","fontFamily","inheritedFont","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n mix,\n resolveStaticColor,\n type ColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/** Reads the theme from the computed style of `element` */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n domColorResolver(element),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":"+BA2BA,IAAMI,EAAkB,CACtB,UACA,UACA,UACA,UACA,UACA,UACA,UACA,SACF,EAEMC,GAAW,EAAmC,IAClDC,GAAO,iBAAiBC,CAAI,CAAC,CAAC,KAAK,GAAK,GAG7BC,GACX,EACA,IACe,CACf,IAAMF,EACJG,GAAW,OAAO,kBAAqB,WACnC,iBAAiBA,CAAO,EACxB,KACN,OAAOC,EACJ,GAASL,EAAQC,EAAOC,CAAI,EAC7BP,EAAAA,iBAAiBS,CAAO,EACxBE,EACAL,GAAO,YAAc,EACvB,CACF,EAsBaM,GACX,EAAyB,CAAC,EAC1B,IACe,CACf,IAAMC,EAAYC,EAAM,WAAa,CAAC,EAOtC,MAAO,CACL,GAPYJ,EACX,GAASG,EAAUN,EAAK,EAAE,KAAK,GAAK,GACrCQ,EAAoBF,CAAS,EAC7BF,GAAS,OAASA,EAAUG,EAAM,QAClC,EAGG,EACH,GAAIA,EAAM,WAAa,CAAE,WAAYA,EAAM,UAAW,EAAI,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oBAAoB,GACjCU,GACA,mDAEF,MAAO,CACL,QAASL,EACT,OACA,YACA,KAAM1B,EAAAA,IAAIsB,EAAYG,EAAQ,GAAI,EAClC,KAAMA,EACN,aACA,QAASH,EACT,QAASI,EAAO,GAChB,aACA,SAAU,GACV,SACF,CACF,EAMaM,EAAc,GAAuC,CAChE,GAAI,OAAO,SAAa,IAAa,UAAa,CAAC,EACnD,IAAMC,EAA2B,CAAC,EAClC,GAAI,OAAO,kBAAqB,WAAY,CAC1C,IAAMC,EAAW,IAAI,iBAAiBC,CAAQ,EAC9C,IAAK,IAAMC,IAAQ,CAAC,SAAS,gBAAiB,SAAS,IAAI,EACrDA,GACFF,EAAS,QAAQE,EAAM,CACrB,WAAY,GACZ,gBAAiB,CAAC,QAAS,QAAS,aAAc,WAAW,CAC/D,CAAC,EAGLH,EAAS,SAAWC,EAAS,WAAW,CAAC,CAC3C,CACA,GAAI,OAAO,YAAe,WAAY,CACpC,IAAMG,EAAQ,WAAW,8BAA8B,EACvDA,EAAM,mBAAmB,SAAUF,CAAQ,EAC3CF,EAAS,SAAWI,EAAM,sBAAsB,SAAUF,CAAQ,CAAC,CACrE,CACA,UAAaF,EAAS,QAAS,GAAOK,EAAG,CAAC,CAC5C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Rgba } from './color.cjs';
|
|
1
|
+
import { ColorResolver, Rgba } from './color.cjs';
|
|
2
2
|
export interface ChartTheme {
|
|
3
3
|
palette: Rgba[];
|
|
4
4
|
text: Rgba;
|
|
@@ -11,9 +11,33 @@ export interface ChartTheme {
|
|
|
11
11
|
fontFamily: string;
|
|
12
12
|
/** Tick label font size in CSS pixels */
|
|
13
13
|
fontSize: number;
|
|
14
|
+
/** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */
|
|
15
|
+
resolve?: ColorResolver;
|
|
14
16
|
}
|
|
15
17
|
/** Reads the theme from the computed style of `element` */
|
|
16
18
|
export declare const readTheme: (element: Element | null, palette?: readonly string[]) => ChartTheme;
|
|
19
|
+
/** Theme of the charts drawn without a DOM (mini-programs, React Native) */
|
|
20
|
+
export interface ChartThemeInput {
|
|
21
|
+
/**
|
|
22
|
+
* Values of the Minerva CSS variables (`--primary-color`, `--text-color`,
|
|
23
|
+
* `--chart-series-1`, ...) used for the theme colors and to resolve
|
|
24
|
+
* `var(--name)` colors of the options
|
|
25
|
+
*/
|
|
26
|
+
variables?: Readonly<Record<string, string>>;
|
|
27
|
+
/** Series colors (hex / rgb) */
|
|
28
|
+
palette?: readonly string[];
|
|
29
|
+
/** Font family of the labels */
|
|
30
|
+
fontFamily?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Font size of the tick labels, in pixels
|
|
33
|
+
* @default 11
|
|
34
|
+
*/
|
|
35
|
+
fontSize?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Builds a theme from plain values (no DOM) */
|
|
38
|
+
export declare const createTheme: (input?: ChartThemeInput, palette?: readonly string[]) => ChartTheme;
|
|
39
|
+
/** Resolver of `var(--name, fallback)` colors against plain variables */
|
|
40
|
+
export declare const staticColorResolver: (variables: Readonly<Record<string, string>>) => ColorResolver;
|
|
17
41
|
/**
|
|
18
42
|
* Calls `onChange` when the theme may have changed: attributes of `<html>` /
|
|
19
43
|
* `<body>` (class, style, data-theme) and the color scheme.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Rgba } from './color.js';
|
|
1
|
+
import { ColorResolver, Rgba } from './color.js';
|
|
2
2
|
export interface ChartTheme {
|
|
3
3
|
palette: Rgba[];
|
|
4
4
|
text: Rgba;
|
|
@@ -11,9 +11,33 @@ export interface ChartTheme {
|
|
|
11
11
|
fontFamily: string;
|
|
12
12
|
/** Tick label font size in CSS pixels */
|
|
13
13
|
fontSize: number;
|
|
14
|
+
/** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */
|
|
15
|
+
resolve?: ColorResolver;
|
|
14
16
|
}
|
|
15
17
|
/** Reads the theme from the computed style of `element` */
|
|
16
18
|
export declare const readTheme: (element: Element | null, palette?: readonly string[]) => ChartTheme;
|
|
19
|
+
/** Theme of the charts drawn without a DOM (mini-programs, React Native) */
|
|
20
|
+
export interface ChartThemeInput {
|
|
21
|
+
/**
|
|
22
|
+
* Values of the Minerva CSS variables (`--primary-color`, `--text-color`,
|
|
23
|
+
* `--chart-series-1`, ...) used for the theme colors and to resolve
|
|
24
|
+
* `var(--name)` colors of the options
|
|
25
|
+
*/
|
|
26
|
+
variables?: Readonly<Record<string, string>>;
|
|
27
|
+
/** Series colors (hex / rgb) */
|
|
28
|
+
palette?: readonly string[];
|
|
29
|
+
/** Font family of the labels */
|
|
30
|
+
fontFamily?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Font size of the tick labels, in pixels
|
|
33
|
+
* @default 11
|
|
34
|
+
*/
|
|
35
|
+
fontSize?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Builds a theme from plain values (no DOM) */
|
|
38
|
+
export declare const createTheme: (input?: ChartThemeInput, palette?: readonly string[]) => ChartTheme;
|
|
39
|
+
/** Resolver of `var(--name, fallback)` colors against plain variables */
|
|
40
|
+
export declare const staticColorResolver: (variables: Readonly<Record<string, string>>) => ColorResolver;
|
|
17
41
|
/**
|
|
18
42
|
* Calls `onChange` when the theme may have changed: attributes of `<html>` /
|
|
19
43
|
* `<body>` (class, style, data-theme) and the color scheme.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { domColorResolver as e, mix as t, resolveStaticColor as n } from "./color.js";
|
|
2
2
|
//#region src/engine/theme.ts
|
|
3
|
-
var
|
|
3
|
+
var r = [
|
|
4
4
|
"#4f46e5",
|
|
5
5
|
"#10b981",
|
|
6
6
|
"#f59e0b",
|
|
@@ -9,40 +9,56 @@ var n = [
|
|
|
9
9
|
"#8b5cf6",
|
|
10
10
|
"#14b8a6",
|
|
11
11
|
"#f97316"
|
|
12
|
-
],
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
], i = (e, t) => e?.getPropertyValue(t).trim() ?? "", a = (t, n) => {
|
|
13
|
+
let r = t && typeof getComputedStyle == "function" ? getComputedStyle(t) : null;
|
|
14
|
+
return c((e) => i(r, e), e(t), n, r?.fontFamily ?? "");
|
|
15
|
+
}, o = (e = {}, t) => {
|
|
16
|
+
let n = e.variables ?? {};
|
|
17
|
+
return {
|
|
18
|
+
...c((e) => n[e]?.trim() ?? "", s(n), t?.length ? t : e.palette, ""),
|
|
19
|
+
...e.fontFamily ? { fontFamily: e.fontFamily } : {},
|
|
20
|
+
...e.fontSize ? { fontSize: e.fontSize } : {}
|
|
21
|
+
};
|
|
22
|
+
}, s = (e) => (t, r) => n(t, e, r), c = (e, n, i, a) => {
|
|
23
|
+
let o = [
|
|
24
|
+
.4,
|
|
25
|
+
.4,
|
|
26
|
+
.4,
|
|
27
|
+
1
|
|
28
|
+
], s = (e) => n(e, o), c = (t, n) => {
|
|
29
|
+
for (let n of t) if (e(n)) return s(`var(${n})`);
|
|
30
|
+
return s(n);
|
|
31
|
+
}, l = c(["--surface-color", "--background-color"], "#ffffff"), u = c(["--text-color"], "#1f2937"), d = c(["--text-secondary-color", "--text-muted-color"], "#6b7280"), f = c(["--border-color"], "#e5e7eb"), p;
|
|
32
|
+
if (i && i.length) p = i.map((e) => s(e));
|
|
18
33
|
else {
|
|
19
|
-
let
|
|
34
|
+
let t = [];
|
|
20
35
|
for (let n = 1; n <= 8; n++) {
|
|
21
|
-
let
|
|
22
|
-
r
|
|
36
|
+
let r = `--chart-series-${n}`;
|
|
37
|
+
e(r) && t.push(s(`var(${r})`));
|
|
23
38
|
}
|
|
24
|
-
|
|
39
|
+
p = t.length ? t : [...[
|
|
25
40
|
"--primary-color",
|
|
26
41
|
"--success-color",
|
|
27
42
|
"--warning-color",
|
|
28
43
|
"--danger-color",
|
|
29
44
|
"--info-color"
|
|
30
|
-
].map((
|
|
45
|
+
].map((t, n) => e(t) ? s(`var(${t})`) : s(r[n])), ...r.slice(5).map((e) => s(e))];
|
|
31
46
|
}
|
|
32
|
-
let
|
|
47
|
+
let m = e("--font-family-sans") || a || "system-ui, -apple-system, 'Segoe UI', sans-serif";
|
|
33
48
|
return {
|
|
34
|
-
palette:
|
|
35
|
-
text:
|
|
36
|
-
textMuted:
|
|
37
|
-
grid:
|
|
38
|
-
axis:
|
|
39
|
-
background:
|
|
40
|
-
surface:
|
|
41
|
-
primary:
|
|
42
|
-
fontFamily:
|
|
43
|
-
fontSize: 11
|
|
49
|
+
palette: p,
|
|
50
|
+
text: u,
|
|
51
|
+
textMuted: d,
|
|
52
|
+
grid: t(l, f, .75),
|
|
53
|
+
axis: f,
|
|
54
|
+
background: l,
|
|
55
|
+
surface: l,
|
|
56
|
+
primary: p[0],
|
|
57
|
+
fontFamily: m,
|
|
58
|
+
fontSize: 11,
|
|
59
|
+
resolve: n
|
|
44
60
|
};
|
|
45
|
-
},
|
|
61
|
+
}, l = (e) => {
|
|
46
62
|
if (typeof document > "u") return () => {};
|
|
47
63
|
let t = [];
|
|
48
64
|
if (typeof MutationObserver == "function") {
|
|
@@ -65,6 +81,6 @@ var n = [
|
|
|
65
81
|
return () => t.forEach((e) => e());
|
|
66
82
|
};
|
|
67
83
|
//#endregion
|
|
68
|
-
export {
|
|
84
|
+
export { o as createTheme, a as readTheme, s as staticColorResolver, l as watchTheme };
|
|
69
85
|
|
|
70
86
|
//# sourceMappingURL=theme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":["DEFAULT_PALETTE","readVar","style","name","readTheme","element","
|
|
1
|
+
{"version":3,"file":"theme.js","names":["DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","domColorResolver","palette","createTheme","variables","input","staticColorResolver","resolveStaticColor","value","fallback","fallbackGray","resolveColor","resolve","color","names","readVariable","background","text","textMuted","border","colors","c","custom","i","fontFamily","inheritedFont","mix","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n mix,\n resolveStaticColor,\n type ColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/** Reads the theme from the computed style of `element` */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n domColorResolver(element),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":";;AA2BA,IAAMA,IAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEMC,KAAW,GAAmC,MAClDC,GAAO,iBAAiBC,CAAI,CAAC,CAAC,KAAK,KAAK,IAG7BC,KACX,GACA,MACe;CACf,IAAMF,IACJG,KAAW,OAAO,oBAAqB,aACnC,iBAAiBA,CAAO,IACxB;CACN,OAAOC,GACJ,MAASL,EAAQC,GAAOC,CAAI,GAC7BI,EAAiBF,CAAO,GACxBG,GACAN,GAAO,cAAc,EACvB;AACF,GAsBaO,KACX,IAAyB,CAAC,GAC1B,MACe;CACf,IAAMC,IAAYC,EAAM,aAAa,CAAC;CAOtC,OAAO;EACL,GAPYL,GACX,MAASI,EAAUP,EAAK,EAAE,KAAK,KAAK,IACrCS,EAAoBF,CAAS,GAC7BF,GAAS,SAASA,IAAUG,EAAM,SAClC,EAGG;EACH,GAAIA,EAAM,aAAa,EAAE,YAAYA,EAAM,WAAW,IAAI,CAAC;EAC3D,GAAIA,EAAM,WA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,SAASL;EACT;EACA;EACA,MAAMM,EAAIV,GAAYG,GAAQ,GAAI;EAClC,MAAMA;EACN;EACA,SAASH;EACT,SAASI,EAAO;EAChB;EACA,UAAU;EACV;CACF;AACF,GAMaO,KAAc,MAAuC;CAChE,IAAI,OAAO,WAAa,KAAa,aAAa,CAAC;CACnD,IAAMC,IAA2B,CAAC;CAClC,IAAI,OAAO,oBAAqB,YAAY;EAC1C,IAAMC,IAAW,IAAI,iBAAiBC,CAAQ;EAC9C,KAAK,IAAMC,KAAQ,CAAC,SAAS,iBAAiB,SAAS,IAAI,GACzD,AAAIA,KACFF,EAAS,QAAQE,GAAM;GACrB,YAAY;GACZ,iBAAiB;IAAC;IAAS;IAAS;IAAc;GAAW;EAC/D,CAAC;EAGL,EAAS,WAAWF,EAAS,WAAW,CAAC;CAC3C;CACA,IAAI,OAAO,cAAe,YAAY;EACpC,IAAMG,IAAQ,WAAW,8BAA8B;EAEvD,AADAA,EAAM,mBAAmB,UAAUF,CAAQ,GAC3CF,EAAS,WAAWI,EAAM,sBAAsB,UAAUF,CAAQ,CAAC;CACrE;CACA,aAAaF,EAAS,SAAS,MAAOK,EAAG,CAAC;AAC5C"}
|
|
@@ -145,8 +145,28 @@ export interface ChartLineAnnotation {
|
|
|
145
145
|
/** Text drawn at the end of the line */
|
|
146
146
|
label?: string;
|
|
147
147
|
}
|
|
148
|
-
/**
|
|
149
|
-
export
|
|
148
|
+
/** Text placed at a data position (omitted coordinates center it on the plot) */
|
|
149
|
+
export interface ChartTextAnnotation {
|
|
150
|
+
type: "text";
|
|
151
|
+
x?: number;
|
|
152
|
+
y?: number;
|
|
153
|
+
text: string;
|
|
154
|
+
/**
|
|
155
|
+
* Side of the text that touches the position: `top` hangs the text below
|
|
156
|
+
* it, `left` starts it there, ...; the text always stays inside the plot
|
|
157
|
+
* @default "center"
|
|
158
|
+
*/
|
|
159
|
+
anchor?: "center" | "top" | "bottom" | "left" | "right";
|
|
160
|
+
/** Text color (defaults to the secondary text color) */
|
|
161
|
+
color?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Font weight
|
|
164
|
+
* @default 500
|
|
165
|
+
*/
|
|
166
|
+
weight?: number;
|
|
167
|
+
}
|
|
168
|
+
/** Background area, reference line or text */
|
|
169
|
+
export type ChartAnnotation = ChartRectAnnotation | ChartLineAnnotation | ChartTextAnnotation;
|
|
150
170
|
/** Zoom / pan / keyboard options */
|
|
151
171
|
export interface ChartInteractionOptions {
|
|
152
172
|
/**
|
|
@@ -169,6 +189,12 @@ export interface ChartInteractionOptions {
|
|
|
169
189
|
* @default true
|
|
170
190
|
*/
|
|
171
191
|
keyboard?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Scatter points can be dragged: `drag` events follow the pointer and a
|
|
194
|
+
* `drop` event ends the gesture (the data is not changed by the chart)
|
|
195
|
+
* @default false
|
|
196
|
+
*/
|
|
197
|
+
dragPoints?: boolean;
|
|
172
198
|
}
|
|
173
199
|
/** Tooltip options */
|
|
174
200
|
export interface ChartTooltipOptions {
|
|
@@ -257,12 +283,41 @@ export interface ChartView {
|
|
|
257
283
|
x: [number, number];
|
|
258
284
|
y: [number, number];
|
|
259
285
|
}
|
|
286
|
+
/** Rectangle in CSS pixels, relative to the chart's container */
|
|
287
|
+
export interface ChartRect {
|
|
288
|
+
x: number;
|
|
289
|
+
y: number;
|
|
290
|
+
width: number;
|
|
291
|
+
height: number;
|
|
292
|
+
}
|
|
293
|
+
/** A dragged point (`drag` / `drop` events) */
|
|
294
|
+
export interface ChartDragEvent {
|
|
295
|
+
/** The point being dragged */
|
|
296
|
+
item: ChartHoverItem;
|
|
297
|
+
/** Data coordinates under the pointer */
|
|
298
|
+
x: number;
|
|
299
|
+
y: number;
|
|
300
|
+
}
|
|
301
|
+
/** A click (or tap) on the plot area outside the points */
|
|
302
|
+
export interface ChartPlotClickEvent {
|
|
303
|
+
/** Data coordinates of the click */
|
|
304
|
+
x: number;
|
|
305
|
+
y: number;
|
|
306
|
+
}
|
|
260
307
|
/** Events of a chart instance */
|
|
261
308
|
export interface ChartEventMap {
|
|
262
309
|
hover: ChartHoverEvent | null;
|
|
263
310
|
click: ChartHoverEvent;
|
|
311
|
+
/** Click on the plot area where there is no point */
|
|
312
|
+
plotClick: ChartPlotClickEvent;
|
|
264
313
|
zoom: ChartView;
|
|
265
314
|
renderer: ChartRendererKind;
|
|
315
|
+
/** The plot area moved or was resized */
|
|
316
|
+
layout: ChartRect;
|
|
317
|
+
/** A point is dragged (`interaction.dragPoints`) */
|
|
318
|
+
drag: ChartDragEvent;
|
|
319
|
+
/** A dragged point was released */
|
|
320
|
+
drop: ChartDragEvent;
|
|
266
321
|
}
|
|
267
322
|
/** Chart created by `createChart` */
|
|
268
323
|
export interface ChartInstance {
|
|
@@ -276,6 +331,18 @@ export interface ChartInstance {
|
|
|
276
331
|
getView(): ChartView;
|
|
277
332
|
/** Sets the visible range */
|
|
278
333
|
setView(view: Partial<ChartView>): void;
|
|
334
|
+
/** Plot area in CSS pixels of the container (`null` before the first frame) */
|
|
335
|
+
getPlotRect(): ChartRect | null;
|
|
336
|
+
/** Data coordinates -> CSS pixels of the container (`null` before the first frame) */
|
|
337
|
+
toPixel(x: number, y: number): {
|
|
338
|
+
x: number;
|
|
339
|
+
y: number;
|
|
340
|
+
} | null;
|
|
341
|
+
/** CSS pixels of the container -> data coordinates (`null` before the first frame) */
|
|
342
|
+
fromPixel(x: number, y: number): {
|
|
343
|
+
x: number;
|
|
344
|
+
y: number;
|
|
345
|
+
} | null;
|
|
279
346
|
/** Backend in use, `null` until ready */
|
|
280
347
|
getRenderer(): ChartRendererKind | null;
|
|
281
348
|
/** Resolves with the backend once the first frame can be drawn (`null` when the browser has no canvas support) */
|
|
@@ -145,8 +145,28 @@ export interface ChartLineAnnotation {
|
|
|
145
145
|
/** Text drawn at the end of the line */
|
|
146
146
|
label?: string;
|
|
147
147
|
}
|
|
148
|
-
/**
|
|
149
|
-
export
|
|
148
|
+
/** Text placed at a data position (omitted coordinates center it on the plot) */
|
|
149
|
+
export interface ChartTextAnnotation {
|
|
150
|
+
type: "text";
|
|
151
|
+
x?: number;
|
|
152
|
+
y?: number;
|
|
153
|
+
text: string;
|
|
154
|
+
/**
|
|
155
|
+
* Side of the text that touches the position: `top` hangs the text below
|
|
156
|
+
* it, `left` starts it there, ...; the text always stays inside the plot
|
|
157
|
+
* @default "center"
|
|
158
|
+
*/
|
|
159
|
+
anchor?: "center" | "top" | "bottom" | "left" | "right";
|
|
160
|
+
/** Text color (defaults to the secondary text color) */
|
|
161
|
+
color?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Font weight
|
|
164
|
+
* @default 500
|
|
165
|
+
*/
|
|
166
|
+
weight?: number;
|
|
167
|
+
}
|
|
168
|
+
/** Background area, reference line or text */
|
|
169
|
+
export type ChartAnnotation = ChartRectAnnotation | ChartLineAnnotation | ChartTextAnnotation;
|
|
150
170
|
/** Zoom / pan / keyboard options */
|
|
151
171
|
export interface ChartInteractionOptions {
|
|
152
172
|
/**
|
|
@@ -169,6 +189,12 @@ export interface ChartInteractionOptions {
|
|
|
169
189
|
* @default true
|
|
170
190
|
*/
|
|
171
191
|
keyboard?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Scatter points can be dragged: `drag` events follow the pointer and a
|
|
194
|
+
* `drop` event ends the gesture (the data is not changed by the chart)
|
|
195
|
+
* @default false
|
|
196
|
+
*/
|
|
197
|
+
dragPoints?: boolean;
|
|
172
198
|
}
|
|
173
199
|
/** Tooltip options */
|
|
174
200
|
export interface ChartTooltipOptions {
|
|
@@ -257,12 +283,41 @@ export interface ChartView {
|
|
|
257
283
|
x: [number, number];
|
|
258
284
|
y: [number, number];
|
|
259
285
|
}
|
|
286
|
+
/** Rectangle in CSS pixels, relative to the chart's container */
|
|
287
|
+
export interface ChartRect {
|
|
288
|
+
x: number;
|
|
289
|
+
y: number;
|
|
290
|
+
width: number;
|
|
291
|
+
height: number;
|
|
292
|
+
}
|
|
293
|
+
/** A dragged point (`drag` / `drop` events) */
|
|
294
|
+
export interface ChartDragEvent {
|
|
295
|
+
/** The point being dragged */
|
|
296
|
+
item: ChartHoverItem;
|
|
297
|
+
/** Data coordinates under the pointer */
|
|
298
|
+
x: number;
|
|
299
|
+
y: number;
|
|
300
|
+
}
|
|
301
|
+
/** A click (or tap) on the plot area outside the points */
|
|
302
|
+
export interface ChartPlotClickEvent {
|
|
303
|
+
/** Data coordinates of the click */
|
|
304
|
+
x: number;
|
|
305
|
+
y: number;
|
|
306
|
+
}
|
|
260
307
|
/** Events of a chart instance */
|
|
261
308
|
export interface ChartEventMap {
|
|
262
309
|
hover: ChartHoverEvent | null;
|
|
263
310
|
click: ChartHoverEvent;
|
|
311
|
+
/** Click on the plot area where there is no point */
|
|
312
|
+
plotClick: ChartPlotClickEvent;
|
|
264
313
|
zoom: ChartView;
|
|
265
314
|
renderer: ChartRendererKind;
|
|
315
|
+
/** The plot area moved or was resized */
|
|
316
|
+
layout: ChartRect;
|
|
317
|
+
/** A point is dragged (`interaction.dragPoints`) */
|
|
318
|
+
drag: ChartDragEvent;
|
|
319
|
+
/** A dragged point was released */
|
|
320
|
+
drop: ChartDragEvent;
|
|
266
321
|
}
|
|
267
322
|
/** Chart created by `createChart` */
|
|
268
323
|
export interface ChartInstance {
|
|
@@ -276,6 +331,18 @@ export interface ChartInstance {
|
|
|
276
331
|
getView(): ChartView;
|
|
277
332
|
/** Sets the visible range */
|
|
278
333
|
setView(view: Partial<ChartView>): void;
|
|
334
|
+
/** Plot area in CSS pixels of the container (`null` before the first frame) */
|
|
335
|
+
getPlotRect(): ChartRect | null;
|
|
336
|
+
/** Data coordinates -> CSS pixels of the container (`null` before the first frame) */
|
|
337
|
+
toPixel(x: number, y: number): {
|
|
338
|
+
x: number;
|
|
339
|
+
y: number;
|
|
340
|
+
} | null;
|
|
341
|
+
/** CSS pixels of the container -> data coordinates (`null` before the first frame) */
|
|
342
|
+
fromPixel(x: number, y: number): {
|
|
343
|
+
x: number;
|
|
344
|
+
y: number;
|
|
345
|
+
} | null;
|
|
279
346
|
/** Backend in use, `null` until ready */
|
|
280
347
|
getRenderer(): ChartRendererKind | null;
|
|
281
348
|
/** Resolves with the backend once the first frame can be drawn (`null` when the browser has no canvas support) */
|
package/dist/charts/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./engine/format.cjs"),t=require("./engine/chart.cjs"),n=require("./react/Chart.cjs"),r=require("./react/charts.cjs");require("./core.cjs"),exports.BarChart=
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./engine/format.cjs"),t=require("./engine/chart.cjs"),n=require("./react/Chart.cjs"),r=require("./engine/presets.cjs"),i=require("./react/charts.cjs"),a=require("./engine/controller.cjs"),o=require("./engine/canvas.cjs");require("./core.cjs"),exports.BarChart=i.BarChart,exports.Chart=n.Chart,exports.LineChart=i.LineChart,exports.QuadrantChart=i.QuadrantChart,exports.ScatterChart=i.ScatterChart,exports.createCanvasChart=o.createCanvasChart,exports.createChart=t.createChart,exports.createChartController=a.createChartController,exports.formatCompact=e.formatCompact,exports.quadrantCenter=r.quadrantCenter,exports.quadrantChartOptions=r.quadrantChartOptions,exports.quadrantOf=r.quadrantOf,exports.scenePrimitives=a.scenePrimitives;
|
package/dist/charts/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Chart } from './react/Chart.cjs';
|
|
2
2
|
export { BarChart, LineChart, QuadrantChart, ScatterChart, } from './react/charts.cjs';
|
|
3
|
-
export type { BarChartProps, ChartCommonProps, ChartHandle, ChartProps, LineChartProps, QuadrantChartProps,
|
|
3
|
+
export type { BarChartProps, ChartCommonProps, ChartHandle, ChartProps, LineChartProps, QuadrantChartProps, QuadrantDropTarget, ScatterChartProps, } from './react/types.cjs';
|
|
4
4
|
export * from './core.cjs';
|
package/dist/charts/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Chart } from './react/Chart.js';
|
|
2
2
|
export { BarChart, LineChart, QuadrantChart, ScatterChart, } from './react/charts.js';
|
|
3
|
-
export type { BarChartProps, ChartCommonProps, ChartHandle, ChartProps, LineChartProps, QuadrantChartProps,
|
|
3
|
+
export type { BarChartProps, ChartCommonProps, ChartHandle, ChartProps, LineChartProps, QuadrantChartProps, QuadrantDropTarget, ScatterChartProps, } from './react/types.js';
|
|
4
4
|
export * from './core.js';
|
package/dist/charts/index.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { formatCompact as e } from "./engine/format.js";
|
|
3
3
|
import { createChart as t } from "./engine/chart.js";
|
|
4
4
|
import { Chart as n } from "./react/Chart.js";
|
|
5
|
-
import {
|
|
5
|
+
import { quadrantCenter as r, quadrantChartOptions as i, quadrantOf as a } from "./engine/presets.js";
|
|
6
|
+
import { BarChart as o, LineChart as s, QuadrantChart as c, ScatterChart as l } from "./react/charts.js";
|
|
7
|
+
import { createChartController as u, scenePrimitives as d } from "./engine/controller.js";
|
|
8
|
+
import { createCanvasChart as f } from "./engine/canvas.js";
|
|
6
9
|
import "./core.js";
|
|
7
|
-
export {
|
|
10
|
+
export { o as BarChart, n as Chart, s as LineChart, c as QuadrantChart, l as ScatterChart, f as createCanvasChart, t as createChart, u as createChartController, e as formatCompact, r as quadrantCenter, i as quadrantChartOptions, a as quadrantOf, d as scenePrimitives };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../engine/chart.cjs");let t=require("react"),n=require("react/jsx-runtime");var
|
|
1
|
+
"use client";const e=require("../engine/chart.cjs");let t=require("react"),n=require("react-dom"),r=require("react/jsx-runtime");var i=(e,t)=>e===void 0?t:typeof e==`number`?`${e}px`:e,a=e=>({series:e.series,xAxis:e.xAxis,yAxis:e.yAxis,renderer:e.renderer,legend:e.legend,tooltip:e.tooltip,crosshair:e.crosshair,annotations:e.annotations,interaction:e.interaction,padding:e.padding,palette:e.palette,ariaLabel:e.ariaLabel});function o({options:a,height:o,width:s,className:c,style:l,handleRef:u,renderTooltip:d,overlay:f,...p}){let m=(0,t.useRef)(null),h=(0,t.useRef)(null),g=(0,t.useRef)(p),_=(0,t.useRef)(d),[v,y]=(0,t.useState)(null),[b,x]=(0,t.useState)(null),S=(0,t.useMemo)(()=>typeof document>`u`?null:document.createElement(`div`),[]),C=(0,t.useMemo)(()=>{if(!d||!S||a.tooltip===!1)return a;let e=typeof a.tooltip==`object`?a.tooltip:{};return{...a,tooltip:{...e,render:e=>_.current?((0,n.flushSync)(()=>y(e)),S):null}}},[a,d,S]),w=(0,t.useRef)(C);return(0,t.useEffect)(()=>{g.current=p,_.current=d}),(0,t.useEffect)(()=>{let t=m.current;if(!t)return;let n=e.createChart(t,w.current);h.current=n;let r=[n.on(`hover`,e=>g.current.onHover?.(e)),n.on(`click`,e=>g.current.onPointClick?.(e)),n.on(`plotClick`,e=>g.current.onPlotClick?.(e)),n.on(`zoom`,e=>g.current.onZoom?.(e)),n.on(`renderer`,e=>g.current.onRendererChange?.(e)),n.on(`drag`,e=>g.current.onDrag?.(e)),n.on(`drop`,e=>g.current.onDrop?.(e)),n.on(`layout`,e=>x(e))];return()=>{r.forEach(e=>e()),n.destroy(),h.current=null}},[]),(0,t.useEffect)(()=>{w.current!==C&&(w.current=C,h.current?.setOptions(C))},[C]),(0,t.useImperativeHandle)(u,()=>({resetZoom:()=>h.current?.resetZoom(),getView:()=>h.current?.getView()??null,setView:e=>h.current?.setView(e),getRenderer:()=>h.current?.getRenderer()??null,getInstance:()=>h.current}),[]),(0,r.jsxs)(`div`,{className:c,style:{position:`relative`,width:i(s,`100%`),height:i(o,`320px`),...l},children:[(0,r.jsx)(`div`,{ref:m,style:{position:`absolute`,inset:0}}),f&&b&&(0,r.jsx)(`div`,{className:`minerva-chart-overlay`,style:{position:`absolute`,left:b.x,top:b.y,width:b.width,height:b.height,pointerEvents:`none`},children:f(b)}),S&&v&&d&&(0,n.createPortal)(d(v),S)]})}function s(e){let{height:t,width:n,className:i,style:s,ref:c,onHover:l,onPointClick:u,onPlotClick:d,onZoom:f,onRendererChange:p,renderTooltip:m}=e;return(0,r.jsx)(o,{options:a(e),height:t,width:n,className:i,style:s,handleRef:c,onHover:l,onPointClick:u,onPlotClick:d,onZoom:f,onRendererChange:p,renderTooltip:m})}exports.Chart=s,exports.ChartBase=o,exports.engineOptions=a;
|
|
2
2
|
//# sourceMappingURL=Chart.cjs.map
|