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

Autorotate x axis tick texts on types "category" and "timeseries" #1236

Closed
michkami opened this issue Feb 7, 2020 · 6 comments
Closed

Autorotate x axis tick texts on types "category" and "timeseries" #1236

michkami opened this issue Feb 7, 2020 · 6 comments

Comments

@michkami
Copy link
Collaborator

michkami commented Feb 7, 2020

Description

I would like to have an option for autorotating x axis tick texts on type "category" if there isn't enough space to fit them between 2 ticks.
Main reason for autorotating x axis tick texts is saving unused space in the chart.

It should autorotate if:

  1. axis_x_tick_multiline === false
  2. axis_x_tick_autorotate === true
  3. axis_x_tick_rotate !== 0
  4. longest text width > space between 2 ticks
  5. Check 1-4 on resize/redraw

It also improves the appereance of the x axis if:

  • the texts are too long and there is less space between 2 ticks or
  • there are many elements on x axis

Examples:

  1. There is enough space so the texts aren't rotated:
    1  not rotated

  2. There is not enough space so the texts are rotated:
    2  rotated

  3. There is not enough space for 1 text so all texts are rotated:
    3  rotated long prefix

  4. There are many elements on x axis:
    4  many elements

Would this feature be useful enough to implement it in billboard or perhaps as a plugin?
If needed, this feature could be expanded and implemented for other axis types in the future.

What do you think about it?

@netil
Copy link
Member

netil commented Feb 10, 2020

Hi @michkami, thanks for the suggestion and looks very nice to be implemented.

The basic determination for weather a feature will be added as plugin or integrated option are:

  • The code size

    If the added code size is minimal, then no issue to be added to the core

  • The general functionality & frequency of the usage

    Even code size is minimal, but the functionality is not something used very frequently for every user, considering as separate plugin is more reasonable in this case.

@netil netil added the feature label Feb 12, 2020
@michkami michkami reopened this Feb 14, 2020
@michkami
Copy link
Collaborator Author

michkami commented Feb 14, 2020

I worked on this issue in the last few days.
As the code changes are not minimal and autorotating could be used frequently, I implemented it in the core.

  1. X axis tick texts can now be rotated automatically if "axis_x_tick_autorotate = true". (only for type category)
  2. If the rotation is set 0 < and < 90 there is a new function for calculating y2 axis overflow length of rotated x axis tick texts. (only for type category)

autorotate without y2 axis shown
autorotateWithoutY2

autorotate with y2 axis shown
autorotateWithY2

  1. Following is not the part of the issue, but it were just 3 lines of code:

resizeXAxisWithY2
It resizes the x axis height if you hide all elements in the chart, which looks better instead of displaying empty space.
This change also works for all three x axis types.

Autorotating works only if:

  • axis_x_tick_multiline is set false
  • axis_x_tick_culling is set false (because some issues with calculating the y2 axis overflow when texts are hidden)
  • axis_x_type is set category

Y2 axis overflow will be calculated if:

  • axis_x_tick_multiline is set false
  • axis_x_tick_culling is set false
  • axis_x_type is set category
  • axis_x_tick_rotate is set 0 < value < 90

If you are ok with this changes, I can make a pull request for all of them.
If there is something to clarify beforehand, we can do it before or within the pull request.

PS: As of some internet problems during writing this comment, I somehow closed and reopened the post, don't ask me how :D

@netil
Copy link
Member

netil commented Feb 17, 2020

@michkami, looks great!

No issue, except the constraint of axis_x_type is set category. It'll be useful if is applicable for timeseries type also.

Timestamp strings is usually is too wide, so adjusting this automatically would be great.

image

@michkami
Copy link
Collaborator Author

Is there any special use for this condition @netil ?

Axis.js 246:9

if (fit || (count && fit)) {
    values = this.generateTickValues(
        $$.mapTargetsToUniqueXs(targets),
        count,
        $$.isTimeSeries()
    );
}

Is it correct that when axis_x_tick_fit is set to false that axis_x_tick_count is ignored?
Shouldn't it be if (fit || count) or is it supposed to work same as if (fit) and then the if expression is just over complicated without a point?

@michkami michkami changed the title Autorotate x axis tick texts on type "category" Autorotate x axis tick texts on types "category" and "timeseries" Feb 20, 2020
@netil netil closed this as completed in 8c51d02 Mar 10, 2020
netil pushed a commit that referenced this issue Mar 11, 2020
# [1.12.0-next.5](1.12.0-next.4...1.12.0-next.5) (2020-03-11)

### Bug Fixes

* **axis:** Fix adding duplicated <title> element ([8d45075](8d45075)), closes [#1271](#1271)
* **axis:** Fix axis label text position ([68b6b86](68b6b86)), closes [#1270](#1270)
* **axis:** Fix axis tick rotate translate ([1bc3f20](1bc3f20)), closes [#1250](#1250) [#1278](#1278)
* **axis:** Fix for multi axes data bound  ([3f8afba](3f8afba)), closes [/github.com//pull/1233#issuecomment-595675546](https://github.com//github.com/naver/billboard.js/pull/1233/issues/issuecomment-595675546)
* **grid:** Fix focus grid to be maintained on resize  ([01ba388](01ba388)), closes [#1239](#1239)

### Features

* **axis:** Autorotate x axis tick texts on type "category" and "timeseries" ([8c51d02](8c51d02)), closes [#1236](#1236) [#1250](#1250)
netil pushed a commit that referenced this issue Mar 20, 2020
# [1.12.0](1.11.1...1.12.0) (2020-03-20)

### Bug Fixes

* **arc:** Fix handling spaced data name ([4824a47](4824a47)), closes [#1168](#1168)
* **arc:** Fix overwriting gauge_max in MultiArcGauge with totalSum ([8b2c28e](8b2c28e)), closes [#1259](#1259) [#1260](#1260)
* **axis:** Correct y Axis tick padding ([145b960](145b960)), closes [#1251](#1251)
* **axis:** Fix adding duplicated <title> element ([8d45075](8d45075)), closes [#1271](#1271)
* **axis:** Fix axis label text position ([68b6b86](68b6b86)), closes [#1270](#1270)
* **axis:** Fix axis tick rotate translate ([1bc3f20](1bc3f20)), closes [#1250](#1250) [#1278](#1278)
* **axis:** Fix for multi axes data bound  ([3f8afba](3f8afba)), closes [/github.com//pull/1233#issuecomment-595675546](https://github.com//github.com/naver/billboard.js/pull/1233/issues/issuecomment-595675546)
* **axis:** Fix text being left behind if getBBox fails ([648aa41](648aa41)), closes [#1283](#1283) [#1284](#1284)
* **bar:** Bar's width resize according the zoom scale ([93184a2](93184a2)), closes [#1185](#1185)
* **callbacks:** Fix triggering in lazy rendering ([3e73fdf](3e73fdf)), closes [#1254](#1254)
* **core:** Fix onrendered firing time ([8b8665c](8b8665c)), closes [#1194](#1194)
* **gauge:** fixed wrong ratio calculation in 'gauge.type = "single"' ([9020246](9020246)), closes [#1205](#1205)
* **grid:** Fix focus grid to be maintained on resize  ([01ba388](01ba388)), closes [#1239](#1239)
* **interaction:** Fix null data point interaction ([901da84](901da84)), closes [#1199](#1199)
* **line:** Fix nullish data rendering with regions ([d0ca937](d0ca937)), closes [#1172](#1172)
* **radar:** Correct text label not showing ([9109fd5](9109fd5)), closes [#1241](#1241)
* **tooltip:** Auto pos adjustion for tooltip ([c54f731](c54f731)), closes [#1243](#1243) [#1239](#1239)
* **tooltip:** Fix tooltip position on overlapping data point ([8dba213](8dba213)), closes [#1267](#1267)
* **tooltip:** Revert on pointer-events css prop ([c74c27a](c74c27a)), closes [#1124](#1124) [#1155](#1155)
* **tooltip,interaction:** Correct tooltip behaves for touch environment ([7090fa9](7090fa9)), closes [#1253](#1253)

### Features

* **axis:** Autorotate x axis tick texts on type "category" and "timeseries" ([8c51d02](8c51d02)), closes [#1236](#1236) [#1250](#1250)
* **axis:** Clone y/y2-axis domain if no data is bound to one of them ([96ac5c7](96ac5c7)), closes [#1231](#1231) [#1233](#1233)
* **axis:** Intent to ship axis.x.min/max.fit ([1650955](1650955)), closes [#7](#7)
* **axis:** Intent to ship axis.y2.tick.rotate ([98992f3](98992f3)), closes [#1157](#1157) [#1158](#1158)
* **axis:** Intent to ship y Axes stepSize ([429c6ec](429c6ec)), closes [#1098](#1098)
* **gauge:** more than one arc are possible for gauges ([7a80e02](7a80e02)), closes [#787](#787) [#1071](#1071) [#1163](#1163)
* **grid:** Intent to ship grid.focus.y ([13d65d1](13d65d1)), closes [#1154](#1154)
* **line:** Intent to ship bubble/line/scatter zerobased ([e45fb33](e45fb33)), closes [#1149](#1149) [#1150](#1150)
* **options:** Intent to ship Arc's expand.rate ([7d6f32f](7d6f32f)), closes [#1189](#1189)
* **plugin:** Intent to ship bubblecompare plugin ([49704e0](49704e0)), closes [#1153](#1153)
* **tooltip:** Enhancement on callback options ([30a7718](30a7718)), closes [#1216](#1216)
* **tooltip:** Intent to ship tooltip.position.unit ([ac078a7](ac078a7)), closes [#1239](#1239)
* **zoom:** Intent to ship zoom.reseteButton.onclick ([694cbcb](694cbcb)), closes [#1171](#1171)
@netil
Copy link
Member

netil commented Mar 20, 2020

🎉 This issue has been resolved in version 1.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@netil netil added the released label Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants