-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Scale rewrite for v2.0 #1132
Merged
Merged
Scale rewrite for v2.0 #1132
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tration. An initial implementation of a linear scale that can be drawn in both horizontal and vertical orientations.
… from the other charts. For now, the config is not changeable.
…f labels to show and as such do not need to rotate
…iguration has a different line colour for the 0 axis
…ng the canvas fully.
…d merges smarter than simply replacing the default object. Tested by overriding the vertical axis 0 point colour. Also implemented dataset axis binding. If nothing is specified, the dataset is bound to the first x and y axis.
…he axes. This is useful when in a multi axis scenario so that the axis that does not draw grid lines does not have weird lines.
…tting the scales. Since each chart needed to know it's scales, there wasn't much point in registering them into the service. When we support overlapping charts, we can do something fancier
Conflicts: src/Chart.Core.js Fixed the sample files & chart type initialize methods so that this.data does not get set to undefined.
…ultiple y axes. Added an example demonstrating this.
…scales since that was clearer and maintains backwards compatibility.
…hich will allow radialLogarithmic, etc in the future. Updated the polar area and radar charts to use the new scale config. The scales draw, but the points do not. This is no different than the current v2.0 branch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This update splits the scale code into separate x and y scales for the line, bar and scatter chart types. The line and bar charts use a "dataset" axis as their only x axis. The scatter chart allows arbitrary numbers of x and y axes.
I created a scale registration system. So far the following scale types are available: "linear", "dataset", and "radialLinear". The last axis type is used by the polar area and radar charts. The hope is that extensions can now provide axis types alone rather than new chart types as well. This means that it will be easier to expand
Chart.js
to use logarithmic axes.I've also update the configuration to a more nested state with respect to the scales. More work is necessary to update the global defaults as well. I wrote a config merge function that can better handle nested data.
Sample Config
Scale Constructor Registration
Extensions should register scale types in the following way.
To use a new scale type, change the scale configuration as follows. The scatter chart will look up the corresponding constructor when building the scales.
Linear Axis
The linear axis limit calculation has been redone to follow the nice number algorithm. http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
The scale config allows the user to provide a callback function that will determine the label for a given tick mark. The user provides this function as
Zero Point Drawing
As can be seen in the scatter chart images below, the linear axis allows different draw settings for the line that represents the 0 points.
Resize Behaviour
During resizing, the linear chart will dynamically scale the number of ticks rather than rotating text.
Scatter Chart
The scatter chart uses a linear axis by default along the bottom. This axis may be moved to the top of the chart area by changing the position to "top" in the configuration. The data for a scatter chart is an object with two parameters
x
andy
.Single Y Axis
Multiple Y Axes
Bar Charts
Bar charts also support multiple y axes. In this example, the red and dark blue traces are bound to the left axis while the cyan trace is bound to the right axis.
Line Charts
Line charts also support multiple y axes.
Issues fixed
This PR should fix the following issues though testing is required and there may be bugs.