Commit Graph

316 Commits

Author SHA1 Message Date
Simon Brunel
bd60fa2dfd Correctly handle decimal display size (#4009)
Fix the `readUsedSize` regular expression to correctly parse (truncate) pixel decimal values.
2017-03-18 11:54:56 +01:00
Simon Brunel
4b421a50bf Add support to fill between datasets (#4008)
The `fill` option now accepts the index of the target dataset (number) or a string starting by "+" or "-" followed by a number representing the dataset index relative to the current one (e.g. `fill: "-2"` on dataset at index 3 will fill to dataset at index 1). It's also possible to "propagate" the filling to the target of an hidden dataset (`options.plugins.filler.propagate`). Fill boundaries `zero`, `top` and `bottom` have been deprecated and replaced by `origin`, `start` and `end`.

Implementation has been moved out of the line element into a new plugin (`src/plugins/plugin.filler.js`) and does not rely anymore on the deprecated model `scaleTop`, `scaleBottom` and `scaleZero` values. Drawing Bézier splines has been refactored in the canvas helpers (note that `Chart.helpers.canvas` is now an alias of `Chart.canvasHelpers`).

Add 3 new examples and extend utils with a pseudo-random number generator that can be initialized with `srand`. That makes possible to design examples starting always with the same initial data.
2017-03-18 11:08:57 +01:00
Simon Brunel
1ca0ffb5d5 Introduce unit test based on image comparison (#3988)
Attempt to make easier the creation of unit tests that check the drawing output. Until now, this was done by checking calls on a 'fake' context, which is hard to maintain (need to update pixel values by hands) and also not reliable when optimizing code (i.e. different calls sequence but same result).

As of now, it's possible to define 'auto' tests based on JSON/PNG fixtures: chart is generated from the JSON file and compared to the associated PNG image. The image diff is done using `pixelmatch`. As an example (and in preparation of the `filler` plugin), add auto tests for the line element `fill` options.
2017-03-05 09:49:12 -07:00
Simon Brunel
c216c0af76 Cleanup and upgrade unit tests environment
`karma.conf.ci.js` has been merged into `karma.conf.js` for local testing consistency: `gulp unittestWatch` has been replaced by `gulp unittest --watch` and thus use exactly the same config file. Upgrade to latest jasmine and karma packages and remove deprecated `gulp-karma` dependency (directly use `karma.Server` in gulp).

Split `test/mockContext.js` into smaller `test/jasmine.*` modules to make easier unit tests maintenance and finally, move all `*.test.js` files under the `test/specs` folder.
2017-03-04 11:39:48 -05:00
Evert Timberg
a3b8fb266a Split radial scale lineArc setting into a combination of existing and new settings.
gridLines.circular is a new option that toggles circular lines. This allows radar charts with circular lines #3082
pointLabels.display is a new option that toggles the display of point labels.
The existing angleLines.display is used with the new pointLabels.display setting is used to trigger the radar like settings.
This required changing the default polar area config.
2017-03-03 06:50:34 -05:00
Simon Brunel
b92b256872 Flatten animation object and fix callbacks
Animation callbacks now receives `animationObject` directly with a reference on the associated chart (`animation.chart`), which deprecates `animation.animationObject` and `animation.chartInstance`. Also fix missing `onComplete` animation argument and make sure that an animation object is passed even when animations are disabled.
2017-03-03 06:49:47 -05:00
Simon Brunel
d25e7b1e1a Handle incoming model values on element transition
If a value is set on the model after `pivot()` has been called, the view wasn't initialized and the animation started from 0. Now, `_start` and incomplete `_view` are initialized to the model value during the transition (no initial implicit transition).

Also remove exception handling when animating a string (color), which is faster when string are not valid colors (e.g. tooltip position). It requires to update `chartjs-color` to version 2.1.0.
2017-03-03 06:49:32 -05:00
etimberg
b50eac366d Add test for layout service weight ordering 2017-02-25 12:10:27 -05:00
Simon Brunel
4741c6f09d Add new dataset update and draw plugin hooks
In order to take full advantage of the new plugin hooks called before and after a dataset is drawn, all drawing operations must happen on stable meta data, so make sure that transitions are performed before.
2017-02-21 20:28:16 -05:00
Simon Brunel
cc90c5c643 Add chart data property setter and unit tests
Chart data can now be entirely replaced using `chart.data = {...}` thanks to the new property setter (instead of using `chart.config.data = {}`). Also update the documentation, as suggested by @ldaguise and @kennethkalmer, with a note about versions prior 2.6.
2017-02-18 11:53:39 -05:00
potatopeelings
85ee592b2a #3849 - Stack bars in z dimension 2017-02-16 17:58:18 -05:00
etimberg
8dafbc02c0 when axes are in the wrong place, update the config position 2017-02-12 11:23:17 -05:00
Evert Timberg
fed42e218a When the dataset label is not defined, the tooltip label string should not include a ':' character. Added a test to cover this case. 2017-02-10 19:30:52 -05:00
Jerry
8f217182b8 Update tooltip only when active element has changed (#3856)
Resolves #3746
2017-02-10 18:51:37 -05:00
Thomas Redston
9f3b51a80c Reuse parsed results rather than redoing work
The input labels/data is converted into moments in `determineDataLimits`, reuse them instead of duplicating the work.
2017-02-10 18:49:35 -05:00
Jerry Chang
074ab2aa87 Fixed HorizontalBar: stacked axis, displays NaN when all legends
unselected (#3770)

added ability to take snapshot of chart limits in order to be used
when max and min value is not finite

added ignore files
2017-02-10 18:40:37 -05:00
Simon Brunel
ba6e041713 Unit tests for Chart constructor and deprecations 2017-02-10 18:37:56 -05:00
Simon Brunel
28ea6c4967 Rename chartInstance to chart 2017-02-10 18:37:56 -05:00
Simon Brunel
13c6121876 Remove deprecated nested chart accesses 2017-02-10 18:37:56 -05:00
Simon Brunel
7205ff5e2a Replace onEvent by before/afterEvent 2017-01-27 19:32:35 -05:00
Simon Brunel
979341ecb0 Plugin hooks and jsdoc enhancements
Make all `before` hooks cancellable (except `beforeInit`), meaning that if any plugin return explicitly `false`, the current action is not performed. Ensure that `init` hooks are called before `update` hooks and add associated calling order unit tests. Deprecate `Chart.PluginBase` in favor of `IPlugin` (no more an inheritable class) and document plugin hooks (also rename `extension` by `hook`).
2017-01-27 19:32:35 -05:00
Simon Brunel
312773ba7b Platform event API abstraction
Move base platform definition and logic in src/platform/platform.js and simplify the browser -> Chart.js event mapping by listing only different naming then fallback to the native type.

Replace `createEvent` by `add/removeEventListener` methods which dispatch Chart.js IEvent objects instead of native events. Move `add/removeResizeListener` implementation into the DOM platform which is now accessible via `platform.add/removeEventListener(chart, 'resize', listener)`.

Finally, remove `bindEvent` and `unbindEvent` from the helpers since the implementation is specific to the chart controller (and should be private).
2017-01-15 14:25:38 -05:00
Evert Timberg
9e9b9cf46d when the cutoutPercentage is 0, the inner radius should be 0 2017-01-15 12:46:01 -05:00
potatopeelings
eebaa84e72 Group stacked bar charts (#2643) (#3563)
Group stacked bar charts (#2643)
2017-01-01 09:36:01 -05:00
Evert Timberg
ecc35c527b Refactoring to put browser specific code in a new class (#3718)
Refactoring to put browser specific code in a new class, BrowserPlatform.
BrowserPlatform implements IPlatform. Chart.Platform is the constructor for the platform object that is attached to the chart instance.

Plugins are notified about the event using the `onEvent` call. The legend plugin was converted to use onEvent instead of the older private `handleEvent` method.
Wrote test to check that plugins are notified about events
2016-12-21 10:22:05 -05:00
SAiTO TOSHiKi
5387c48bd8 Fix bar draw issue with borderWidth. (#3680)
Fix bar draw issue.
1. `Chart.elements.Rectangle.draw` function supports both horizontal and vertical bar.
2. Corrected bar position at minus.
3. Adjust bar size when `borderWidth` is set.
4. Adjust bar size when `borderSkipped` is set.
5. Adjust `borderWidth` with value near 0(base).
6. Update test.
2016-12-20 09:01:07 -05:00
etimberg
7756bedec6 fix stacked bars on logarithmic axes 2016-12-18 09:11:58 -05:00
Simon Brunel
3187a788e1 Add support for local plugins and plugin options
Plugins can now be declared in the chart `config.plugins` array and will only be applied to the associated chart(s), after the globally registered plugins. Plugin specific options are now scoped under the `config.options.plugins` options. Hooks now receive the chart instance as first argument and the plugin options as last argument.
2016-12-18 08:46:15 -05:00
Evert Timberg
18f77db362 fix linting again 2016-12-16 22:24:12 -05:00
Evert Timberg
00d3c5a282 fix linting 2016-12-16 22:20:18 -05:00
Tarqwyn
34d26ea497 Fix bug when calculating if steps fit into scale as a whole number then smal floating point errors make the consition pass false 2016-12-13 21:22:02 -05:00
etimberg
6f40d04964 Fix infinite loop in logarithmic tick generation 2016-12-07 18:47:30 -05:00
Toshiki Saito
bdcdbc2abf Fixed miscalculation of Bar width.
for Bar and horizontalBar type,
include stacked scale.
issue #3589
2016-12-02 07:57:59 -05:00
Evert Timberg
3ff58e5065 Revert "Fixed tooltip labelling on Bar Chart when min is defined (#3618)" 2016-12-01 07:58:39 -05:00
Jerry Chang
b6807b2dd9 fixed tooltip labelling on Bar Chart when min is defined
added helper method to adjust the index

pass in chartConfig rather than access within method, make it easier to
test

added semi-colon at the end of helper method

added test for adjustIndex helper method

fixed lint issues

added integration test for the interaction of trigger an event over the
bar

.

.

moved adjustIndex into element helper

removed method from helper and adjusted method in core.interaction

added test for the element adjustIndex helper

added a skipIndexAdjustment method to handle when to skip the adjustment
along with test cases

fixed lint issues

removed the test for the helper method
2016-11-28 18:29:56 -05:00
etimberg
7a8f20e88f Fix monotone cubic interpolation when two adjacent points are at the exact same x pixel value 2016-11-28 18:28:06 -05:00
Christopher Moeller
97f6c8f12d Add rectRounded point style 2016-11-26 12:58:49 -05:00
etimberg
2e5df0ff42 Allow updating the config of a chart at runtime 2016-11-25 07:19:59 -05:00
Evert Timberg
7e5e29e3ee Improve radial scale (#3625)
Clean up radial linear scale. It now supports multiple lines for point labels. Fixes #3225
2016-11-25 07:19:43 -05:00
etimberg
58afbe428c Properly use the ticks.padding option. To correctly fix the issue, the default padding was changed from 0 to 10. This change caused all of the test changes since the width of a vertical scale was lowered by 10px 2016-11-20 11:52:08 -05:00
Jerry Chang
4fbb1bdbbc Fixed Issue with tooltip label display when given null data value (#3528)
When datasets.data contains a null value, the label displays incorrect
value.

code additions:
- unit tests for truthy label values (when data is null)
- checks to ensure handling of null value in getLabelByIndex method

added mock data sets from issue #3528 example

expect the return value from getLabelForIndex method to be valid (truthy)

added check for null of first data value in getLabelForIndex

fixed indentation and null comparison operator in code

fixed mistake in definition of firstData variable

changed testing for data on index 0 to using index variable

changed firstData to use value instead

condense the statments to use value variable
2016-11-19 09:29:15 -05:00
etimberg
48cb8b78e7 Remove unnecessary padding usages and update category scale tests 2016-11-18 17:58:07 -05:00
Evert Timberg
5dd1c77cf5 Take vertical padding into account 2016-11-18 17:58:07 -05:00
Evert Timberg
eaf109c2b1 When an axis needs padding due to a long, rotated, label it should be added inside the layout system rather than in each axis. 2016-11-18 17:58:07 -05:00
etimberg
f7d60c2606 Allow line chart to use pointBorderWidth of 0 correctly 2016-11-17 21:05:47 -05:00
etimberg
339265d21e use correct option for setting tension on radar charts 2016-11-14 07:27:01 -05:00
etimberg
3f2d7efc70 Add a function to filter items out of the legend 2016-11-12 18:48:25 -05:00
Simon Brunel
6b449a9e7c Fix retina scale when display size is implicit
The retinaScale helper now enforces the display size to the correct values because if no style has been set on the canvas, the render size is used as display size, making the chart bigger (or smaller) when deviceAspectRatio is different of 1.
2016-11-11 18:10:19 -05:00
Simon Brunel
efced4780c Fix context state restoration on destroy
In many cases, the canvas render size is changed by the lib, causing the state stack to be discarded, meaning that we can't use save() and restore() to release the context with its initial state (i.e. before creating the chart). Since we don't need (want) to manually save / restore the context initial state, simply make sure to reset it to the default state to give a fresh context back to the user. That also means we don't need to revert the scale when the pixel device ratio is not 1.
2016-11-07 19:16:45 -05:00
etimberg
74d4dbc608 X and Y interaction modes now use the intersect option 2016-11-05 08:19:07 -04:00