E529 feat(Chart): Add Patternfly Chart componenet by yaacov · Pull Request #103 · patternfly/patternfly-react · GitHub
[go: up one dir, main page]

Skip to content

feat(Chart): Add Patternfly Chart componenet#103

Merged
priley86 merged 3 commits intopatternfly:masterfrom
yaacov:feat-line-chart
Dec 13, 2017
Merged

feat(Chart): Add Patternfly Chart componenet#103
priley86 merged 3 commits intopatternfly:masterfrom
yaacov:feat-line-chart

Conversation

@yaacov
Copy link
Contributor
@yaacov yaacov commented Dec 8, 2017

What:
Add a chart component.

Why:
We currently use line charts to display data using angular [1], we want the option to render the same charts using react.

How:
This implementation is copy-paste react component of the Patternfly example here [2].

Storybook:
https://yaacov.github.io/patternfly-react/?knob-Label=Danger%20Will%20Robinson%21&selectedKind=Chart&selectedStory=Basic%20Example&full=0&down=1&left=1&panelRight=0&downPanel=storybooks%2Fstorybook-addon-knobs

[1] https://github.com/patternfly/angular-patternfly/tree/master/src/charts/line
[2] http://www.patternfly.org/pattern-library/data-visualization/line-chart/#/code

@ohadlevy
Copy link
Member
ohadlevy commented Dec 8, 2017

Thanks @yaacov :) happy to see you here

@yaacov
Copy link
Contributor Author
yaacov commented Dec 8, 2017

@ohadlevy Thanks :-) where are you ?

@yaacov
Copy link
Contributor Author
yaacov commented Dec 8, 2017

cc @nimrodshn

@yaacov yaacov force-pushed the feat-line-chart branch 7 times, most recently from b29aa03 to e5f759f Compare December 9, 2017 00:06
@yaacov
Copy link
Contributor Author
yaacov commented Dec 9, 2017

@ohadlevy who can review this ?

@yaacov yaacov force-pushed the feat-line-chart branch 2 times, most recently from bed0c26 to c55c6da Compare December 9, 2017 09:22
@sharvit
Copy link
Contributor
sharvit commented Dec 10, 2017

Thanks @yaacov !

As we spoke, I think you can upgrade the LineChart component to be only Chart because the type property will allow configuring which type of chart to render.

@priley86 shared this library with me and with @nimrodshn:
https://github.com/bcbcarl/react-c3js

After reviewing it, I think you can just use this library with the addition of the className.

@yaacov
Copy link
Contributor Author
yaacov commented Dec 10, 2017

@sharvit @priley86 nice !

Now it's only a wrapper for react-c3js , 2 lines 😄

p.s.
@sharvit also s/LineChar/Chart/g

@yaacov yaacov changed the title feat(LineChart): Add Patternfly lineChart componenet feat(Chart): Add Patternfly Chart componenet Dec 10, 2017
Copy link
Contributor
@sharvit sharvit left a comment

Choose a reason for hiding this comment

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

@yaacov, Thanks for updating and adding the stories so fast!

Added a small comment about the Chart.js

import React from 'react';
import C3Chart from 'react-c3js';

const Chart = props => <C3Chart {...props} className="line-chart-pf" />;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Shouldn't the line-chart-pf be only existed for line chart?
    I guess each chart has its own class but haven't really checked it.
  2. It should be possible to add more classes when using the component. (e.g. <Chart data={data} className="my-chart-class" />)
    I would suggest something like:
import React from 'react';
import C3Chart from 'react-c3js';
import ClassNames from 'classnames';

const Chart = ({ className, ...props }) => {
  className = ClassNames(className, {
    'line-chart-pf': props.type === 'line'
  });

  return <C3Chart {...props} className={className} />;
};

export default Chart;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🍻 👍

@yaacov yaacov force-pushed the feat-line-chart branch 2 times, most recently from bc4bd0b to a23686d Compare December 10, 2017 12:47
@priley86
Copy link
Member
priley86 commented Dec 10, 2017

@yaacov @sharvit this is a great start..

We also have Bar, Donut:
https://rawgit.com/patternfly/patternfly/master-dist/dist/tests/

I would try to match those as close as possible... We also have a lot of default settings here:
https://github.com/patternfly/patternfly/blob/master/src/js/patternfly-settings-charts.js

Those get used like this for example:
https://github.com/patternfly/patternfly/blob/master/tests/pages/_includes/widgets/charts/donut-whole-relationship.html

I think we can expose those as default objects/functions and allow consumer to use them by default or override them... we should show this in the storybook stories I am guessing..

Utilization Bar is not using c3... so I think we can ignore that one in this PR.

I will try to check in and help review this some more tomorrow...

cc: @jeff-phillips-18 what else on the charts?

import ClassNames from 'classnames';

const Chart = ({ ...props }) => {
const chartType = props.data.type || 'line';
Copy link
Member
@priley86 priley86 Dec 10, 2017

Choose a reason for hiding this comment

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

I would almost rather throw new Error(`Unsupported type=${type}`); but that is just personal preference. When consuming downstream, if I don't see the type specified some place I will get confused...

@yaacov
Copy link
Contributor Author
yaacov commented Dec 10, 2017

@priley86 @sharvit thanks for the reviews,

We also have Bar, Donut:

👍 added to the story.

We also have a lot of default settings here:

I do not know how to consume patternfly-settings-charts.js functions [1] , any idea how to do that ?
Or should we just copy paste some useful defaults into patternfly-react ?

[1] https://github.com/patternfly/patternfly/blob/master/src/js/patternfly-settings-charts.js

@priley86
Copy link
Member
priley86 commented Dec 10, 2017

My preference is to avoid consuming PF jquery in this project if possible (as we have not done that up to this point), but will let @jeff-phillips-18 weigh in on this. I think this is a good question to consider at this point as I see a few good options to sharing these sort of things:

  1. Re-export those default objects/functions here in PF React.
    • 👍 We can write ES6
    • 👎 Angular PatternFly / Patternfly Ng projects would not see them
  2. Create a new shared es6 library that just exposes common es6 constants (colors/chart defaults/etc.) as es6 modules. Maybe call it "patternfly-constants" and expose it on NPM...
    • 👍 We can write es6 and can also be consumed by Angular PF/Patternfly Ng
    • 👎 We have to maintain another library / npm
  3. Consume the current PF jquery into PF React
    • 👍 It exists already and can be shared
    • 👎 It's jquery and my watch says the year is 2017 😢
  4. Do nothing and let consumer figure it out for now.
    • 👍 Avoids jquery in this repo
    • 👎 Tougher on consumer

I think there is some clarification needed first...

@yaacov
Copy link
Contributor Author
yaacov commented Dec 10, 2017

@priley86 👍 Thanks

@priley86
Copy link
Member
priley86 commented Dec 10, 2017

@yaacov @jeff-phillips-18 I did a bit more homework just now... ;)

It looks like patternfly-ng is consuming globals in patternfly-settings.js. Consuming from a global (on the window) is not really the es6 standard way of doing this, but it gets the job done 😆
https://github.com/patternfly/patternfly/blob/master-dist/dist/js/patternfly-settings.js
https://github.com/patternfly/patternfly-ng/blob/master/src/vendor.ts#L19

I think this is a decent alternative - we should be able to add this import into config.js

@jeff-phillips-18 does this work for you?

const pfSetDonutChartTitle = patternfly.pfSetDonutChartTitle;

const addDonutTitle = lifecycle({
componentDidMount() {
Copy link
Member

Choose a reason for hiding this comment

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

two comments:

  1. should this be only on mount, maybe on update as well?
  2. maybe it make sense to test the props before calling the pf function (as i assume it would be faster not to call it if its not needed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Thanks.

Set also the 'componentDidUpdate' method.
Testing for change is a little tricky and may take the same time as re draw ... need to think how to do that ...

@waldenraines
Copy link

/cc @lizagilman

@yaacov
Copy link
Contributor Author
yaacov commented Dec 13, 2017

@ohadlevy @priley86 @sharvit Hi, all

a. Bar Chart auto generate tooltips from categories.
b. Donut Chart now auto generate the central title.

gifrecord_2017-12-13_192654

@yaacov yaacov force-pushed the feat-line-chart branch 2 times, most recently from ea0ae9d to a3a9625 Compare December 13, 2017 17:39
}

// Set Bar Chart tooltip
console.log(name, props);
Copy link
Member
@priley86 priley86 Dec 13, 2017

Choose a reason for hiding this comment

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

do we need it? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh ... fixed thanks :-)

@priley86
Copy link
Member

this looks beautiful to me @yaacov 🎨

great job iterating so fast on this.

*/

const donutConfigData = {
columns: [['MHz Used', 60], ['MHz Available', 40]],
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be rendering "60% Mhz" in the title... and I think it should be "60 Mhz".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed :-)

p.s.
Patternfly is very opinionated about that :-)
https://github.com/patternfly/patternfly/blob/master/src/js/patternfly-settings-charts.js#L24

@priley86
Copy link
Member

@yaacov I don't see any other issue at this point. Terrific job...

@jeff-phillips-18 @jgiardino what else?

@ohadlevy
Copy link
Member
ohadlevy commented Dec 13, 2017 via email

@jgiardino
Copy link
Contributor

These are great!

The only thing I notice is that there is a bounce effect in the legend of the pie chart, and there isn't one on the donut.

But when I check patternfly, I see some inconsistency there. For example, the pie chart test page includes the bounce effect, but the code sample on patternfly.org does not.

@mcarrano @LHinson Do you know if we have any details on what's expected here?

@yaacov Do you know where this setting gets enabled?

I don't see this as something that should block merging this PR, though. We can capture it and revisit it later.

Copy link
Contributor
@jgiardino jgiardino left a comment

Choose a reason for hiding this comment

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

Other than wanting to know where the bounce animation in the legend is coming from, these look good to me.

@yaacov
Copy link
Contributor Author
yaacov commented Dec 13, 2017

@jgiardino hi,

The only thing I notice is that there is a bounce effect in the legend of the pie chart, and there isn't one on the donut.

This is what I have on fedora27 default filrefox, it looks the same to me, what am I missing ?

peek 2017-12-13 21-38
peek 2017-12-13 21-39

@jgiardino
Copy link
Contributor

I don't see the effect in Firefox either. After poking around, I don't think it's an intentional effect. When I disable the following style, it doesn't happen:

.c3-legend-item-tile, .c3-xgrid-focus, .c3-ygrid, .c3-event-rect, .c3-bars path {
    shape-rendering: crispEdges;
}

So it looks like this is just a side effect of having crisp edges and altering the opacity, which isn't something we have control over.

@priley86
Copy link
Member

cool! great job @yaacov! great job React team ;)

@priley86 priley86 merged commit e2cc2b5 into patternfly:master Dec 13, 2017
@sharvit
Copy link
Contributor
sharvit commented Dec 14, 2017

Nice!! I love those changes!
Thank you @yaacov 👍

HarikrishnanBalagopal pushed a commit to HarikrishnanBalagopal/patternfly-react that referenced this pull request Sep 29, 2021
use localhost i
9D76
nstead of 0.0.0.0 for host so app opens correctly on windows
use enzyme-adapter-react-17 to ensure jest test works
remove stub async module support
prevent url from changing when selecting SkipToContent component
update readme screenshot preview
patch storybook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0