Skip to content

Commit

Permalink
feat: add ZoomBarOptions.initZoomDomain
Browse files Browse the repository at this point in the history
- update storybook
- add init() and destroy() in ZoomBar
  • Loading branch information
hlyang397 committed Jun 19, 2020
1 parent e09064e commit 456001b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
5 changes: 5 additions & 0 deletions packages/core/demo/data/time-series-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ const selectionEndFun = (selection, domain) => {
console.log(domain);
};

const initZoomDomain = [
new Date(2020, 11, 10, 23, 59, 25),
new Date(2020, 11, 11, 0, 0, 25)
];
export const lineTimeSeriesZoomBarOptions = {
title: "Line (time series) - zoom-bar enabled",
axes: {
Expand All @@ -463,6 +467,7 @@ export const lineTimeSeriesZoomBarOptions = {
},
zoomBar: {
enabled: true,
initZoomDomain: initZoomDomain,
selectionStart: selectionStartFun,
selectionInProgress: selectionInProgressFun,
selectionEnd: selectionEndFun
Expand Down
25 changes: 21 additions & 4 deletions packages/core/src/components/axes/zoom-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export class ZoomBar extends Component {

brush = brushX();

init() {
// get initZoomDomain
const zoomBarOptions = this.model.getOptions().zoomBar;
if (zoomBarOptions.initZoomDomain !== undefined) {
this.model.set(
{ zoomDomain: zoomBarOptions.initZoomDomain },
{ skipUpdate: true }
);
}
}

render(animate = true) {
const svg = this.getContainerSVG();
const { cartesianScales } = this.services;
Expand Down Expand Up @@ -221,6 +232,7 @@ export class ZoomBar extends Component {
const brushArea = DOMUtils.appendOrSelect(svg, "g.brush").call(
this.brush
);

if (
zoomDomain === undefined ||
zoomDomain[0].valueOf() === zoomDomain[1].valueOf()
Expand All @@ -239,10 +251,11 @@ export class ZoomBar extends Component {
}
}

zoomIn() {
const mainXScale = this.services.cartesianScales.getMainXScale();
console.log("zoom in", mainXScale.domain());
}
// could be used by Toolbar
// zoomIn() {
// const mainXScale = this.services.cartesianScales.getMainXScale();
// console.log("zoom in", mainXScale.domain());
// }

// brush event listener
brushed(zoomDomain, scale, selection) {
Expand Down Expand Up @@ -337,4 +350,8 @@ export class ZoomBar extends Component {
.attr("width", handleBarWidth)
.attr("height", handleBarHeight);
}

destroy() {
this.brush.on("start brush end", null); // remove event listener
}
}
12 changes: 6 additions & 6 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const timeScale: TimeScaleOptions = {
*/
export const zoomBar: ZoomBarOptions = {
enabled: false,
initZoomDomain: undefined,
selectionStart: undefined,
selectionInProgress: undefined,
selectionEnd: undefined
Expand Down Expand Up @@ -236,8 +237,8 @@ const lineChart: LineChartOptions = Tools.merge({}, axisChart, {
*/
const areaChart: AreaChartOptions = Tools.merge({}, lineChart, {
timeScale: Tools.merge(timeScale, {
addSpaceOnEdges: 0,
} as TimeScaleOptions),
addSpaceOnEdges: 0
} as TimeScaleOptions)
} as LineChartOptions);

/**
Expand Down Expand Up @@ -380,8 +381,8 @@ export const lines = {
export const area = {
opacity: {
unselected: 0,
selected: 0.4,
},
selected: 0.4
}
};

/**
Expand All @@ -391,8 +392,7 @@ export const areas = {
opacity: {
unselected: 0.3,
selected: 1
},

}
};

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/interfaces/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ export interface ZoomBarOptions {
* is the zoom-bar visible or not
*/
enabled?: boolean;

/**
* an two element array which represents the initial zoom domain
*/
initZoomDomain?: Object[];

/**
* a function to handle selection start event
*/
Expand Down

0 comments on commit 456001b

Please sign in to comment.