@unovis/ts 1.6.0-pre.1 → 1.6.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/components/area/index.js +2 -1
- package/components/area/index.js.map +1 -1
- package/components/axis/config.d.ts +4 -0
- package/components/axis/config.js +2 -2
- package/components/axis/config.js.map +1 -1
- package/components/axis/index.d.ts +0 -1
- package/components/axis/index.js +51 -19
- package/components/axis/index.js.map +1 -1
- package/components/axis/style.d.ts +40 -1
- package/components/axis/style.js +34 -35
- package/components/axis/style.js.map +1 -1
- package/components/brush/config.d.ts +1 -1
- package/components/brush/config.js.map +1 -1
- package/components/bullet-legend/config.d.ts +2 -0
- package/components/bullet-legend/config.js +1 -0
- package/components/bullet-legend/config.js.map +1 -1
- package/components/bullet-legend/index.js +10 -2
- package/components/bullet-legend/index.js.map +1 -1
- package/components/bullet-legend/modules/shape.d.ts +1 -0
- package/components/bullet-legend/modules/shape.js +61 -41
- package/components/bullet-legend/modules/shape.js.map +1 -1
- package/components/bullet-legend/types.d.ts +1 -1
- package/components/bullet-legend/types.js.map +1 -1
- package/components/crosshair/config.d.ts +20 -7
- package/components/crosshair/config.js +1 -1
- package/components/crosshair/config.js.map +1 -1
- package/components/crosshair/index.d.ts +8 -7
- package/components/crosshair/index.js +144 -72
- package/components/crosshair/index.js.map +1 -1
- package/components/graph/config.d.ts +8 -0
- package/components/graph/config.js +1 -1
- package/components/graph/config.js.map +1 -1
- package/components/graph/index.d.ts +1 -0
- package/components/graph/index.js +14 -9
- package/components/graph/index.js.map +1 -1
- package/components/graph/modules/layout.js +33 -31
- package/components/graph/modules/layout.js.map +1 -1
- package/components/graph/modules/link/index.js +1 -1
- package/components/graph/modules/link/index.js.map +1 -1
- package/components/graph/types.d.ts +2 -1
- package/components/graph/types.js.map +1 -1
- package/components/nested-donut/config.d.ts +1 -1
- package/components/nested-donut/config.js.map +1 -1
- package/components/plotband/config.d.ts +59 -0
- package/components/plotband/config.js +9 -0
- package/components/plotband/config.js.map +1 -0
- package/components/plotband/constants.d.ts +5 -0
- package/components/plotband/constants.js +413 -0
- package/components/plotband/constants.js.map +1 -0
- package/components/plotband/index.d.ts +15 -0
- package/components/plotband/index.js +92 -0
- package/components/plotband/index.js.map +1 -0
- package/components/plotband/style.d.ts +4 -0
- package/components/plotband/style.js +38 -0
- package/components/plotband/style.js.map +1 -0
- package/components/plotband/types.d.ts +51 -0
- package/components/plotband/types.js +27 -0
- package/components/plotband/types.js.map +1 -0
- package/components/plotline/config.d.ts +91 -0
- package/components/plotline/config.js +9 -0
- package/components/plotline/config.js.map +1 -0
- package/components/plotline/constants.d.ts +6 -0
- package/components/plotline/constants.js +58 -0
- package/components/plotline/constants.js.map +1 -0
- package/components/plotline/index.d.ts +14 -0
- package/components/plotline/index.js +102 -0
- package/components/plotline/index.js.map +1 -0
- package/components/plotline/style.d.ts +4 -0
- package/components/plotline/style.js +42 -0
- package/components/plotline/style.js.map +1 -0
- package/components/plotline/types.d.ts +53 -0
- package/components/plotline/types.js +33 -0
- package/components/plotline/types.js.map +1 -0
- package/components/rolling-pin-legend/config.d.ts +19 -0
- package/components/rolling-pin-legend/config.js +11 -0
- package/components/rolling-pin-legend/config.js.map +1 -0
- package/components/rolling-pin-legend/index.d.ts +16 -0
- package/components/rolling-pin-legend/index.js +69 -0
- package/components/rolling-pin-legend/index.js.map +1 -0
- package/components/rolling-pin-legend/style.d.ts +22 -0
- package/components/rolling-pin-legend/style.js +39 -0
- package/components/rolling-pin-legend/style.js.map +1 -0
- package/components/rolling-pin-legend/types.d.ts +1 -0
- package/components/rolling-pin-legend/types.js +2 -0
- package/components/rolling-pin-legend/types.js.map +1 -0
- package/components/scatter/index.d.ts +1 -0
- package/components/scatter/index.js +11 -1
- package/components/scatter/index.js.map +1 -1
- package/components/timeline/config.d.ts +65 -14
- package/components/timeline/config.js +15 -1
- package/components/timeline/config.js.map +1 -1
- package/components/timeline/constants.d.ts +3 -0
- package/components/timeline/constants.js +6 -0
- package/components/timeline/constants.js.map +1 -0
- package/components/timeline/index.d.ts +21 -10
- package/components/timeline/index.js +380 -95
- package/components/timeline/index.js.map +1 -1
- package/components/timeline/style.d.ts +7 -0
- package/components/timeline/style.js +40 -1
- package/components/timeline/style.js.map +1 -1
- package/components/timeline/types.d.ts +62 -0
- package/components/timeline/types.js +2 -0
- package/components/timeline/types.js.map +1 -0
- package/components/timeline/utils.d.ts +2 -0
- package/components/timeline/utils.js +16 -0
- package/components/timeline/utils.js.map +1 -0
- package/components/tooltip/index.js +4 -3
- package/components/tooltip/index.js.map +1 -1
- package/components/treemap/config.d.ts +52 -0
- package/components/treemap/config.js +6 -0
- package/components/treemap/config.js.map +1 -0
- package/components/treemap/index.d.ts +18 -0
- package/components/treemap/index.js +274 -0
- package/components/treemap/index.js.map +1 -0
- package/components/treemap/style.d.ts +25 -0
- package/components/treemap/style.js +69 -0
- package/components/treemap/style.js.map +1 -0
- package/components/treemap/types.d.ts +11 -0
- package/components/treemap/types.js +2 -0
- package/components/treemap/types.js.map +1 -0
- package/components/xy-labels/index.js +1 -1
- package/components/xy-labels/index.js.map +1 -1
- package/components.d.ts +10 -2
- package/components.js +4 -0
- package/components.js.map +1 -1
- package/containers/single-container/index.js +3 -1
- package/containers/single-container/index.js.map +1 -1
- package/containers/xy-container/config.d.ts +2 -0
- package/containers/xy-container/config.js +1 -1
- package/containers/xy-container/config.js.map +1 -1
- package/containers/xy-container/index.js +17 -7
- package/containers/xy-container/index.js.map +1 -1
- package/core/component/index.d.ts +4 -0
- package/core/component/index.js +6 -0
- package/core/component/index.js.map +1 -1
- package/core/xy-component/index.d.ts +1 -0
- package/core/xy-component/index.js +3 -1
- package/core/xy-component/index.js.map +1 -1
- package/data-models/graph.js +7 -1
- package/data-models/graph.js.map +1 -1
- package/index.js +10 -3
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/styles/index.js +1 -0
- package/styles/index.js.map +1 -1
- package/types/data.d.ts +5 -0
- package/types/data.js +7 -0
- package/types/data.js.map +1 -1
- package/types/position.d.ts +2 -1
- package/types/position.js +1 -0
- package/types/position.js.map +1 -1
- package/types/text.d.ts +1 -1
- package/types/text.js.map +1 -1
- package/types.d.ts +5 -0
- package/types.js +6 -1
- package/types.js.map +1 -1
- package/utils/color.d.ts +7 -0
- package/utils/color.js +14 -2
- package/utils/color.js.map +1 -1
- package/utils/data.d.ts +4 -4
- package/utils/data.js +41 -10
- package/utils/data.js.map +1 -1
- package/utils/index.js +3 -3
- package/utils/path.d.ts +8 -0
- package/utils/path.js +109 -1
- package/utils/path.js.map +1 -1
- package/utils/text.d.ts +3 -2
- package/utils/text.js +22 -10
- package/utils/text.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/brush/config.ts"],"sourcesContent":["import { D3BrushEvent } from 'd3-brush'\nimport { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { Arrangement } from 'types/position'\n\n// We extend partial XY config interface because x and y properties are optional for Brush\nexport interface BrushConfigInterface<Datum> extends Partial<XYComponentConfigInterface<Datum>> {\n /** Callback function to be called on any Brush event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrush?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush start event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushStart?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush move event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushMove?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush end event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushEnd?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Width of the Brush handle. Default: `1` */\n handleWidth?: number;\n /** Brush selection in the data space coordinates, can be used to control the selection. Default: `undefined` */\n selection?: [number, number] | null;\n /** Allow dragging the selected area as a whole in order to change the selected range. Default: `false` */\n draggable?: boolean;\n /** Position of the handle: `Arrangement.Inside` or `Arrangement.Outside`. Default: `Arrangement.Inside` */\n handlePosition?: Arrangement | string;\n /** Constraint Brush selection to a minimal length in data units. Default: `undefined` */\n selectionMinLength?: number;\n}\n\nexport const BrushDefaultConfig: BrushConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrush: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushStart: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushMove: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushEnd: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n handleWidth: 9,\n selection: null,\n draggable: false,\n handlePosition: Arrangement.Inside,\n selectionMinLength: undefined,\n}\n"],"names":[],"mappings":";;;AAoCO,MAAM,kBAAkB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC1B,wBAAwB,CAAA,EAAA;;IAE3B,OAAO,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;IAE1G,YAAY,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;IAE/G,WAAW,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;AAE9G,IAAA,UAAU,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,QAAa,EAC7G,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,IAAI,EACf,SAAS,EAAE,KAAK,EAChB,cAAc,EAAE,WAAW,CAAC,MAAM,EAClC,kBAAkB,EAAE,SAAS;;;;"}
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/brush/config.ts"],"sourcesContent":["import { D3BrushEvent } from 'd3-brush'\nimport { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { Arrangement } from 'types/position'\n\n// We extend partial XY config interface because x and y properties are optional for Brush\nexport interface BrushConfigInterface<Datum> extends Partial<XYComponentConfigInterface<Datum>> {\n /** Callback function to be called on any Brush event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrush?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush start event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushStart?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush move event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushMove?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush end event.\n * Default: `(selection: [number, number], event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrushEnd?: ((selection: [number, number] | undefined, event: D3BrushEvent<Datum>, userDriven: boolean) => void);\n /** Width of the Brush handle. Default: `1` */\n handleWidth?: number;\n /** Brush selection in the data space coordinates, can be used to control the selection. Default: `undefined` */\n selection?: [number, number] | null;\n /** Allow dragging the selected area as a whole in order to change the selected range. Default: `false` */\n draggable?: boolean;\n /** Position of the handle: `Arrangement.Inside` or `Arrangement.Outside`. Default: `Arrangement.Inside` */\n handlePosition?: Arrangement.Inside | Arrangement.Outside | string;\n /** Constraint Brush selection to a minimal length in data units. Default: `undefined` */\n selectionMinLength?: number;\n}\n\nexport const BrushDefaultConfig: BrushConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrush: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushStart: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushMove: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushEnd: <Datum>(s: [number, number] | undefined, e: D3BrushEvent<Datum>, userDriven: boolean): void => {},\n handleWidth: 9,\n selection: null,\n draggable: false,\n handlePosition: Arrangement.Inside,\n selectionMinLength: undefined,\n}\n"],"names":[],"mappings":";;;AAoCO,MAAM,kBAAkB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC1B,wBAAwB,CAAA,EAAA;;IAE3B,OAAO,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;IAE1G,YAAY,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;IAE/G,WAAW,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,KAAU,GAAG;;AAE9G,IAAA,UAAU,EAAE,CAAQ,CAA+B,EAAE,CAAsB,EAAE,UAAmB,QAAa,EAC7G,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,IAAI,EACf,SAAS,EAAE,KAAK,EAChB,cAAc,EAAE,WAAW,CAAC,MAAM,EAClC,kBAAkB,EAAE,SAAS;;;;"}
|
|
@@ -24,6 +24,8 @@ export interface BulletLegendConfigInterface {
|
|
|
24
24
|
labelMaxWidth?: string | null;
|
|
25
25
|
/** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */
|
|
26
26
|
bulletSize?: string | null;
|
|
27
|
+
/** Spacing between multiple bullet symbols in pixels. Default: `4` */
|
|
28
|
+
bulletSpacing?: number;
|
|
27
29
|
/** Bullet shape enum value or accessor function. Default: `d => d.shape ?? BulletShape.Circle */
|
|
28
30
|
bulletShape?: GenericAccessor<BulletShape, BulletLegendItemInterface>;
|
|
29
31
|
/** Legend orientation. When set to `BulletLegendOrientation.Vertical`, each legend item will
|
|
@@ -7,6 +7,7 @@ const BulletLegendDefaultConfig = {
|
|
|
7
7
|
labelFontSize: null,
|
|
8
8
|
labelMaxWidth: null,
|
|
9
9
|
bulletSize: null,
|
|
10
|
+
bulletSpacing: 4,
|
|
10
11
|
bulletShape: d => { var _a; return (_a = d.shape) !== null && _a !== void 0 ? _a : BulletShape.Circle; },
|
|
11
12
|
orientation: BulletLegendOrientation.Horizontal,
|
|
12
13
|
renderIntoProvidedDomNode: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/bullet-legend/config.ts"],"sourcesContent":["// Local Types\nimport { GenericAccessor } from 'types/accessor'\nimport { BulletLegendItemInterface, BulletShape, BulletLegendOrientation } from './types'\n\nexport interface BulletLegendConfigInterface {\n /** Legend items. Array of `BulletLegendItemInterface`:\n * ```\n * {\n * name: string | number;\n * color?: string;\n * shape?: BulletShape;\n * inactive?: boolean;\n * hidden?: boolean;\n * pointer?: boolean;\n * }\n * ```\n * Default: `[]` */\n items: BulletLegendItemInterface[];\n /** Apply a specific class to the labels. Default: `''` */\n labelClassName?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((d: BulletLegendItemInterface, i: number) => void);\n /** Label text (<span> element) font-size CSS. Default: `null` */\n labelFontSize?: string | null;\n /** Label text (<span> element) max-width CSS property. Default: `null` */\n labelMaxWidth?: string | null;\n /** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */\n bulletSize?: string | null;\n /** Bullet shape enum value or accessor function. Default: `d => d.shape ?? BulletShape.Circle */\n bulletShape?: GenericAccessor<BulletShape, BulletLegendItemInterface>;\n /** Legend orientation. When set to `BulletLegendOrientation.Vertical`, each legend item will\n * start on a new line. Default: `BulletLegendOrientation.Horizontal` */\n orientation?: BulletLegendOrientation | string;\n /** If set to true, the legend will be rendered directly into the HTML element provided to the constructor\n * without creating additional `div` element. Default: `false` */\n renderIntoProvidedDomNode?: boolean;\n}\n\nexport const BulletLegendDefaultConfig: BulletLegendConfigInterface = {\n items: [],\n labelClassName: '',\n onLegendItemClick: undefined,\n labelFontSize: null,\n labelMaxWidth: null,\n bulletSize: null,\n bulletShape: d => d.shape ?? BulletShape.Circle,\n orientation: BulletLegendOrientation.Horizontal,\n renderIntoProvidedDomNode: false,\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/bullet-legend/config.ts"],"sourcesContent":["// Local Types\nimport { GenericAccessor } from 'types/accessor'\nimport { BulletLegendItemInterface, BulletShape, BulletLegendOrientation } from './types'\n\nexport interface BulletLegendConfigInterface {\n /** Legend items. Array of `BulletLegendItemInterface`:\n * ```\n * {\n * name: string | number;\n * color?: string;\n * shape?: BulletShape;\n * inactive?: boolean;\n * hidden?: boolean;\n * pointer?: boolean;\n * }\n * ```\n * Default: `[]` */\n items: BulletLegendItemInterface[];\n /** Apply a specific class to the labels. Default: `''` */\n labelClassName?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((d: BulletLegendItemInterface, i: number) => void);\n /** Label text (<span> element) font-size CSS. Default: `null` */\n labelFontSize?: string | null;\n /** Label text (<span> element) max-width CSS property. Default: `null` */\n labelMaxWidth?: string | null;\n /** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */\n bulletSize?: string | null;\n /** Spacing between multiple bullet symbols in pixels. Default: `4` */\n bulletSpacing?: number;\n /** Bullet shape enum value or accessor function. Default: `d => d.shape ?? BulletShape.Circle */\n bulletShape?: GenericAccessor<BulletShape, BulletLegendItemInterface>;\n /** Legend orientation. When set to `BulletLegendOrientation.Vertical`, each legend item will\n * start on a new line. Default: `BulletLegendOrientation.Horizontal` */\n orientation?: BulletLegendOrientation | string;\n /** If set to true, the legend will be rendered directly into the HTML element provided to the constructor\n * without creating additional `div` element. Default: `false` */\n renderIntoProvidedDomNode?: boolean;\n}\n\nexport const BulletLegendDefaultConfig: BulletLegendConfigInterface = {\n items: [],\n labelClassName: '',\n onLegendItemClick: undefined,\n labelFontSize: null,\n labelMaxWidth: null,\n bulletSize: null,\n bulletSpacing: 4,\n bulletShape: d => d.shape ?? BulletShape.Circle,\n orientation: BulletLegendOrientation.Horizontal,\n renderIntoProvidedDomNode: false,\n}\n"],"names":[],"mappings":";;AAwCa,MAAA,yBAAyB,GAAgC;AACpE,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,cAAc,EAAE,EAAE;AAClB,IAAA,iBAAiB,EAAE,SAAS;AAC5B,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,WAAW,EAAE,CAAC,cAAI,OAAA,CAAA,EAAA,GAAA,CAAC,CAAC,KAAK,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,WAAW,CAAC,MAAM,CAAA,EAAA;IAC/C,WAAW,EAAE,uBAAuB,CAAC,UAAU;AAC/C,IAAA,yBAAyB,EAAE,KAAK;;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { select } from 'd3-selection';
|
|
2
|
+
import toPx from 'to-px';
|
|
2
3
|
import { merge } from '../../utils/data.js';
|
|
3
4
|
import { BulletLegendDefaultConfig } from './config.js';
|
|
4
5
|
import { BulletLegendOrientation } from './types.js';
|
|
5
|
-
import { createBullets, updateBullets } from './modules/shape.js';
|
|
6
|
+
import { createBullets, getBulletsTotalWidth, updateBullets } from './modules/shape.js';
|
|
6
7
|
import * as style from './style.js';
|
|
7
8
|
import { root, item, itemVertical, clickable, bullet, label } from './style.js';
|
|
8
9
|
|
|
@@ -40,7 +41,14 @@ class BulletLegend {
|
|
|
40
41
|
.attr('class', bullet)
|
|
41
42
|
.call(createBullets);
|
|
42
43
|
legendItemsMerged.select(`.${bullet}`)
|
|
43
|
-
.style('width',
|
|
44
|
+
.style('width', function (d) {
|
|
45
|
+
const colors = Array.isArray(d.color) ? d.color : [d.color];
|
|
46
|
+
const numColors = colors.length;
|
|
47
|
+
const defaultSize = toPx(getComputedStyle(this).getPropertyValue('--vis-legend-bullet-size')) || 9;
|
|
48
|
+
const baseSize = config.bulletSize ? toPx(config.bulletSize) : defaultSize;
|
|
49
|
+
const spacing = config.bulletSpacing;
|
|
50
|
+
return `${getBulletsTotalWidth(baseSize, numColors, spacing)}px`;
|
|
51
|
+
})
|
|
44
52
|
.style('height', config.bulletSize)
|
|
45
53
|
.style('box-sizing', 'content-box')
|
|
46
54
|
.call(updateBullets, this.config, this._colorAccessor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/bullet-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Config\nimport { BulletLegendDefaultConfig, BulletLegendConfigInterface } from './config'\n\n// Local Types\nimport { BulletLegendItemInterface, BulletLegendOrientation } from './types'\n\n// Modules\nimport { createBullets, updateBullets } from './modules/shape'\n\n// Styles\nimport * as s from './style'\n\nexport class BulletLegend {\n static selectors = s\n protected _defaultConfig = BulletLegendDefaultConfig as BulletLegendConfigInterface\n public config: BulletLegendConfigInterface = this._defaultConfig\n\n div: Selection<HTMLElement, unknown, null, undefined>\n element: HTMLElement\n prevConfig: BulletLegendConfigInterface\n protected _container: HTMLElement\n\n private _colorAccessor = (d: BulletLegendItemInterface): string => d.color\n\n constructor (element: HTMLElement, config?: BulletLegendConfigInterface) {\n this._container = element\n\n this.div = config?.renderIntoProvidedDomNode ? select(this._container) : select(this._container).append<HTMLElement>('div')\n this.div.classed(s.root, true)\n\n this.element = this.div.node()\n\n if (config) this.update(config)\n }\n\n update (config: BulletLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n\n const legendItems = this.div.selectAll<HTMLDivElement, unknown>(`.${s.item}`).data(config.items)\n\n const legendItemsEnter = legendItems.enter().append('div')\n .on('click', this._onItemClick.bind(this))\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n legendItemsMerged\n .attr('class', d => `${s.item} ${d.className ?? ''}`)\n .classed(s.itemVertical, config.orientation === BulletLegendOrientation.Vertical)\n .classed(s.clickable, d => !!config.onLegendItemClick && this._isItemClickable(d))\n .attr('title', d => d.name)\n .style('display', (d: BulletLegendItemInterface) => d.hidden ? 'none' : null)\n\n // Bullet\n legendItemsEnter.append('span')\n .attr('class', s.bullet)\n .call(createBullets)\n\n legendItemsMerged.select<SVGElement>(`.${s.bullet}`)\n .style('width', config.bulletSize)\n .style('height', config.bulletSize)\n .style('box-sizing', 'content-box')\n .call(updateBullets, this.config, this._colorAccessor)\n\n // Labels\n legendItemsEnter.append('span')\n .attr('class', s.label)\n .classed(config.labelClassName, true)\n .style('max-width', config.labelMaxWidth)\n .style('font-size', config.labelFontSize)\n\n legendItemsMerged.select(`.${s.label}`)\n .text((d: BulletLegendItemInterface) => d.name)\n\n legendItems.exit().remove()\n }\n\n _isItemClickable (item: BulletLegendItemInterface): boolean {\n return item.pointer === undefined ? true : item.pointer\n }\n\n _onItemClick (event: MouseEvent, d: BulletLegendItemInterface): void {\n const { config: { onLegendItemClick } } = this\n\n const legendItems = this.div.selectAll(`.${s.item}`).nodes() as HTMLElement[]\n const index = legendItems.indexOf(event.currentTarget as HTMLElement)\n if (onLegendItemClick) onLegendItemClick(d, index)\n }\n\n public destroy (): void {\n if (this.element !== this._container) this.div.remove()\n }\n}\n"],"names":["s.root","s.item","s.itemVertical","s.clickable","s.bullet","s.label","s"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/bullet-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport toPx from 'to-px'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Config\nimport { BulletLegendDefaultConfig, BulletLegendConfigInterface } from './config'\n\n// Local Types\nimport { BulletLegendItemInterface, BulletLegendOrientation } from './types'\n\n// Modules\nimport { createBullets, updateBullets, getBulletsTotalWidth } from './modules/shape'\n\n// Styles\nimport * as s from './style'\n\nexport class BulletLegend {\n static selectors = s\n protected _defaultConfig = BulletLegendDefaultConfig as BulletLegendConfigInterface\n public config: BulletLegendConfigInterface = this._defaultConfig\n\n div: Selection<HTMLElement, unknown, null, undefined>\n element: HTMLElement\n prevConfig: BulletLegendConfigInterface\n protected _container: HTMLElement\n\n private _colorAccessor = (d: BulletLegendItemInterface): string|string[] => d.color\n\n constructor (element: HTMLElement, config?: BulletLegendConfigInterface) {\n this._container = element\n\n this.div = config?.renderIntoProvidedDomNode ? select(this._container) : select(this._container).append<HTMLElement>('div')\n this.div.classed(s.root, true)\n\n this.element = this.div.node()\n\n if (config) this.update(config)\n }\n\n update (config: BulletLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n\n const legendItems = this.div.selectAll<HTMLDivElement, unknown>(`.${s.item}`).data(config.items)\n\n const legendItemsEnter = legendItems.enter().append('div')\n .on('click', this._onItemClick.bind(this))\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n legendItemsMerged\n .attr('class', d => `${s.item} ${d.className ?? ''}`)\n .classed(s.itemVertical, config.orientation === BulletLegendOrientation.Vertical)\n .classed(s.clickable, d => !!config.onLegendItemClick && this._isItemClickable(d))\n .attr('title', d => d.name)\n .style('display', (d: BulletLegendItemInterface) => d.hidden ? 'none' : null)\n\n // Bullet\n legendItemsEnter.append('span')\n .attr('class', s.bullet)\n .call(createBullets)\n\n legendItemsMerged.select<SVGElement>(`.${s.bullet}`)\n .style('width', function (d: BulletLegendItemInterface) {\n const colors = Array.isArray(d.color) ? d.color : [d.color]\n const numColors = colors.length\n const defaultSize = toPx(getComputedStyle(this).getPropertyValue('--vis-legend-bullet-size')) || 9\n const baseSize = config.bulletSize ? toPx(config.bulletSize) : defaultSize\n const spacing = config.bulletSpacing\n return `${getBulletsTotalWidth(baseSize, numColors, spacing)}px`\n })\n .style('height', config.bulletSize)\n .style('box-sizing', 'content-box')\n .call(updateBullets, this.config, this._colorAccessor)\n\n // Labels\n legendItemsEnter.append('span')\n .attr('class', s.label)\n .classed(config.labelClassName, true)\n .style('max-width', config.labelMaxWidth)\n .style('font-size', config.labelFontSize)\n\n legendItemsMerged.select(`.${s.label}`)\n .text((d: BulletLegendItemInterface) => d.name)\n\n legendItems.exit().remove()\n }\n\n _isItemClickable (item: BulletLegendItemInterface): boolean {\n return item.pointer === undefined ? true : item.pointer\n }\n\n _onItemClick (event: MouseEvent, d: BulletLegendItemInterface): void {\n const { config: { onLegendItemClick } } = this\n\n const legendItems = this.div.selectAll(`.${s.item}`).nodes() as HTMLElement[]\n const index = legendItems.indexOf(event.currentTarget as HTMLElement)\n if (onLegendItemClick) onLegendItemClick(d, index)\n }\n\n public destroy (): void {\n if (this.element !== this._container) this.div.remove()\n }\n}\n"],"names":["s.root","s.item","s.itemVertical","s.clickable","s.bullet","s.label","s"],"mappings":";;;;;;;;;MAkBa,YAAY,CAAA;IAYvB,WAA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S,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAA;KACxD;IAED,YAAY,CAAE,KAAiB,EAAE,CAA4B,EAAA;QAC3D,MAAM,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,EAAE,GAAG,IAAI,CAAA;AAE9C,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAI,CAAA,EAAAJ,IAAM,CAAA,CAAE,CAAC,CAAC,KAAK,EAAmB,CAAA;QAC7E,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,aAA4B,CAAC,CAAA;AACrE,QAAA,IAAI,iBAAiB;AAAE,YAAA,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;KACnD;IAEM,OAAO,GAAA;AACZ,QAAA,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,UAAU;AAAE,YAAA,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;KACxD;;AAzFM,YAAS,CAAA,SAAA,GAAGK,KAAC;;;;"}
|
|
@@ -2,5 +2,6 @@ import { Selection } from 'd3-selection';
|
|
|
2
2
|
import { ColorAccessor } from "../../../types/accessor";
|
|
3
3
|
import { BulletLegendConfigInterface } from '../config';
|
|
4
4
|
import { BulletLegendItemInterface } from '../types';
|
|
5
|
+
export declare function getBulletsTotalWidth(bulletSize: number, numBullets: number, spacing: number): number;
|
|
5
6
|
export declare function createBullets(container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLElement, unknown>): void;
|
|
6
7
|
export declare function updateBullets(container: Selection<SVGElement, BulletLegendItemInterface, HTMLElement, unknown>, config: BulletLegendConfigInterface, colorAccessor: ColorAccessor<BulletLegendItemInterface>): void;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { select } from 'd3-selection';
|
|
2
2
|
import { symbol } from 'd3-shape';
|
|
3
|
+
import toPx from 'to-px';
|
|
3
4
|
import { Symbol } from '../../../types/symbol.js';
|
|
4
5
|
import { getColor } from '../../../utils/color.js';
|
|
5
|
-
import { getString } from '../../../utils/data.js';
|
|
6
|
+
import { getString, ensureArray } from '../../../utils/data.js';
|
|
6
7
|
import { PATTERN_SIZE_PX } from '../../../styles/patterns.js';
|
|
7
8
|
import { BulletShape } from '../types.js';
|
|
8
9
|
|
|
@@ -19,6 +20,11 @@ const shapeScale = {
|
|
|
19
20
|
[BulletShape.Triangle]: Math.sqrt(3) / 4,
|
|
20
21
|
[BulletShape.Wye]: 5 / 11,
|
|
21
22
|
};
|
|
23
|
+
function getBulletsTotalWidth(bulletSize, numBullets, spacing) {
|
|
24
|
+
if (numBullets < 1)
|
|
25
|
+
return 0;
|
|
26
|
+
return bulletSize * numBullets + spacing * (numBullets - 1);
|
|
27
|
+
}
|
|
22
28
|
function createBullets(container) {
|
|
23
29
|
container.each((d, i, els) => {
|
|
24
30
|
select(els[i]).append('svg')
|
|
@@ -29,53 +35,67 @@ function createBullets(container) {
|
|
|
29
35
|
}
|
|
30
36
|
function updateBullets(container, config, colorAccessor) {
|
|
31
37
|
container.each((d, i, els) => {
|
|
38
|
+
var _a;
|
|
32
39
|
const shape = getString(d, config.bulletShape, i);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
40
|
+
const colors = ensureArray((_a = d.color) !== null && _a !== void 0 ? _a : getColor(d, colorAccessor, i));
|
|
41
|
+
const numBullets = colors.length;
|
|
42
|
+
const bulletWidth = BULLET_SIZE;
|
|
43
|
+
const defaultBulletSize = toPx(getComputedStyle(els[i]).getPropertyValue('--vis-legend-bullet-size'));
|
|
44
|
+
const spacing = config.bulletSpacing * (BULLET_SIZE / defaultBulletSize); // Scale spacing relative to bullet size
|
|
45
|
+
const width = getBulletsTotalWidth(bulletWidth, numBullets, spacing);
|
|
35
46
|
const height = shape === BulletShape.Line ? BULLET_SIZE / 2.5 : BULLET_SIZE;
|
|
36
47
|
const selection = select(els[i]).select('svg')
|
|
37
48
|
.attr('viewBox', `0 0 ${width} ${height}`);
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
// Remove existing paths
|
|
50
|
+
selection.selectAll('path').remove();
|
|
40
51
|
const opacity = d.inactive ? 'var(--vis-legend-bullet-inactive-opacity)' : 1;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
// Create a path for each color
|
|
53
|
+
colors.forEach((color, colorIndex) => {
|
|
54
|
+
const bulletPath = selection.append('path');
|
|
55
|
+
if (shape === BulletShape.Line) {
|
|
56
|
+
const x1 = colorIndex * (bulletWidth + spacing);
|
|
57
|
+
const x2 = x1 + bulletWidth;
|
|
58
|
+
bulletPath
|
|
59
|
+
.attr('d', `M${x1},${height / 2} L${x2},${height / 2}`)
|
|
60
|
+
.attr('transform', null)
|
|
61
|
+
.style('opacity', opacity)
|
|
62
|
+
.style('stroke', color)
|
|
63
|
+
.style('stroke-width', '3px')
|
|
64
|
+
.style('fill', null)
|
|
65
|
+
.style('fill-opacity', null)
|
|
66
|
+
.style('marker-start', 'none')
|
|
67
|
+
.style('marker-end', 'none');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const symbolGen = symbol()
|
|
71
|
+
.type(Symbol[shape])
|
|
72
|
+
.size(bulletWidth * height * shapeScale[shape]);
|
|
73
|
+
const scale = (bulletWidth - 2) / bulletWidth;
|
|
74
|
+
let dy = height / 2;
|
|
75
|
+
switch (shape) {
|
|
76
|
+
case BulletShape.Triangle:
|
|
77
|
+
dy += height / 8;
|
|
78
|
+
break;
|
|
79
|
+
case BulletShape.Star:
|
|
80
|
+
dy += height / 16;
|
|
81
|
+
break;
|
|
82
|
+
case BulletShape.Wye:
|
|
83
|
+
dy -= height / 16;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
const dx = colorIndex * (bulletWidth + spacing) + bulletWidth / 2;
|
|
87
|
+
bulletPath
|
|
88
|
+
.attr('d', symbolGen)
|
|
89
|
+
.attr('transform', `translate(${dx}, ${Math.round(dy)}) scale(${scale})`)
|
|
90
|
+
.style('stroke', color)
|
|
91
|
+
.style('stroke-width', '1px')
|
|
92
|
+
.style('opacity', null)
|
|
93
|
+
.style('fill', color)
|
|
94
|
+
.style('fill-opacity', opacity);
|
|
68
95
|
}
|
|
69
|
-
|
|
70
|
-
.attr('d', symbolGen)
|
|
71
|
-
.attr('transform', `translate(${width / 2}, ${Math.round(dy)}) scale(${scale})`)
|
|
72
|
-
.style('stroke-width', '1px')
|
|
73
|
-
.style('opacity', null)
|
|
74
|
-
.style('fill', color)
|
|
75
|
-
.style('fill-opacity', opacity);
|
|
76
|
-
}
|
|
96
|
+
});
|
|
77
97
|
});
|
|
78
98
|
}
|
|
79
99
|
|
|
80
|
-
export { createBullets, updateBullets };
|
|
100
|
+
export { createBullets, getBulletsTotalWidth, updateBullets };
|
|
81
101
|
//# sourceMappingURL=shape.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.js","sources":["../../../../src/components/bullet-legend/modules/shape.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { symbol } from 'd3-shape'\n\n// Types\nimport { ColorAccessor } from 'types/accessor'\nimport { Symbol, SymbolType } from 'types/symbol'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { getString } from 'utils/data'\n\n// Constants\nimport { PATTERN_SIZE_PX } from 'styles/patterns'\n\n// Local types\nimport { BulletLegendConfigInterface } from '../config'\nimport { BulletShape, BulletLegendItemInterface } from '../types'\n\n// Size with respect to the viewBox. We use this to compute path data which is independent of the\n// the configured size.\nconst BULLET_SIZE = PATTERN_SIZE_PX * 3\n\n// Different shapes need different scaling to fit the full size\nconst shapeScale: Record<SymbolType, number> = {\n [BulletShape.Circle]: Math.PI / 4,\n [BulletShape.Cross]: 5 / 9,\n [BulletShape.Diamond]: Math.sqrt(3) / 6,\n [BulletShape.Square]: 1,\n [BulletShape.Star]: 0.3,\n [BulletShape.Triangle]: Math.sqrt(3) / 4,\n [BulletShape.Wye]: 5 / 11,\n}\n\nexport function createBullets (\n container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLElement, unknown>\n): void {\n container.each((d, i, els) => {\n select(els[i]).append('svg')\n .attr('width', '100%')\n .attr('height', '100%')\n .append('path')\n })\n}\n\nexport function updateBullets (\n container: Selection<SVGElement, BulletLegendItemInterface, HTMLElement, unknown>,\n config: BulletLegendConfigInterface,\n colorAccessor: ColorAccessor<BulletLegendItemInterface>\n): void {\n container.each((d, i, els) => {\n const shape = getString(d, config.bulletShape, i) as BulletShape\n const
|
|
1
|
+
{"version":3,"file":"shape.js","sources":["../../../../src/components/bullet-legend/modules/shape.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { symbol } from 'd3-shape'\nimport toPx from 'to-px'\n\n// Types\nimport { ColorAccessor } from 'types/accessor'\nimport { Symbol, SymbolType } from 'types/symbol'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { ensureArray, getString } from 'utils/data'\n\n// Constants\nimport { PATTERN_SIZE_PX } from 'styles/patterns'\n\n// Local types\nimport { BulletLegendConfigInterface } from '../config'\nimport { BulletShape, BulletLegendItemInterface } from '../types'\n\n// Size with respect to the viewBox. We use this to compute path data which is independent of the\n// the configured size.\nconst BULLET_SIZE = PATTERN_SIZE_PX * 3\n\n// Different shapes need different scaling to fit the full size\nconst shapeScale: Record<SymbolType, number> = {\n [BulletShape.Circle]: Math.PI / 4,\n [BulletShape.Cross]: 5 / 9,\n [BulletShape.Diamond]: Math.sqrt(3) / 6,\n [BulletShape.Square]: 1,\n [BulletShape.Star]: 0.3,\n [BulletShape.Triangle]: Math.sqrt(3) / 4,\n [BulletShape.Wye]: 5 / 11,\n}\n\nexport function getBulletsTotalWidth (bulletSize: number, numBullets: number, spacing: number): number {\n if (numBullets < 1) return 0\n return bulletSize * numBullets + spacing * (numBullets - 1)\n}\n\nexport function createBullets (\n container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLElement, unknown>\n): void {\n container.each((d, i, els) => {\n select(els[i]).append('svg')\n .attr('width', '100%')\n .attr('height', '100%')\n .append('path')\n })\n}\n\nexport function updateBullets (\n container: Selection<SVGElement, BulletLegendItemInterface, HTMLElement, unknown>,\n config: BulletLegendConfigInterface,\n colorAccessor: ColorAccessor<BulletLegendItemInterface>\n): void {\n container.each((d, i, els) => {\n const shape = getString(d, config.bulletShape, i) as BulletShape\n const colors = ensureArray(d.color ?? getColor(d, colorAccessor, i))\n const numBullets = colors.length\n const bulletWidth = BULLET_SIZE\n const defaultBulletSize = toPx(getComputedStyle(els[i]).getPropertyValue('--vis-legend-bullet-size'))\n const spacing = config.bulletSpacing * (BULLET_SIZE / defaultBulletSize) // Scale spacing relative to bullet size\n const width = getBulletsTotalWidth(bulletWidth, numBullets, spacing)\n const height = shape === BulletShape.Line ? BULLET_SIZE / 2.5 : BULLET_SIZE\n\n const selection = select(els[i]).select('svg')\n .attr('viewBox', `0 0 ${width} ${height}`)\n\n // Remove existing paths\n selection.selectAll('path').remove()\n\n const opacity = d.inactive ? 'var(--vis-legend-bullet-inactive-opacity)' : 1\n\n // Create a path for each color\n colors.forEach((color, colorIndex) => {\n const bulletPath = selection.append('path')\n\n if (shape === BulletShape.Line) {\n const x1 = colorIndex * (bulletWidth + spacing)\n const x2 = x1 + bulletWidth\n bulletPath\n .attr('d', `M${x1},${height / 2} L${x2},${height / 2}`)\n .attr('transform', null)\n .style('opacity', opacity)\n .style('stroke', color)\n .style('stroke-width', '3px')\n .style('fill', null)\n .style('fill-opacity', null)\n .style('marker-start', 'none')\n .style('marker-end', 'none')\n } else {\n const symbolGen = symbol()\n .type(Symbol[shape])\n .size(bulletWidth * height * shapeScale[shape])\n\n const scale = (bulletWidth - 2) / bulletWidth\n let dy = height / 2\n switch (shape) {\n case BulletShape.Triangle:\n dy += height / 8\n break\n case BulletShape.Star:\n dy += height / 16\n break\n case BulletShape.Wye:\n dy -= height / 16\n break\n }\n\n const dx = colorIndex * (bulletWidth + spacing) + bulletWidth / 2\n bulletPath\n .attr('d', symbolGen)\n .attr('transform', `translate(${dx}, ${Math.round(dy)}) scale(${scale})`)\n .style('stroke', color)\n .style('stroke-width', '1px')\n .style('opacity', null)\n .style('fill', color)\n .style('fill-opacity', opacity)\n }\n })\n })\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBA;AACA;AACA,MAAM,WAAW,GAAG,eAAe,GAAG,CAAC,CAAA;AAEvC;AACA,MAAM,UAAU,GAA+B;IAC7C,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC;AACjC,IAAA,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC;AAC1B,IAAA,CAAC,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACvC,IAAA,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;AACvB,IAAA,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG;AACvB,IAAA,CAAC,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACxC,IAAA,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE;CAC1B,CAAA;SAEe,oBAAoB,CAAE,UAAkB,EAAE,UAAkB,EAAE,OAAe,EAAA;IAC3F,IAAI,UAAU,GAAG,CAAC;AAAE,QAAA,OAAO,CAAC,CAAA;IAC5B,OAAO,UAAU,GAAG,UAAU,GAAG,OAAO,IAAI,UAAU,GAAG,CAAC,CAAC,CAAA;AAC7D,CAAC;AAEK,SAAU,aAAa,CA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AE,OAAO,CAAC,CAAA;AAClC,aAAA;AACH,SAAC,CAAC,CAAA;AACJ,KAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/components/bullet-legend/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport { SymbolType } from 'types/symbol'\n\nexport interface BulletLegendItemInterface {\n name: string | number;\n color?: string
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/components/bullet-legend/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport { SymbolType } from 'types/symbol'\n\nexport interface BulletLegendItemInterface {\n name: string | number;\n color?: string | Array<string>;\n className?: string;\n shape?: BulletShape;\n inactive?: boolean;\n hidden?: boolean;\n pointer?: boolean;\n}\n\nexport const BulletShape = {\n ...SymbolType,\n Line: 'line',\n} as const\n\nexport type BulletShape = typeof BulletShape[keyof typeof BulletShape]\n\nexport enum BulletLegendOrientation {\n Horizontal = 'horizontal',\n Vertical = 'vertical',\n}\n"],"names":[],"mappings":";;AAAA;AAaa,MAAA,WAAW,GAAG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACtB,UAAU,CAAA,EAAA,EACb,IAAI,EAAE,MAAM,EAAA,EACJ;IAIE,wBAGX;AAHD,CAAA,UAAY,uBAAuB,EAAA;AACjC,IAAA,uBAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB,IAAA,uBAAA,CAAA,UAAA,CAAA,GAAA,UAAqB,CAAA;AACvB,CAAC,EAHW,uBAAuB,KAAvB,uBAAuB,GAGlC,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -21,9 +21,11 @@ export interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponen
|
|
|
21
21
|
baseline?: NumericAccessor<Datum>;
|
|
22
22
|
/** An instance of the Tooltip component to be used with Crosshair. Default: `undefined` */
|
|
23
23
|
tooltip?: Tooltip | undefined;
|
|
24
|
-
/** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement.
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement.
|
|
25
|
+
* When `snapToData` is `false`, `datum` will be `undefined` but `data` and `leftNearestDatumIndex` will be provided.
|
|
26
|
+
* Default: `d => ''` */
|
|
27
|
+
template?: (datum: Datum, x: number | Date, data: Datum[], leftNearestDatumIndex: number) => string | HTMLElement;
|
|
28
|
+
/** Hide Crosshair when the corresponding datum element is far from mouse pointer. Default: `true` */
|
|
27
29
|
hideWhenFarFromPointer?: boolean;
|
|
28
30
|
/** Distance in pixels to check in the hideWhenFarFromPointer condition. Default: `100` */
|
|
29
31
|
hideWhenFarFromPointerDistance?: number;
|
|
@@ -34,11 +36,22 @@ export interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponen
|
|
|
34
36
|
*/
|
|
35
37
|
snapToData?: boolean;
|
|
36
38
|
/** Custom function for setting up the crosshair circles, usually needed when `snapToData` is set to `false`.
|
|
37
|
-
* The function receives the horizontal position of the crosshair (in the data space, not in pixels), the data array
|
|
38
|
-
*
|
|
39
|
-
* It has to return an array of the CrosshairCircle objects: `{ y: number; color: string; opacity?: number }[]`.
|
|
39
|
+
* The function receives the horizontal position of the crosshair (in the data space, not in pixels), the data array,
|
|
40
|
+
* the `yScale` instance to help you calculate the correct vertical position of the circles, and the nearest datum index.
|
|
41
|
+
* It has to return an array of the `CrosshairCircle` objects: `{ y: number; color: string; opacity?: number }[]`.
|
|
40
42
|
* Default: `undefined`
|
|
41
43
|
*/
|
|
42
|
-
getCircles?: (x: number | Date
|
|
44
|
+
getCircles?: (x: number | Date, data: Datum[], yScale: ContinuousScale, leftNearestDatumIndex: number) => CrosshairCircle[];
|
|
45
|
+
/** Callback function that is called when the crosshair is moved:
|
|
46
|
+
* - `x` is the horizontal position of the crosshair in the data space;
|
|
47
|
+
* - `datum` is the nearest datum to the crosshair;
|
|
48
|
+
* - `datumIndex` is the index of the nearest datum.
|
|
49
|
+
* - `event` is the event that triggered the crosshair move (mouse or wheel).
|
|
50
|
+
*
|
|
51
|
+
* When the mouse goes out of the container and on wheel events, all the arguments are `undefined` except for `event`.
|
|
52
|
+
* Default: `undefined` */
|
|
53
|
+
onCrosshairMove?: (x?: number | Date, datum?: Datum, datumIndex?: number, event?: MouseEvent | WheelEvent) => void;
|
|
54
|
+
/** Force the crosshair to show at a specific position. Default: `undefined` */
|
|
55
|
+
forceShowAt?: number | Date;
|
|
43
56
|
}
|
|
44
57
|
export declare const CrosshairDefaultConfig: CrosshairConfigInterface<unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { XYComponentDefaultConfig } from '../../core/xy-component/config.js';
|
|
2
2
|
|
|
3
|
-
const CrosshairDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), { yStacked: undefined, baseline: null, duration: 100, tooltip: undefined, template: (d, x) => '', hideWhenFarFromPointer: true, hideWhenFarFromPointerDistance: 100, snapToData: true, getCircles: undefined, color: undefined, strokeColor: undefined, strokeWidth: undefined });
|
|
3
|
+
const CrosshairDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), { yStacked: undefined, baseline: null, duration: 100, tooltip: undefined, template: (d, x, data, leftNearestDatumIndex) => '', hideWhenFarFromPointer: true, hideWhenFarFromPointerDistance: 100, snapToData: true, getCircles: undefined, color: undefined, strokeColor: undefined, strokeWidth: undefined, onCrosshairMove: undefined, forceShowAt: undefined });
|
|
4
4
|
|
|
5
5
|
export { CrosshairDefaultConfig };
|
|
6
6
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\nimport { Tooltip } from 'components/tooltip'\n\n// Types\nimport { NumericAccessor, ColorAccessor } from 'types/accessor'\nimport { ContinuousScale } from 'types/scale'\nimport { WithOptional } from 'types/misc'\nimport { CrosshairCircle } from './types'\n\n// We extend partial XY config interface because x and y properties are optional for Crosshair\nexport interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponentConfigInterface<Datum>, 'x' | 'y'> {\n /** Optional accessor function for getting the values along the X axis. Default: `undefined` */\n x?: NumericAccessor<Datum>;\n /** Optional single of multiple accessor functions for getting the values along the Y axis. Default: `undefined` */\n y?: NumericAccessor<Datum> | NumericAccessor<Datum>[];\n /** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */\n color?: ColorAccessor<Datum>;\n /** Optional stroke color accessor function for crosshair circles. Default: `undefined` */\n strokeColor?: ColorAccessor<Datum>;\n /** Optional stroke width for crosshair circles. Default: `undefined` */\n strokeWidth?: NumericAccessor<Datum>;\n /** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */\n yStacked?: NumericAccessor<Datum>[];\n /** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */\n baseline?: NumericAccessor<Datum>;\n /** An instance of the Tooltip component to be used with Crosshair. Default: `undefined` */\n tooltip?: Tooltip | undefined;\n /** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\nimport { Tooltip } from 'components/tooltip'\n\n// Types\nimport { NumericAccessor, ColorAccessor } from 'types/accessor'\nimport { ContinuousScale } from 'types/scale'\nimport { WithOptional } from 'types/misc'\nimport { CrosshairCircle } from './types'\n\n// We extend partial XY config interface because x and y properties are optional for Crosshair\nexport interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponentConfigInterface<Datum>, 'x' | 'y'> {\n /** Optional accessor function for getting the values along the X axis. Default: `undefined` */\n x?: NumericAccessor<Datum>;\n /** Optional single of multiple accessor functions for getting the values along the Y axis. Default: `undefined` */\n y?: NumericAccessor<Datum> | NumericAccessor<Datum>[];\n /** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */\n color?: ColorAccessor<Datum>;\n /** Optional stroke color accessor function for crosshair circles. Default: `undefined` */\n strokeColor?: ColorAccessor<Datum>;\n /** Optional stroke width for crosshair circles. Default: `undefined` */\n strokeWidth?: NumericAccessor<Datum>;\n /** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */\n yStacked?: NumericAccessor<Datum>[];\n /** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */\n baseline?: NumericAccessor<Datum>;\n /** An instance of the Tooltip component to be used with Crosshair. Default: `undefined` */\n tooltip?: Tooltip | undefined;\n // TODO: Change `datum` type to `Datum | undefined`. This may break the build for many people, so we might want to do it in version 2.0\n /** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement.\n * When `snapToData` is `false`, `datum` will be `undefined` but `data` and `leftNearestDatumIndex` will be provided.\n * Default: `d => ''` */\n template?: (datum: Datum, x: number | Date, data: Datum[], leftNearestDatumIndex: number) => string | HTMLElement;\n /** Hide Crosshair when the corresponding datum element is far from mouse pointer. Default: `true` */\n hideWhenFarFromPointer?: boolean;\n /** Distance in pixels to check in the hideWhenFarFromPointer condition. Default: `100` */\n hideWhenFarFromPointerDistance?: number;\n /** Snap to the nearest data point.\n * If disabled, the tooltip template will receive only the horizontal position of the crosshair and you'll be responsible\n * for getting the underlying data records and crosshair circles (see the `getCircles` configuration option).\n * Default: `true`\n */\n snapToData?: boolean;\n /** Custom function for setting up the crosshair circles, usually needed when `snapToData` is set to `false`.\n * The function receives the horizontal position of the crosshair (in the data space, not in pixels), the data array,\n * the `yScale` instance to help you calculate the correct vertical position of the circles, and the nearest datum index.\n * It has to return an array of the `CrosshairCircle` objects: `{ y: number; color: string; opacity?: number }[]`.\n * Default: `undefined`\n */\n getCircles?: (x: number | Date, data: Datum[], yScale: ContinuousScale, leftNearestDatumIndex: number) => CrosshairCircle[];\n /** Callback function that is called when the crosshair is moved:\n * - `x` is the horizontal position of the crosshair in the data space;\n * - `datum` is the nearest datum to the crosshair;\n * - `datumIndex` is the index of the nearest datum.\n * - `event` is the event that triggered the crosshair move (mouse or wheel).\n *\n * When the mouse goes out of the container and on wheel events, all the arguments are `undefined` except for `event`.\n * Default: `undefined` */\n onCrosshairMove?: (x?: number | Date, datum?: Datum, datumIndex?: number, event?: MouseEvent | WheelEvent) => void;\n /** Force the crosshair to show at a specific position. Default: `undefined` */\n forceShowAt?: number | Date;\n}\n\nexport const CrosshairDefaultConfig: CrosshairConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n yStacked: undefined,\n baseline: null,\n duration: 100,\n tooltip: undefined,\n template: <Datum>(d: Datum, x: number | Date, data: Datum[], leftNearestDatumIndex: number): string => '',\n hideWhenFarFromPointer: true,\n hideWhenFarFromPointerDistance: 100,\n snapToData: true,\n getCircles: undefined,\n color: undefined,\n strokeColor: undefined,\n strokeWidth: undefined,\n onCrosshairMove: undefined,\n forceShowAt: undefined,\n}\n\n"],"names":[],"mappings":";;AA8DO,MAAM,sBAAsB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC9B,wBAAwB,CAC3B,EAAA,EAAA,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,SAAS,EAClB,QAAQ,EAAE,CAAQ,CAAQ,EAAE,CAAgB,EAAE,IAAa,EAAE,qBAA6B,KAAa,EAAE,EACzG,sBAAsB,EAAE,IAAI,EAC5B,8BAA8B,EAAE,GAAG,EACnC,UAAU,EAAE,IAAI,EAChB,UAAU,EAAE,SAAS,EACrB,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,SAAS,EACtB,WAAW,EAAE,SAAS,EACtB,eAAe,EAAE,SAAS,EAC1B,WAAW,EAAE,SAAS;;;;"}
|
|
@@ -11,10 +11,9 @@ export declare class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairCo
|
|
|
11
11
|
config: CrosshairConfigInterface<Datum>;
|
|
12
12
|
container: Selection<SVGSVGElement, any, SVGSVGElement, any>;
|
|
13
13
|
line: Selection<SVGLineElement, any, SVGElement, any>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
show: boolean;
|
|
14
|
+
private _xPx;
|
|
15
|
+
private _yPx;
|
|
16
|
+
private _mouseEvent;
|
|
18
17
|
private _animFrameId;
|
|
19
18
|
/** Tooltip component to be used by Crosshair if not provided by the config.
|
|
20
19
|
* This property is supposed to be set externally by a container component like XYContainer. */
|
|
@@ -23,13 +22,15 @@ export declare class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairCo
|
|
|
23
22
|
private _accessors;
|
|
24
23
|
set accessors(accessors: CrosshairAccessors<Datum>);
|
|
25
24
|
get accessors(): CrosshairAccessors<Datum>;
|
|
25
|
+
private _isContainerInViewport;
|
|
26
26
|
constructor(config?: CrosshairConfigInterface<Datum>);
|
|
27
27
|
setContainer(containerSvg: Selection<SVGSVGElement, unknown, SVGSVGElement, unknown>): void;
|
|
28
28
|
_render(customDuration?: number): void;
|
|
29
|
-
hide(): void;
|
|
29
|
+
hide(sourceEvent?: MouseEvent | WheelEvent): void;
|
|
30
30
|
_onMouseMove(event: MouseEvent): void;
|
|
31
|
-
_onMouseOut(): void;
|
|
32
|
-
|
|
31
|
+
_onMouseOut(event?: MouseEvent): void;
|
|
32
|
+
_onWheel(event: WheelEvent): void;
|
|
33
|
+
_showTooltip(datum: Datum, xValue: number, pos: [number, number], nearestDatumIndex: number | undefined): void;
|
|
33
34
|
_hideTooltip(): void;
|
|
34
35
|
getYDataExtent(): number[];
|
|
35
36
|
private getCircleData;
|