Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbar #791

Merged
merged 31 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ebc79e2
feat: create toolbar components
hlyang397 Sep 1, 2020
e611cbf
refactor: use constants in configuration
hlyang397 Sep 2, 2020
4febc82
feat: create toolbar storybook demo group
hlyang397 Sep 3, 2020
fc89ba2
refactor: toolbar button
hlyang397 Sep 4, 2020
3294ec2
feat: disable toolbar button if it won't work
hlyang397 Sep 4, 2020
ac8c1f7
fix: title should use parent node to get max title width
hlyang397 Sep 8, 2020
a3ed332
feat: provide minZoomRatio option
hlyang397 Sep 8, 2020
65ade54
Merge branch 'master' into create-toolbar
Sep 10, 2020
b5e355f
Merge branch 'master' into create-toolbar
hlyang397 Sep 14, 2020
9014561
feat allow overflow menu item to be disabled
hlyang397 Sep 14, 2020
4080fb6
Merge branch 'master' into create-toolbar
hlyang397 Sep 21, 2020
840c452
feat: combine toolbar icon and overflow menu item to controls
hlyang397 Sep 21, 2020
71f66f1
Merge branch 'master' into create-toolbar
hlyang397 Sep 22, 2020
1ca8e64
Merge branch 'master' into create-toolbar
hlyang397 Sep 24, 2020
fe574fd
fix: not import src/ in demo folder to avoid build failure
hlyang397 Sep 24, 2020
081a301
feat: support keyboard event for toolbar button
hlyang397 Sep 29, 2020
56b3c20
refactor: fix scss style
hlyang397 Oct 5, 2020
f6a4a59
refactor: change configuration name
hlyang397 Oct 5, 2020
ad3c9b0
refactor: remove default ToolbarControls in configuration
hlyang397 Oct 5, 2020
f18b3a9
Merge branch 'master' of github.com:carbon-design-system/carbon-chart…
hlyang397 Oct 5, 2020
bf47a52
feat: allow to use keyboard to control overflow menu
hlyang397 Oct 5, 2020
c21edba
Merge branch 'master' into create-toolbar
hlyang397 Oct 6, 2020
4e3be68
fix: align toolbar to title component
hlyang397 Oct 6, 2020
4ca109d
Merge branch 'master' into create-toolbar
hlyang397 Oct 12, 2020
4c136d2
refactor: refactor statements and fix typos
hlyang397 Oct 14, 2020
1c7e6ca
refactor: change ToolbarControl.text field to optional
hlyang397 Oct 14, 2020
bcee77b
refactor: use getControlConfigByType() to reduce methods count
hlyang397 Oct 15, 2020
d9ccac3
Merge branch 'master' into create-toolbar
hlyang397 Oct 27, 2020
ffb41bc
refactor: minor changes per comments
hlyang397 Oct 27, 2020
0f1889d
refactor: remove toolbar control text in demo
hlyang397 Oct 27, 2020
70f7497
refactor: use d3.select to replace document.getElementById
hlyang397 Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/core/demo/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as stepDemos from "./step";
import * as meterDemos from "./meter";
import * as timeSeriesAxisDemos from "./time-series-axis";
import * as radarDemos from "./radar";
import * as toolbarDemos from "./toolbar";
import * as zoomBarDemos from "./zoom-bar";

export * from "./area";
Expand Down Expand Up @@ -762,6 +763,23 @@ let allDemoGroups = [
}
]
},
{
title: "Toolbar (alpha)",
demos: [
{
options: toolbarDemos.toolbarStackedBarTimeSeriesOptions,
data: toolbarDemos.toolbarStackedBarTimeSeriesData,
chartType: chartTypes.StackedBarChart,
isDemoExample: false
},
{
options: toolbarDemos.toolbarLineTimeSeriesOptions,
data: toolbarDemos.toolbarLineTimeSeriesData,
chartType: chartTypes.LineChart,
isDemoExample: false
}
]
},
{
title: "Zoom bar (alpha)",
demos: [
Expand Down
48 changes: 48 additions & 0 deletions packages/core/demo/data/toolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as areaChart from "./area";
import * as barChart from "./bar";
import * as lineChart from "./line";
import * as pieChart from "./pie";

// utility function to update title and enable toolbar option
const addToolbarOptions = (
options,
configs: any = { enableZoomBar: false, enableResetZoom: false }
) => {
options.experimental = true;

let titlePostfix = " - enable Toolbar";
options.toolbar = {
enabled: true
};
if (configs.enableZoomBar) {
titlePostfix += ", Zoom bar";
options.zoomBar = {
top: {
enabled: true
}
};
}
if (configs.enableResetZoom) {
titlePostfix += ", Reset Zoom";
options.toolbar.overflowMenuItems = {
resetZoom: {
enabled: true
}
};
}
options.title += titlePostfix;
return options;
};

export const toolbarStackedBarTimeSeriesData =
barChart.stackedBarTimeSeriesData;
export const toolbarStackedBarTimeSeriesOptions = addToolbarOptions(
Object.assign({}, barChart.stackedBarTimeSeriesOptions),
{ enableZoomBar: true }
);

export const toolbarLineTimeSeriesData = lineChart.lineTimeSeriesData;
export const toolbarLineTimeSeriesOptions = addToolbarOptions(
Object.assign({}, lineChart.lineTimeSeriesOptions),
{ enableZoomBar: true, enableResetZoom: true }
);
52 changes: 48 additions & 4 deletions packages/core/src/axis-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Title,
AxisChartsTooltip,
Spacer,
Toolbar,
ZoomBar
} from "./components";
import { Tools } from "./tools";
Expand All @@ -41,6 +42,11 @@ export class AxisChart extends Chart {
"top",
"enabled"
);
const toolbarEnabled = Tools.getProperty(
this.model.getOptions(),
"toolbar",
"enabled"
);

this.services.cartesianScales.findDomainAndRangeAxes(); // need to do this before getMainXAxisPosition()
const mainXAxisPosition = this.services.cartesianScales.getMainXAxisPosition();
Expand All @@ -56,9 +62,41 @@ export class AxisChart extends Chart {
mainXAxisPosition === AxisPositions.BOTTOM &&
mainXScaleType === ScaleTypes.TIME;

const titleAvailable = !!this.model.getOptions().title;
const titleComponent = {
id: "title",
components: [new Title(this.model, this.services)],
growth: {
x: LayoutGrowth.STRETCH,
y: LayoutGrowth.FIXED
}
};

const toolbarComponent = {
id: "toolbar",
components: [new Toolbar(this.model, this.services)],
growth: {
x: LayoutGrowth.PREFERRED,
y: LayoutGrowth.FIXED
}
};

const headerComponent = {
id: "header",
components: [
new LayoutComponent(
this.model,
this.services,
[
// always add title to keep layout correct
titleComponent,
...(toolbarEnabled ? [toolbarComponent] : [])
],
{
direction: LayoutDirection.ROW
}
)
],
growth: {
x: LayoutGrowth.PREFERRED,
y: LayoutGrowth.FIXED
Expand Down Expand Up @@ -160,14 +198,20 @@ export class AxisChart extends Chart {
}
};

// Add chart title if it exists
const topLevelLayoutComponents = [];
if (this.model.getOptions().title) {
topLevelLayoutComponents.push(titleComponent);
// header component is required for either title or toolbar
if (titleAvailable || toolbarEnabled) {
topLevelLayoutComponents.push(headerComponent);

const titleSpacerComponent = {
id: "spacer",
components: [new Spacer(this.model, this.services)],
components: [
new Spacer(
this.model,
this.services,
toolbarEnabled ? { size: 10 } : undefined
)
],
growth: {
x: LayoutGrowth.PREFERRED,
y: LayoutGrowth.FIXED
Expand Down
Loading