Browse Source

Merge pull request 'New renderEnd callbacks' (#2) from new-part-render-end-callback into main

Reviewed-on: #2
pull/3/head
vargburz 1 year ago
parent
commit
da36400a02
  1. 2
      package.json
  2. 10
      src/index.ts
  3. 8
      src/models/options.ts
  4. 11
      src/types.ts

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/core", "name": "@chartwerk/core",
"version": "0.6.14", "version": "0.6.15",
"description": "Chartwerk core", "description": "Chartwerk core",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

10
src/index.ts

@ -23,6 +23,7 @@ import {
ScrollPanDirection, ScrollPanDirection,
AxisOption, AxisOption,
AxesOptions, AxesOptions,
RenderComponent,
} from './types'; } from './types';
import { uid } from './utils'; import { uid } from './utils';
import { palette } from './colors'; import { palette } from './colors';
@ -193,6 +194,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
this.metricContainer = clipContatiner this.metricContainer = clipContatiner
.append('g') .append('g')
.attr('class', 'metrics-rect'); .attr('class', 'metrics-rect');
this.options.callbackComponentRenderEnd(RenderComponent.METRICS_CONTAINER);
} }
protected createSvg(): void { protected createSvg(): void {
@ -209,6 +211,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
protected renderGrid(): void { protected renderGrid(): void {
this.grid.render(); this.grid.render();
this.options.callbackComponentRenderEnd(RenderComponent.GRID);
} }
protected renderAxes(): void { protected renderAxes(): void {
@ -216,6 +219,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
this.renderXAxis(); this.renderXAxis();
this.renderYAxis(); this.renderYAxis();
this.renderY1Axis(); this.renderY1Axis();
this.options.callbackComponentRenderEnd(RenderComponent.AXES);
} }
protected renderXAxis(): void { protected renderXAxis(): void {
@ -316,6 +320,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
.attr('x2', this.width) .attr('x2', this.width)
.style('pointer-events', 'none'); .style('pointer-events', 'none');
} }
this.options.callbackComponentRenderEnd(RenderComponent.CROSSHAIR);
} }
protected addEvents(): void { protected addEvents(): void {
@ -363,6 +368,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
.attr('cursor', 'crosshair') .attr('cursor', 'crosshair')
.attr('fill', 'none'); .attr('fill', 'none');
} }
this.options.callbackComponentRenderEnd(RenderComponent.OVERLAY);
} }
protected initBrush(): void { protected initBrush(): void {
@ -449,6 +455,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
.attr('height', this.height) .attr('height', this.height)
.attr('x', 0) .attr('x', 0)
.attr('y', 0); .attr('y', 0);
this.options.callbackComponentRenderEnd(RenderComponent.CLIP_PATH);
} }
protected renderLegend(): void { protected renderLegend(): void {
@ -487,6 +494,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
.text(series[idx].target) .text(series[idx].target)
.on('click', () => this.options.callbackLegendLabelClick(idx)); .on('click', () => this.options.callbackLegendLabelClick(idx));
} }
this.options.callbackComponentRenderEnd(RenderComponent.LEGEND);
} }
protected renderYLabel(): void { protected renderYLabel(): void {
@ -904,7 +912,7 @@ export {
ChartwerkPod, VueChartwerkPodMixin, ChartwerkPod, VueChartwerkPodMixin,
PodState, CoreSeries, CoreOptions, CORE_SERIE_DEFAULTS, CORE_DEFAULT_OPTIONS, PodState, CoreSeries, CoreOptions, CORE_SERIE_DEFAULTS, CORE_DEFAULT_OPTIONS,
Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation, Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation,
AxesOptions, AxisOption, AxesOptions, AxisOption, RenderComponent,
AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent,
palette palette
}; };

8
src/models/options.ts

@ -4,7 +4,7 @@ import {
CrosshairOptions, CrosshairOrientation, CrosshairOptions, CrosshairOrientation,
ZoomEvents, MouseZoomEvent, MousePanEvent, DoubleClickEvent, ScrollZoomEvent, ScrollPanEvent, ZoomEvents, MouseZoomEvent, MousePanEvent, DoubleClickEvent, ScrollZoomEvent, ScrollPanEvent,
ScrollPanOrientation, ScrollPanDirection, PanOrientation, KeyEvent, BrushOrientation, ScrollPanOrientation, ScrollPanDirection, PanOrientation, KeyEvent, BrushOrientation,
Margin, TimeFormat, AxisRange, Margin, TimeFormat, AxisRange, RenderComponent,
} from '../types'; } from '../types';
import lodashDefaultsDeep from 'lodash/defaultsDeep'; import lodashDefaultsDeep from 'lodash/defaultsDeep';
@ -176,6 +176,12 @@ export class CoreOptions<O extends Options> {
} }
} }
callbackComponentRenderEnd(part: RenderComponent): void {
if(has(this._options.eventsCallbacks, 'componentRenderEnd')) {
this._options.eventsCallbacks.componentRenderEnd(part);
}
}
callbackLegendClick(idx: number): void { callbackLegendClick(idx: number): void {
if(has(this._options.eventsCallbacks, 'onLegendClick')) { if(has(this._options.eventsCallbacks, 'onLegendClick')) {
this._options.eventsCallbacks.onLegendClick(idx); this._options.eventsCallbacks.onLegendClick(idx);

11
src/types.ts

@ -29,6 +29,7 @@ export type Options = {
sharedCrosshairMove?: (event: any) => void, sharedCrosshairMove?: (event: any) => void,
renderStart?: () => void, renderStart?: () => void,
renderEnd?: () => void, renderEnd?: () => void,
componentRenderEnd?: (part: RenderComponent) => void,
}; };
axis?: AxesOptions; axis?: AxesOptions;
grid?: GridOptions; grid?: GridOptions;
@ -195,3 +196,13 @@ export type ScrollPanEvent = {
orientation?: ScrollPanOrientation; orientation?: ScrollPanOrientation;
direction?: ScrollPanDirection; direction?: ScrollPanDirection;
} }
export enum RenderComponent {
CLIP_PATH = 'clipPath',
OVERLAY = 'overlay',
AXES = 'axes',
GRID = 'grid',
CROSSHAIR = 'crosshair',
METRICS_CONTAINER = 'metricsContainer',
LEGEND = 'legend',
}
Loading…
Cancel
Save