Contributor How To Guides
Our contributor how to guides are recipes to address specific use cases when working with Britecharts. They assume contributor knowledge about Britecharts and the library structure. If this is the first time you contribute to Britecharts, we recommend you to read the Contributing Guide first.
How to Create a Pull Request
When you have a branch that you want to contribute back to Britecharts, you need to create a Pull Request(PR) to propose the addition of the code. Follow these steps:
- When you're finished coding,
git checkout master
- Run
git pull upstream master
(note that your local master should always reflect upstream master) - Run
git checkout <your branch>
- Execute
git rebase master
& reconcile all conflicts - Make sure everything looks OK codewise by running
yarn run check
- Push the branch to your fork with
git push origin <your branch>
- Create a new PR, filling the PR template, and adding a link to the original issue filed (if you see "unable to merge", please pull from your upstream and rebase again)
- Be patient while you wait for the maintainers to check it :)
If you are new to Open Source, you can learn how to create Pull Requests here.
How to Modify a Chart in @britecharts/core
This how-to guide helps you in modifying a chart. We assume you already created an issue and got the green light form the maintainers of the project (or maybe you are working your fork if you are not contributing back to Britecharts).
We have created our charts with a Test-First approach, and we encourage you to keep it the same. However, you can also write tests later too. For a TDD workflow, the process of modifying a component would look like this:
- Create a new branch for your modification
- On a new terminal, run
yarn run demos
in the root folder and navigate to the chart's demo in storybook - Find the test of the chart you want to modify in
/packages/core/src/charts/<chartName>
with at.spec.js
extension - Write a failing test for the API accessor or the feature you want to add
- On a new terminal, run
yarn run test
from the root folder - Check that the test fails
- Write the code that would make that test pass on the chart located in
/packages/core/src/charts/<chartName>
. Please follow our API Guidelines. - Make the test pass by writing the less amount of code
- Refactor until you get a nice and clean code
- Add/update the JSDoc comments so that the proper documentation gets generated when you run
yarn run docs
- Check the storybook demo to see the code in action (you can also add a new demo there if necessary)
- Create a pull request and ask the maintainers to review it
- Once you have their OK, they will merge your pull request
How to Create a New Chart in @britecharts/core
Adding a new chart is a bunch of work, but we hope that using the current code and documentation helps you in the process. The steps are:
- Create a new branch for your component
- On a new terminal, run
yarn run demos
to see the storybook running. - Given that your new chart is
chart-name
, create a folder within/packages/core/src/charts
namedchart-name
and in the same folder a new test filechart-name.spec.js
. - Create a new data builder file. Name it something like
chartNameChartDataBuilder.js
. - In the chart folder, create a new chart file called
chart-name.js
. - Create a
<chartName>.stories.js
file to hold a new demo for the new chart. Re-run the demos script to get it showing in the storybook. - Go to
webpack.config.js
and add the new chart to theCHARTS
object, give it a camel case name. - Go to your test file
/packages/core/src/charts/chart-name.spec.js
and, taking another test as an example, copy over pieces until you have the first test case. - Add one test and make it fail by calling
yarn run test
or keep the tests running withyarn run test:watch
. - Keep on coding according to our API Guidelines
- Once you think you are close to having something working, start adding JSDoc comments to your code
- Generate your docs with
yarn run docs
and manually test the API definition in the docs site. - Create a pull request with your branch and ping one of the core maintainers to get it reviewed
- Once you have addressed all the comments and got the green light, the maintainers will merge the PR