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 26 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 @@ -768,6 +769,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
70 changes: 70 additions & 0 deletions packages/core/demo/data/toolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as barChart from "./bar";
import * as lineChart from "./line";

// utility function to enable toolbar option
const addToolbarOptions = (options, configs?) => {
options.experimental = true;

options.toolbar = {
enabled: true
};
options.zoomBar = {
top: {
enabled: true
}
};
options.toolbar.controls = [
{
type: "Zoom in",
text: "Zoom in"
},
{
type: "Zoom out",
text: "Zoom out"
},
{
type: "Reset zoom",
text: "Reset zoom"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to provide the text field every time? are they not defaulted to the correct term?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, text field is not required and it's defaulted to type.
This is to demo how to change the toolbar control text.
The other story shows that it also works without text field.
Let me know if you like to remove the text field in demo data as well.
Update interface in 1c7e6ca.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'd better to just include a small tutorial story for the toolbar and describe this there. I wouldn't want the text in the demo code, that'll result in users copying that code over to their projects, and it'll show up in codesandbox

}
];

if (configs) {
if (configs.titlePostfix) {
hlyang397 marked this conversation as resolved.
Show resolved Hide resolved
options.title += configs.titlePostfix;
}
if (configs.numberOfIcons) {
options.toolbar.numberOfIcons = configs.numberOfIcons;
}
if (configs.controls) {
options.toolbar.controls = configs.controls;
}
}

return options;
};

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

export const toolbarLineTimeSeriesData = lineChart.lineTimeSeriesData;
export const toolbarLineTimeSeriesOptions = addToolbarOptions(
Object.assign({}, lineChart.lineTimeSeriesOptions),
{
titlePostfix: " - two icons",
numberOfIcons: 2,
controls: [
{
type: "Reset zoom"
},
{
type: "Zoom in"
},
{
type: "Zoom out"
}
]
}
);
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: 15 } : undefined
)
],
growth: {
x: LayoutGrowth.PREFERRED,
y: LayoutGrowth.FIXED
Expand Down
Loading