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
Add donut chart pattern #200
Conversation
I think a lot of those commits can/should be squashed. A commit should be a change, if it takes you several commits to get it right but they are all the same thing then condense them. It keeps the change atomic. |
Okay. I've squashed the commits and following comments in #180 only included the donut chart pattern for this PR. |
Ideally, these components should be separate PRs -- it's a bit much to review at once. If there are two components, they should have their own examples. Tabs can be used to show variations of that example. Please include a link to a working example. A screenshot is also very helpful. I can download and build your code, but others (designers) will need to review. There are instructions in the contribution guide for how to setup Travis to generate an example for you. |
I'd like to setup Travis to generate an example for me. The contribution guide states: You will also need to add an AUTH_TOKEN variable to Travis generated in your GitHub account to allow Travis to connect to your fork. Do you have more detailed instructions on how to accomplish this? My Travis build fails as it's not authorized to push to my repository. In the meantime I've attached a link to a screenshot of the donut example page: |
@jiekang |
@sahil143 Thank you! |
A demo via rawgit is available at: http://rawgit.com/jiekang/patternfly-ng/donut-chart-dist/dist-demo/#/ The donut chart is routed at: http://rawgit.com/jiekang/patternfly-ng/donut-chart-dist/dist-demo/#/donut |
Does the donut chart provide the ability to add horizontal and vertical labels like the Angular PatternFly example? |
@dlabrecq For context, the code is as close to a 1 to 1 transform of
In general, there should be no functional difference between the I see a labelConfig in the donut-pct API [3]. Is that what you are referring to? It is not available in the donut chart. |
Ah, yes users can add a legend. In general, users can add c3 configuration in the same manner as before (which is how the legend is added in the angularjs example). @dlabrecq Would you like me to modify the angular example to include exactly the two that you showed? |
Yes, please do. Need to ensure the examples can demonstrate feature parity with APF. |
@dlabrecq Okay, done. Looks like the rawgit has automatically updated and the result can be viewed there. |
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.
Please update the example to show tooltips like Angular PatternFly.
src/app/chart/donut/donut-config.ts
Outdated
/** | ||
* An optional function to customize the text of the center label | ||
*/ | ||
centerLabelFn?: any; |
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.
In general, we want to stay away from callback functions. Instead, this can be a simple centerLabel property.
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.
Changed to centerLabel
property.
/** | ||
* An optional function to handle when donut is clicked | ||
*/ | ||
onClickFn?: any; |
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.
Instead of a callback function, we would like to have an onClick event in the component.
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.
This onClickFn mirrors angular-patternfly
and would be an API difference between angular-patternfly
and patternfly-ng
if changed, is that okay? My approach was to keep things one to one such that anyone deciding to port from one to the other would not have to make any config changes due to incompatibilities. However I realize angularjs
and angular
are completely different projects so this might not be a concern for this project.
I don't understand what an "onClick event in the component" means, could you elaborate?
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.
Yes, it's ok to be different from APF. This is our opportunity to clean things up.
Instead of calling a function when the donut is clicked, we emit an event. A developer can easily subscript to the event like so:
<pfng-donut-chart (onClick)="myFunction($event)"...
Then, in the component we would have something like this:
/**
* The event emitted when an item has been clicked
*/
@output('onClick') onClick = new EventEmitter();
And some method to handle the click:
handleClick($event: MouseEvent): void {
this.onClick.emit({
item: item
} as ListEvent);
}
src/app/chart/donut/donut-config.ts
Outdated
/** | ||
* C3 inherited configuration for colors | ||
*/ | ||
colors?: any; |
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.
It's not clear what "colors" is. Please add an example to the comments? For example:
'colors' : {
'Cats': '#0088ce', // blue
'Hamsters': '#3f9c35', // green
'Fish': '#ec7a08', // orange
'Dogs': '#cc0000' // red
}
I wonder if a typed object may help here?
colors?: Color;
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.
I've updated the comment with an example. I'm reluctant to add a typed object for c3 inherited configuration as it mimics c3 configuration exactly. Maybe a link to the c3 API that it's intended to match would work for all c3 inherited configuration?
@@ -0,0 +1 @@ | |||
<div #chartElement id="{{donutChartId}}"></div> |
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.
We will need to create the pf-empty-chart for the no data available use case. This is an integral part of the component HTML layout in Angular Patternfly. It should be a very simple component -- please let me know if you need help with that?
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.
I presume this is another issue and PR? I can take a look at porting this. I suppose it's:
https://github.com/patternfly/angular-patternfly/blob/master/src/charts/empty-chart.component.js
https://github.com/patternfly/angular-patternfly/blob/master/src/charts/empty-chart.html
it('should setup onclick correctly', () => { | ||
expect(typeof(comp.config.data.onclick)).toBe('function'); | ||
}); | ||
}); |
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.
These tests are a great start.
In addition to these tests, I would like to see a couple tests ported from donut-pct.spec.js. For example, anything that tests the label would be very useful here. The donut-pct tests seem to share a lot in common with donut.
src/demo/app-routing.module.ts
Outdated
@@ -20,6 +20,7 @@ import { SearchHighlightExampleComponent } | |||
import { SortExampleComponent } from '../app/sort/examples/sort-example.component'; | |||
import { SortArrayExampleComponent } from '../app/pipe/sort-array/examples/sort-array-example.component'; | |||
import { SparklineExampleComponent } from '../app/chart/sparkline/examples/sparkline-example.component'; | |||
import { DonutExampleComponent } from '../app/chart/donut/examples/donut-example.component'; |
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.
Alphabetical order please
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.
Done.
Thoughts on adding ordered-imports
and the like to enforce tslinting of alphabetical order as a separate issue/PR? Also I noticed tslint
was updated from 4.x to 5.x and the tslint config file contains unsupported configuration for member-ordering
. It doesn't seem to break anything but I think a fix would be good for those using editors that read from the config file to show tslint warnings.
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.
Yes, it would be good to fix this. A separate PR would probably be best.
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.
The member-ordering seems to be working; for example, if I add a private method before a public one. Although, it's possible that config could be deprecated?
Unfortunately, none of that enforces import ordering, just fields, methods, and constructors. However, I did find adding this does the trick:
"ordered-imports": true,
src/demo/app-routing.module.ts
Outdated
@@ -85,6 +86,9 @@ const routes: Routes = [{ | |||
}, { | |||
path: 'sparkline', | |||
component: SparklineExampleComponent | |||
}, { | |||
path: 'donut', |
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.
Alphabetical order please
src/demo/app.component.html
Outdated
@@ -37,6 +37,9 @@ <h3>Components</h3> | |||
<li> | |||
<a routerLink="/sparkline" routerLinkActive="active">Sparkline</a> | |||
</li> | |||
<li> | |||
<a routerLink="/donut" routerLinkActive="active">Donut</a> |
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.
Alphabetical order please
src/demo/app.module.ts
Outdated
@@ -55,6 +56,7 @@ import { NavigationExampleModule } from '../app/navigation/examples/navigation-e | |||
SortArrayExampleModule, | |||
SortExampleModule, | |||
SparklineExampleModule, | |||
DonutExampleModule, |
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.
Alphabetical order please
src/demo/app.module.ts
Outdated
@@ -27,6 +27,7 @@ import { SearchHighlightExampleModule } from '../app/pipe/search-highlight/examp | |||
import { SortArrayExampleModule } from '../app/pipe/sort-array/examples/sort-array-example.module'; | |||
import { SortExampleModule } from '../app/sort/examples/sort-example.module'; | |||
import { SparklineExampleModule } from '../app/chart/sparkline/examples/sparkline-example.module'; | |||
import { DonutExampleModule } from '../app/chart/donut/examples/donut-example.module'; |
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.
Alphabetical order please
… and config updates
…t config comments
Observable | ||
.timer(0, 5000) | ||
.map(() => Math.floor(Math.random() * 100) + 100) | ||
.subscribe(val => this.config2.chartHeight = val); |
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.
This is very cool, but can we add this as a separate example? For example, have a "Basic" and "Dynamic" tabs similar to other component examples.
Sometimes my tooltip disappears as I'm attempting to hover and the data changes under me.
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.
As an example, we could have examples named donut-basic-example.component.ts and donut-dynamic-example.component.ts...
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.
LGTM
This adds the donut chart pattern addressing one half of issue #180
The patterns closely follow the angularJS versions:
http://www.patternfly.org/angular-patternfly/#/api/patternfly.charts.component:pfDonutChart
Notable differences:
chartHeight
are moved under the config as for exampleconfig.chartHeight
orconfig.centerLabel
A demo via rawgit is available via:
http://rawgit.com/jiekang/patternfly-ng/donut-chart-dist/dist-demo/#/donut
Thoughts?