Skip to content

Commit

Permalink
feat(core): adding onDoubleClick to Chart
Browse files Browse the repository at this point in the history
New property to respond to double click events.
  • Loading branch information
markmcdowell committed Jul 9, 2020
1 parent 0b48e94 commit 1b6498b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
13 changes: 7 additions & 6 deletions packages/core/src/CanvasContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
interface CanvasContainerProps {
readonly height: number;
readonly ratio: number;
readonly style?: React.CSSProperties;
readonly width: number;
readonly zIndex?: number;
}
Expand All @@ -21,17 +22,17 @@ export class CanvasContainer extends React.PureComponent<CanvasContainerProps> {
}

public render() {
const { height, width, zIndex, ratio } = this.props;
const { height, ratio, style, width, zIndex } = this.props;

const adjustedWidth = width * ratio;
const adjustedHeight = height * ratio;
const style: React.CSSProperties = { position: "absolute", width, height };
const canvasStyle: React.CSSProperties = { position: "absolute", width, height };

return (
<div style={{ position: "absolute", zIndex }}>
<canvas ref={this.bgRef} width={adjustedWidth} height={adjustedHeight} style={style} />
<canvas ref={this.axesRef} width={adjustedWidth} height={adjustedHeight} style={style} />
<canvas ref={this.mouseRef} width={adjustedWidth} height={adjustedHeight} style={style} />
<div style={{ ...style, position: "absolute", zIndex }}>
<canvas ref={this.bgRef} width={adjustedWidth} height={adjustedHeight} style={canvasStyle} />
<canvas ref={this.axesRef} width={adjustedWidth} height={adjustedHeight} style={canvasStyle} />
<canvas ref={this.mouseRef} width={adjustedWidth} height={adjustedHeight} style={canvasStyle} />
</div>
);
}
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ChartProps {
readonly height?: number;
readonly id: number | string;
readonly onContextMenu?: (event: React.MouseEvent, props: unknown) => void;
readonly onDoubleClick?: (event: React.MouseEvent, props: unknown) => void;
readonly origin?: number[] | ((width: number, height: number) => number[]);
readonly padding?: number | { top: number; bottom: number };
readonly yExtents?: number[] | ((data: any) => number) | ((data: any) => number[]);
Expand Down Expand Up @@ -76,18 +77,27 @@ export class Chart extends PureComponent<ChartProps> {
}

private readonly listener = (type: string, moreProps, state, e) => {
const { id, onContextMenu } = this.props;
const { id, onContextMenu, onDoubleClick } = this.props;

switch (type) {
case "contextmenu": {
const { currentCharts } = moreProps;
if (currentCharts.indexOf(id) > -1) {
if (onContextMenu !== undefined) {
if (onContextMenu !== undefined) {
const { currentCharts } = moreProps;
if (currentCharts.indexOf(id) > -1) {
onContextMenu(e, moreProps);
}
}
break;
}
case "dblclick": {
if (onDoubleClick !== undefined) {
const { currentCharts } = moreProps;
if (currentCharts.indexOf(id) > -1) {
onDoubleClick(e, moreProps);
}
}
break;
}
}
};
}
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { ChartCanvas } from "./ChartCanvas";
export { Chart } from "./Chart";
export * from "./Chart";
export * from "./GenericChartComponent";
export * from "./GenericComponent";
export * from "./utils";
Expand Down

0 comments on commit 1b6498b

Please sign in to comment.