@indiminds/charts 1.0.1

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.
Files changed (51) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +159 -0
  3. package/dist/bar-chart/bar-chart.d.ts +26 -0
  4. package/dist/bar-chart/index.d.ts +2 -0
  5. package/dist/bar-chart/index.js +1 -0
  6. package/dist/bar-chart/types.d.ts +48 -0
  7. package/dist/candlestick/candlestick-chart.d.ts +73 -0
  8. package/dist/candlestick/data-sync.d.ts +29 -0
  9. package/dist/candlestick/index.d.ts +2 -0
  10. package/dist/candlestick/index.js +1 -0
  11. package/dist/candlestick/interaction.d.ts +10 -0
  12. package/dist/candlestick/layout-calculator.d.ts +23 -0
  13. package/dist/candlestick/pane-state.d.ts +19 -0
  14. package/dist/candlestick/panel-resize.d.ts +4 -0
  15. package/dist/candlestick/price-style.d.ts +9 -0
  16. package/dist/candlestick/renderers/candles.d.ts +5 -0
  17. package/dist/candlestick/renderers/grid.d.ts +2 -0
  18. package/dist/candlestick/renderers/index.d.ts +20 -0
  19. package/dist/candlestick/renderers/indicators.d.ts +30 -0
  20. package/dist/candlestick/renderers/overlays.d.ts +8 -0
  21. package/dist/candlestick/renderers/price-line.d.ts +4 -0
  22. package/dist/candlestick/viewport.d.ts +28 -0
  23. package/dist/canvas-chart-base.d.ts +23 -0
  24. package/dist/category-axis.d.ts +9 -0
  25. package/dist/category-layout.d.ts +9 -0
  26. package/dist/chart-shell.d.ts +14 -0
  27. package/dist/combo-chart/combo-chart.d.ts +26 -0
  28. package/dist/combo-chart/index.d.ts +2 -0
  29. package/dist/combo-chart/index.js +1 -0
  30. package/dist/combo-chart/types.d.ts +75 -0
  31. package/dist/config.d.ts +94 -0
  32. package/dist/line-chart/index.d.ts +2 -0
  33. package/dist/line-chart/index.js +1 -0
  34. package/dist/line-chart/line-chart.d.ts +21 -0
  35. package/dist/line-chart/types.d.ts +30 -0
  36. package/dist/pie-chart/index.d.ts +2 -0
  37. package/dist/pie-chart/index.js +1 -0
  38. package/dist/pie-chart/pie-chart.d.ts +21 -0
  39. package/dist/pie-chart/types.d.ts +26 -0
  40. package/dist/plot-frame.d.ts +19 -0
  41. package/dist/renderers/helpers.d.ts +17 -0
  42. package/dist/renderers/primitives/axis-pills.d.ts +11 -0
  43. package/dist/renderers/primitives/context.d.ts +36 -0
  44. package/dist/renderers/primitives/decorations.d.ts +44 -0
  45. package/dist/renderers/primitives/grouped-bars.d.ts +43 -0
  46. package/dist/renderers/primitives/index.d.ts +5 -0
  47. package/dist/renderers/primitives/marks.d.ts +40 -0
  48. package/dist/renderers/value-axis.d.ts +18 -0
  49. package/dist/scale.d.ts +36 -0
  50. package/dist/types.d.ts +53 -0
  51. package/package.json +67 -0
@@ -0,0 +1,43 @@
1
+ import { type DrawContext } from "./context";
2
+ /** How a bar is painted. The striped and hollow styles let a caller mark a
3
+ * bar as having gone up or down without adding a second series. */
4
+ export type BarFillMode = "solid" | "hatched" | "outline";
5
+ export interface BarSeries {
6
+ color: string;
7
+ /** One entry per category, aligned to the chart's category list. */
8
+ values: readonly (number | null)[];
9
+ /** Per-category override, aligned to `values`. Missing = "solid". */
10
+ fillModes?: readonly BarFillMode[];
11
+ /** Per-category color override, aligned to `values` — for a single series
12
+ * whose bars are classified individually. Missing entries use `color`. */
13
+ colors?: readonly (string | null | undefined)[];
14
+ }
15
+ /** A bar that moved between two values — solid up to the smaller one, then
16
+ * striped (it grew) or hollow (it shrank) the rest of the way. */
17
+ export interface DeltaBarSeries {
18
+ color: string;
19
+ from: readonly (number | null)[];
20
+ to: readonly (number | null)[];
21
+ }
22
+ interface BarGroupOptions {
23
+ baseline?: number;
24
+ /** Fraction of the category slot the whole group occupies. */
25
+ groupWidthRatio?: number;
26
+ /** Fraction of each bar's own width left as a gap to its neighbor. */
27
+ barGapRatio?: number;
28
+ /** Highlights one category's bars on hover, by brightening them rather than
29
+ * dimming everything else. */
30
+ focusIndex?: number | null;
31
+ /** 0-1 growing-in animation. 1, the default, draws bars at full height. */
32
+ growProgress?: number;
33
+ /** Bars per category, when a caller draws several batches that should sit
34
+ * side by side. Defaults to `series.length`. */
35
+ slotCount?: number;
36
+ /** Where this batch starts within that row of bars. Default 0. */
37
+ slotOffset?: number;
38
+ }
39
+ export declare function drawGroupedBars(c: DrawContext, series: readonly BarSeries[], options?: BarGroupOptions): void;
40
+ /** Bars showing a before and after value: solid up to the smaller of the two,
41
+ * then striped if it grew or hollow if it shrank. */
42
+ export declare function drawDeltaBars(c: DrawContext, series: readonly DeltaBarSeries[], options?: BarGroupOptions): void;
43
+ export {};
@@ -0,0 +1,5 @@
1
+ export { applyStyle, lastValueBefore, withPaneClip, type DrawContext, type PlotStyle, } from "./context";
2
+ export { drawBand, drawHistogram, drawLine, momentumColor, type HistogramColorMode, type MomentumColors, } from "./marks";
3
+ export { drawLabelPill, drawPaneDivider, drawPaneGrid, drawReferenceLines, drawZones, niceStep, roundRect, type PillStyle, type ReferenceLine, type Zone, } from "./decorations";
4
+ export { drawAxisPills, type AxisPill } from "./axis-pills";
5
+ export { drawGroupedBars, drawDeltaBars, type BarFillMode, type BarSeries, type DeltaBarSeries, } from "./grouped-bars";
@@ -0,0 +1,40 @@
1
+ import { type DrawContext, type PlotStyle } from "./context";
2
+ /** Draws a line, leaving a gap wherever a value is missing. In "directional"
3
+ * mode each stretch takes its colour from `colorValues`, and the line breaks
4
+ * where that flips rather than joining the two sides together. */
5
+ export declare function drawLine(c: DrawContext, values: readonly (number | null)[], style: PlotStyle, options?: {
6
+ colorMode?: "fixed" | "directional";
7
+ momentumColors?: MomentumColors;
8
+ colorValues?: readonly (number | null)[];
9
+ }): void;
10
+ /** Fills the area between two lines, skipping missing values. In "directional"
11
+ * mode the fill is split into separate patches wherever `colorValues` flips. */
12
+ export declare function drawBand(c: DrawContext, upper: readonly (number | null)[], lower: readonly (number | null)[], style: PlotStyle, options?: {
13
+ colorMode?: "fixed" | "directional";
14
+ momentumColors?: MomentumColors;
15
+ colorValues?: readonly (number | null)[];
16
+ }): void;
17
+ /** How a histogram picks its bar colours:
18
+ * "fixed" — one colour throughout.
19
+ * "momentum" — above/below zero picks the colour, rising or falling
20
+ * against the previous bar picks the bright or dull shade.
21
+ * "directional" — a second series decides, e.g. volume bars coloured by
22
+ * whether that candle closed up or down. */
23
+ export type HistogramColorMode = "fixed" | "momentum" | "directional";
24
+ export interface MomentumColors {
25
+ bullStrong: string;
26
+ bullWeak: string;
27
+ bearStrong: string;
28
+ bearWeak: string;
29
+ }
30
+ declare function momentumColor(value: number, prev: number | null | undefined, colors: MomentumColors): string;
31
+ export declare function drawHistogram(c: DrawContext, values: readonly (number | null)[], style: PlotStyle, options?: {
32
+ baseline?: number;
33
+ colorMode?: HistogramColorMode;
34
+ momentumColors?: MomentumColors;
35
+ /** The companion series "directional" mode reads — only its sign matters. */
36
+ colorValues?: readonly (number | null)[];
37
+ /** How much of its slot a bar fills, 0-1. */
38
+ barWidthRatio?: number;
39
+ }): void;
40
+ export { momentumColor };
@@ -0,0 +1,18 @@
1
+ import { type PlotFrame } from "../plot-frame";
2
+ import type { PriceExtent } from "../types";
3
+ export interface ValueAxisSpec {
4
+ extent: PriceExtent;
5
+ toY: (value: number) => number;
6
+ format: (value: number) => string;
7
+ /** Which gutter the tick labels sit in. */
8
+ side: "left" | "right";
9
+ /** Whether this axis' ticks also draw the horizontal gridlines. Only one
10
+ * axis should: two sets rarely land on the same pixel and just double up. */
11
+ gridlines: boolean;
12
+ }
13
+ export declare function drawValueAxis(ctx: CanvasRenderingContext2D, frame: PlotFrame, spec: ValueAxisSpec): void;
14
+ /** The line the categories sit on, closing the bottom of the plot. */
15
+ export declare function drawAxisBaseline(ctx: CanvasRenderingContext2D, frame: PlotFrame): void;
16
+ /** Vertical gridlines at the same ticks the category labels land on, so the
17
+ * pane reads as a full grid rather than horizontal-only. */
18
+ export declare function drawCategoryGridlines(ctx: CanvasRenderingContext2D, frame: PlotFrame, categoryCount: number, toX: (categoryIndex: number) => number, step: number): void;
@@ -0,0 +1,36 @@
1
+ import type { PriceExtent } from "./types";
2
+ /** Fits the visible data with some padding. */
3
+ export interface AutoScale {
4
+ mode: "auto";
5
+ /** Fraction of the data span added above and below. */
6
+ cushionRatio: number;
7
+ /** Minimum padding for nearly flat data. */
8
+ minCushion?: number;
9
+ }
10
+ /** Fits the data, but never scrolls past `min`/`max` and always keeps
11
+ * `alwaysInclude` on screen. */
12
+ export interface FixedScale {
13
+ mode: "fixed";
14
+ min: number;
15
+ max: number;
16
+ /** Levels that must stay on screen even when the data is far from them. */
17
+ alwaysInclude?: [number, number];
18
+ cushionRatio: number;
19
+ minCushion?: number;
20
+ }
21
+ /** Reuses the price pane's own range — for indicators drawn over the candles. */
22
+ export interface PriceScale {
23
+ mode: "price";
24
+ }
25
+ export type PaneScale = AutoScale | FixedScale | PriceScale;
26
+ /** Vertical breathing room inside a pane, in px. */
27
+ export declare const PANE_PAD_TOP = 8;
28
+ export declare const PANE_PAD_BOTTOM = 8;
29
+ /** The value range to draw `series` against over the visible index window.
30
+ * Null when there's nothing to fit, or when the caller owns the range ("price"). */
31
+ export declare function computePaneExtent(scale: PaneScale, series: readonly (readonly (number | null)[])[], startIndex: number, endIndex: number): PriceExtent | null;
32
+ /** Value -> canvas Y inside a pane. The padding keeps highs and lows off the
33
+ * pane's edges; the price pane passes 0 because its range is padded already. */
34
+ export declare function makeToY(extent: PriceExtent, top: number, height: number, padTop?: number, padBottom?: number): (value: number) => number;
35
+ /** Inverse of makeToY — canvas Y back to a value, for the crosshair label. */
36
+ export declare function makeFromY(extent: PriceExtent, top: number, height: number, padTop?: number, padBottom?: number): (y: number) => number;
@@ -0,0 +1,53 @@
1
+ import type { CandleData as ChartCandle, Viewport as ChartViewport, PaneLayout, PriceExtent } from "@indiminds/chart-types";
2
+ type CandleData = ChartCandle;
3
+ /** Where one sub-pane sits. `minHeight` only matters while dragging a divider,
4
+ * so it lives here rather than in the shared chart-types contract. */
5
+ type PaneRect = PaneLayout & {
6
+ minHeight: number;
7
+ };
8
+ type ChartLayout = {
9
+ width: number;
10
+ height: number;
11
+ chartWidth: number;
12
+ chartHeight: number;
13
+ priceScaleWidth: number;
14
+ timeScaleHeight: number;
15
+ /** Sub-panes stacked below the price pane, top to bottom. Empty when every
16
+ * indicator draws over the candles instead of in its own pane. */
17
+ panes: PaneRect[];
18
+ timeAxisTop: number;
19
+ };
20
+ type Viewport = ChartViewport;
21
+ /** Hovered candle plus its absolute index, or null when the cursor leaves. */
22
+ type CrosshairEvent = {
23
+ candle: CandleData;
24
+ index: number;
25
+ } | null;
26
+ /** Pane geometry, published so DOM overlays can position against the canvas. */
27
+ type LayoutSnapshot = {
28
+ width: number;
29
+ chartWidth: number;
30
+ chartHeight: number;
31
+ panes: PaneRect[];
32
+ };
33
+ /** Mutable on purpose — refreshChartColors() rewrites these when the theme
34
+ * changes, and renderers read them fresh on every draw. */
35
+ declare const COLORS: {
36
+ bullish: string;
37
+ bearish: string;
38
+ grid: string;
39
+ text: string;
40
+ crosshair: string;
41
+ priceLine: string;
42
+ pill: string;
43
+ pillText: string;
44
+ divider: string;
45
+ dividerActive: string;
46
+ background: string;
47
+ };
48
+ type ColorKey = keyof typeof COLORS;
49
+ /** Re-reads the themed colors off the page. Canvas can't understand var(), so
50
+ * we have to copy out the resolved values. */
51
+ declare function refreshChartColors(): void;
52
+ export { COLORS, refreshChartColors };
53
+ export type { CandleData, ChartLayout, PaneRect, Viewport, PriceExtent, CrosshairEvent, LayoutSnapshot, ColorKey, };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@indiminds/charts",
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "description": "Canvas-based charting engine for React/Next.js — candlestick, bar, combo, line and pie charts, zero charting-library dependencies.",
6
+ "author": "Indiminds <sonu@indiminds.com>",
7
+ "license": "UNLICENSED",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Indiminds-Trading-Org/Back-Testing-UI.git",
14
+ "directory": "packages/charting-engine"
15
+ },
16
+ "keywords": [
17
+ "charts",
18
+ "charting",
19
+ "canvas",
20
+ "react",
21
+ "candlestick",
22
+ "ohlc",
23
+ "trading",
24
+ "bar-chart",
25
+ "line-chart",
26
+ "pie-chart",
27
+ "financial-charts"
28
+ ],
29
+ "main": "./dist/candlestick/index.js",
30
+ "types": "./dist/candlestick/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/candlestick/index.d.ts",
37
+ "default": "./dist/candlestick/index.js"
38
+ },
39
+ "./bar": {
40
+ "types": "./dist/bar-chart/index.d.ts",
41
+ "default": "./dist/bar-chart/index.js"
42
+ },
43
+ "./combo": {
44
+ "types": "./dist/combo-chart/index.d.ts",
45
+ "default": "./dist/combo-chart/index.js"
46
+ },
47
+ "./line": {
48
+ "types": "./dist/line-chart/index.d.ts",
49
+ "default": "./dist/line-chart/index.js"
50
+ },
51
+ "./pie": {
52
+ "types": "./dist/pie-chart/index.d.ts",
53
+ "default": "./dist/pie-chart/index.js"
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@indiminds/chart-types": "1.0.1"
58
+ },
59
+ "devDependencies": {
60
+ "esbuild": "^0.24.0"
61
+ },
62
+ "scripts": {
63
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc --emitDeclarationOnly && node build.mjs",
64
+ "typecheck": "tsc --noEmit",
65
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
66
+ }
67
+ }