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

feat(bar): add non zero based bar chart #2438

Closed
wants to merge 14 commits into from

Conversation

ajaxlab
Copy link
Contributor

@ajaxlab ajaxlab commented Nov 29, 2021

Issue

Resolves #2408 Non zerobased bar chart

Details

General

  • This PR support a range value for bar chart.
  • The range value consists of two numbers of array..
  • For a dataset with single numbers it draws as it was.
  • If start value is greater than end value it will throw an error.
  • Tests, docs, apis and demo added.

For stack bar chart

If a chart has a range value then it draws absolute position (not stacked)

Test cases

Basic

{
  data: {
    columns: [
      ["data1",  -100, 100, [100, 200], [200, 300]]
    ],
    type: "bar"
  }
}

image

Reversed range

{
  data: {
    columns: [
      ["data1",  -100, 100, [200, 100], [300, 200]]
    ],
    type: "bar"
  }
}

Throws an error

Multiple

{
  data: {
    columns: [
      ["data1", [100, 200], [200, 300]],
      ["data2", [-100, 100], [-50, -30]],
    ],
    type: "bar"
  }
}

image

With single numbers

{
  data: {
    columns: [
      ["data1", 100, 200, [100, 200], [200, 300]],
      ["data2", -100, -50, [-100, 100], [-50, -30]],
    ],
    type: "bar"
  }
}

image

With a groups option

{
  data: {
    columns: [
      ["data1", 200, [100, 200], [200, 300]],
      ["data2", -50, [-100, 50], [-50, -30]],
    ],
    type: "bar",
    groups: [["data1", "data2"]],
  }
}

image

Demo

image

image

@coveralls
Copy link

coveralls commented Nov 29, 2021

Coverage Status

Coverage increased (+0.02%) to 90.086% when pulling 2714dc1 on ajaxlab:feature-2408-nonzero-based-bar into ff3cf99 on naver:master.

Copy link
Member

@netil netil left a comment

Choose a reason for hiding this comment

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

Please, checkout the mIssing part to complete:

@@ -204,6 +204,8 @@ export default {
value = $$.getRatio("index", d, true);
} else if ($$.isBubbleZType(d)) {
value = $$.getBubbleZData(d.value, "y");
} else if (isRange(value)) {
Copy link
Member

Choose a reason for hiding this comment

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

isRange is too broad, because [n, n] ranged array value used only in bar type. In this condition, when data is given with [n, n] format, but not being "bar" type will meet the condition.

So, rather than "isRange()", determining ranged bar type value should work only for bar type like .isBubbleZTtype().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@netil

How about naming .isBarRangeType(d) ?
like

isAreaRangeType(d): boolean {
return this.isTypeOf(d, TYPE_BY_CATEGORY.AreaRange);
},

@@ -63,6 +65,8 @@ const isValue = (v: any): boolean => v || v === 0;
const isFunction = (v: any): boolean => typeof v === "function";
const isString = (v: any): boolean => typeof v === "string";
const isNumber = (v: any): boolean => typeof v === "number";
const isNumberArray = (arr: any): boolean => isArray(arr) && arr.every(v => isNumber(v));
const isRange = (arr: any): boolean => isNumberArray(arr) && arr.length === 2;
Copy link
Member

Choose a reason for hiding this comment

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

util.ts is the collection for general purposes. Ranged array data is only used for bar type, so for now including this in a global utility file might not necessary.

Copy link
Contributor Author

@ajaxlab ajaxlab Nov 29, 2021

Choose a reason for hiding this comment

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

@netil
Okay I'll move the code to a bar related place.

// TODO We could extract this if block
// as defaultRangeValueFormat like thing.
if (isRange(v)) {
return `${Math.min(...v)} ~ ${Math.max(...v)}`;
Copy link
Member

Choose a reason for hiding this comment

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

The data format for ranged bar data, should be following as [start, end]. There's no need to get min/max value. To get reason for this, it should be able treat data values as [end, start] case, which isn't proper data format that will be accepted.

// is enough return as:
return v.join(" ~ ")

Copy link
Contributor Author

@ajaxlab ajaxlab Nov 29, 2021

Choose a reason for hiding this comment

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

@netil
Okay I got it, so you mean the following code should not render any thing right?

{
  data: {
    columns: [
      ["data1",  [200, 100], [300, 200]]
    ],
    type: "bar"
  }
}

Then I have another question, the above code should throw an error or just does't render quietly?

Copy link
Member

Choose a reason for hiding this comment

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

IMO, it should throw error to let user know issue explicitly. Currently there's no general error handling, which should be added in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I'll make it throw an error :)

netil added a commit to netil/billboard.js that referenced this pull request Nov 30, 2021
netil added a commit to netil/billboard.js that referenced this pull request Nov 30, 2021
@netil netil closed this in ff3cf99 Nov 30, 2021
@netil netil reopened this Nov 30, 2021
@ajaxlab ajaxlab force-pushed the feature-2408-nonzero-based-bar branch from 85146cb to 2714dc1 Compare December 3, 2021 02:47
@ajaxlab
Copy link
Contributor Author

ajaxlab commented Dec 3, 2021

@netil
I've updated this PR as your review comments. 😃

@netil netil closed this in 3588abe Dec 3, 2021
github-actions bot pushed a commit that referenced this pull request Dec 17, 2021
# [3.3.0-next.1](3.2.2...3.3.0-next.1) (2021-12-17)

### Bug Fixes

* **text:** Fix text position with candlestick type combination ([f84ab3e](f84ab3e)), closes [#2436](#2436)
* **tooltip:** fix candlestick tooltip display with xs option ([0278067](0278067)), closes [#2434](#2434)

### Features

* **bar:** add non zero based bar chart ([3588abe](3588abe)), closes [#2408](#2408) [#2438](#2438)
* **bar:** Implement stacking bar radius ([8f14d1a](8f14d1a)), closes [#2428](#2428)
* **module:** Support dual CJS/ESM package ([437c007](437c007)), closes [#2202](#2202)
* **option:** Enhance padding to be removed completely ([2052a19](2052a19)), closes [#2367](#2367)
* **plugin:** Intent to ship TableView plugin ([215b611](215b611)), closes [#1873](#1873)
github-actions bot pushed a commit that referenced this pull request Jan 14, 2022
# [3.3.0](3.2.2...3.3.0) (2022-01-14)

### Bug Fixes

* **api:** Ensure svg nodes to be removed from memory  ([f49ed83](f49ed83)), closes [#2489](#2489)
* **event:** fix touch event handling on arc ([d3d2e05](d3d2e05)), closes [#2477](#2477)
* **text:** Fix text position with candlestick type combination ([f84ab3e](f84ab3e)), closes [#2436](#2436)
* **tooltip:** fix candlestick tooltip display with xs option ([0278067](0278067)), closes [#2434](#2434)
* **types:** Fix axis types definition ([92fb033](92fb033)), closes [#2499](#2499)
* **types:** Fix plugin's type definition ([f3690f9](f3690f9)), closes [#2483](#2483)

### Features

* **axis:** alow user to hide tick lines while using culling ([aad8c45](aad8c45)), closes [#2478](#2478) [#2480](#2480)
* **bar:** add non zero based bar chart ([3588abe](3588abe)), closes [#2408](#2408) [#2438](#2438)
* **bar:** Implement stacking bar radius ([8f14d1a](8f14d1a)), closes [#2428](#2428)
* **bar:** Intent to ship bar.indices.removeNull ([b16605d](b16605d)), closes [#1687](#1687)
* **option:** Enhance padding to be removed completely ([2052a19](2052a19)), closes [#2367](#2367)
RenuRai added a commit to RenuRai/react-billboardjs3 that referenced this pull request Sep 12, 2022
feat(bar): add non zero based bar chart: naver/billboard.js#2438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non zerobased bar chart
3 participants