-
Notifications
You must be signed in to change notification settings - Fork 184
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
feat(scatter): Add Scatter to the Angular package and storybook #301
Merged
theiliad
merged 3 commits into
carbon-design-system:master
from
stanislavgeorgiev:master
Jul 10, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ | |
"email": "iliadm@ca.ibm.com" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
Component, | ||
AfterViewInit | ||
} from "@angular/core"; | ||
|
||
import { BaseChart } from "./base-chart.component"; | ||
|
||
import { ScatterChart } from "@carbon/charts"; | ||
|
||
/** | ||
* Wrapper around `ScatterChart` in carbon charts library | ||
* | ||
* Most functions just call their equivalent from the chart library. | ||
*/ | ||
@Component({ | ||
selector: "n-scatter-chart", | ||
template: ` | ||
<div #nChart class='n-chart-container'> | ||
</div> | ||
` | ||
}) | ||
export class ScatterChartComponent extends BaseChart implements AfterViewInit { | ||
/** | ||
* Runs after view init to create a chart, attach it to `chartRef` and draw it. | ||
*/ | ||
ngAfterViewInit() { | ||
this.chart = new ScatterChart( | ||
this.chartRef.nativeElement, | ||
{ | ||
data: this.data, | ||
options: this.options | ||
} | ||
); | ||
|
||
Object.assign(this, this.chart); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { storiesOf } from "@storybook/angular"; | ||
|
||
import { colors } from "./helpers/commons"; | ||
|
||
import { ChartsModule } from "../src/charts.module"; | ||
import { ScatterComponent } from "./scatter/scatter.component"; | ||
|
||
import { scatterData, lineOptions } from "./../../core/demo/demo-data/line"; | ||
|
||
const scatterStories = storiesOf("Scatter", module); | ||
scatterStories.add("Basic", () => ({ | ||
component: ScatterComponent, | ||
moduleMetadata: { | ||
imports: [ChartsModule] | ||
}, | ||
props: { | ||
scatterData: scatterData, | ||
scatterOptions: lineOptions | ||
} | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div style="margin: 30px;"> | ||
<n-scatter-chart | ||
class="n-chart" | ||
[data]="scatterData" | ||
[options]="scatterOptions" | ||
style="height: 500px;" | ||
#scatterChart> | ||
</n-scatter-chart> | ||
|
||
<button class="btn--primary" (click)="changeDemoData()">Change Data</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Component, ViewChild } from "@angular/core"; | ||
|
||
import { colors, randomizeValue } from "../helpers/commons"; | ||
import { Input } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "app-scatter", | ||
templateUrl: "./scatter.component.html" | ||
}) | ||
export class ScatterComponent { | ||
@ViewChild("scatterChart") scatterChart; | ||
|
||
@Input() scatterOptions = {}; | ||
@Input() scatterData = {}; | ||
|
||
changeDemoData() { | ||
const oldData = this.scatterChart.data; | ||
|
||
// Randomize old data values | ||
const newData = Object.assign({}, oldData); | ||
newData.datasets = oldData.datasets.map(dataset => { | ||
const datasetNewData = dataset.data.map(dataPoint => randomizeValue(dataPoint, false)); | ||
|
||
const newDataset = Object.assign({}, dataset, { data: datasetNewData }); | ||
|
||
return newDataset; | ||
}); | ||
|
||
this.scatterData = newData; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally never caught this ... we'll want to switch the prefix to either
ibm-
(to match carbon-angular) orc-
(for carbon) ... the easiest way going forwards will be"ibm-scatter-chart, n-scatter-chart"
(or whatever prefix) until we hit v1.Doesn't stop this PR, but just something we should sort out sooner rather than later.