Commit Graph

367 Commits

Author SHA1 Message Date
Simon Brunel
f90ee8c786 Add support for detached canvas element (#4591)
Allow to create a chart on a canvas not yet attached to the DOM (detection based on CSS animations described in https://davidwalsh.name/detect-node-insertion). The resize element (IFRAME) is added only when the canvas receives a parent or when `style.display` changes from `none`. This change also allows to re-parent the canvas under a different node (the resizer element following). This is a preliminary work for the DIV based resizer.
2017-08-01 14:28:45 +02:00
Simon Brunel
97e2373721 Change ticks.mode to scale.distribution (#4582)
Fix `ticks.mode` behavior when `ticks.source` is `auto`: the lookup table is now built from the data and not from the ticks, so data (and ticks) are correctly distributed along the scale. Rename the option to `distribution` (more explicit than `mode`) and since this option applies from now on the data, it seems better to have it under `scale` instead `scale.ticks`.
2017-07-30 21:24:29 +02:00
Simon Brunel
53b7a6392f Change scale.ticks back to an array of strings (#4573)
Internal ticks are now stored as objects in the PRIVATE this._ticks member and must not be accessed directly from outside this class. this.ticks is around for a long time and hasn't been marked as private, so we can't change its structure without unexpected breaking changes. If you need to access the scale ticks, use scale.getTicks() instead.
2017-07-29 21:26:36 +02:00
Evert Timberg
326991ce50 index-y interaction mode + convert horizontal bar defaults to new mode (#4458)
index-y interaction mode + convert horizontal bar defaults to new mode
2017-07-28 18:07:28 -04:00
Simon Brunel
2cc242d5a3 New time scale ticks.source: 'data' option (#4568)
This new option value generates ticks from data (including labels from {t|x|y} data objects).
2017-07-27 06:41:09 +02:00
Simon Brunel
c6bda02468 Rewrite unit test waitForResize helper (#4566)
The original implementation tries to intercept events from the chart internal iframe, which ones failing on Chrome 60. Checking internals doesn't seem the best approach, instead we could consider that a chart has been resized after the resize method has been called and processed. So let's hook `Chart.resize` and callback once it's done.
2017-07-26 13:33:45 +02:00
Simon Brunel
3aa7a20923 New time scale ticks.bounds option (#4556)
`ticks.bounds` (`'data'`(default)|`'label'`): `data` preserves the data range while `labels` ensures that all labels are visible. This option is bypassed by the min/max time options.

Remove the useless time scale `_model` object containing private members: instead, make these members private (prefixed by `_`) part of the scale.
2017-07-25 10:12:53 +02:00
Simon Brunel
48d6face28 Move and rewrite time helpers (#4549)
Move time helpers back into time scale, remove the `Chart.helpers.time namespace` and attempt to make the auto generation logic a bit simpler. The generate method doesn't anymore enforce min/max, the calling code needs to clamp timestamps if needed.
2017-07-23 11:41:12 -04:00
andig
e7445a5f00 Honour time scale min/max settings (#4522) 2017-07-22 14:35:06 +02:00
Simon Brunel
4c763bff44 Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.

http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops
2017-07-22 14:13:09 +02:00
Ben McCann
f6b6956a3a Fix ESLint errors (#4485) 2017-07-22 09:19:06 +02:00
Ben McCann
48d76b20fe Allow specifying the time axis via t attribute (#4533)
For time series charts it may make more sense to specify the horizontal axis using the variable `t`. This change will make it much easier to use the time scale with the financial chart, which takes in the data points `{t, o, h, l, c}`.
2017-07-22 08:33:22 +02:00
Simon Brunel
7b6388883a Refactor padding parsing under helpers.options (#4544)
New Chart.helpers.options.toPadding helpers that converts a number or object into a padding {top, right, bottom, left, height, width} object.
2017-07-21 15:03:03 +02:00
Simon Brunel
090196c07c Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.

https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
2017-07-20 19:20:54 +02:00
Simon Brunel
5ad1b4ade7 New time scale ticks.mode/.source options (#4507)
`ticks.source` (`'auto'`(default)|`'labels'`): `auto` generates "optimal" ticks based on min, max and a few more options (current `time` implementation`). `labels` generates ticks from the user given `data.labels` values (two additional trailing and leading ticks can be added if min and max are provided).

`ticks.mode` (`'linear'`(default)|`series`): `series` displays ticks at the same distance from each other, whatever the time value they represent, while `linear` displays them linearly in time: the distance between each tick represent the amount of time between their time values.
2017-07-19 21:04:15 +02:00
andig
3bb31ca592 Allow category labels definition at scale level (#4506) 2017-07-19 12:41:17 +02:00
Suhaib Khan
b03ab1ca45 Fix labelOffset not working for vertical axes (#4249) 2017-07-15 10:19:16 +02:00
Simon Brunel
56050dc9b7 Move easing effects in separate file + unit tests 2017-07-08 12:02:33 -04:00
etimberg
7d60857819 Use proper reverse option in radial linear scale 2017-07-04 07:25:58 -04:00
Evert Timberg
cc9e88aebc Support an array for line chart pointBorderWidth 2017-07-04 07:24:37 -04:00
Simon Brunel
225bfd36f3 Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object.
2017-07-01 14:51:38 +02:00
Simon Brunel
ecca3373b2 Increase ESLint complexity and add config for tests (#4421)
Raise the cyclomatic complexity to 10 which seems to better match the project coding style and still reasonable (6 being quite low). Also move unit tests specific eslint rules in the cascaded `./test/.eslintrc` file (previously in `gulp.js`).
2017-07-01 09:55:11 +02:00
etimberg
ccb2898539 When all datasets are hidden, the linear scale defaults to a range of 0 - 1.
If `ticks.min` was set this would not set the range correctly.
Added a test to cover this case as well
2017-06-25 13:32:08 -04:00
Simon Brunel
548edc65ea Fix non-passive event listener warning in Chrome
Deprecate `addEvent` and `removeEvent`, and move implementation in `platform.dom.js`. Add 'options' feature detection to register event listeners as passive and prevent warning in Chrome.
2017-06-25 10:15:55 -04:00
Evert Timberg
8834babef2 Ensure deprecated unitStepSize property of time scale is respected (#4401) 2017-06-25 14:37:38 +02:00
Simon Brunel
5d95280d7b Change valueAtIndexOrDefault behavior (#4423)
For consistency with `valueOrDefault`, `valueAtIndexOrDefault` now returns null if `value` (expected array) is null. Also get rid of the superfluous `get` prefix in `getValueOrDefault` and `getValueAtIndexOrDefault`.
2017-06-25 10:54:37 +02:00
Simon Brunel
5196e05062 Cleanup and reorganize core and canvas helpers
Move some of the "core" and "canvas" utils in `helpers.core.js` and `helpers.canvas.js` and introduce the new `isNullOrUndef` and `isObject` helpers. Deprecate `indexOf` and rename `drawRoundedRectangle` to `roundedRect` which now creates a simple `rect` path if radius is 0. Write missing unit tests for the moved helpers.
2017-06-24 13:28:52 -04:00
Evert Timberg
6c82c93853 Fix error when legend label options are not defined (#4402) 2017-06-24 17:35:46 +02:00
etimberg
de0ea5c6ba Multiple lines of text in the chart title 2017-06-19 07:07:35 -04:00
Andrew
2d7c1f0d2c Time axis tick formatting with major and minor units (#4268)
Working towards creating the TimeSeries scale, this PR adds formatting for major and minor ticks on axes.
2017-06-15 07:20:16 -04:00
Ricardo Costa
009ae4dec6 Support hover animation duration during updates (#4300)
See discussion in the issue for context and possible approaches.

When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.

This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one. 

Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.

.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it.
2017-06-11 12:06:39 -04:00
Simon Brunel
5e58114848 Fix filling between datasets of different lengths 2017-06-10 09:44:15 -04:00
OlduwanSteve
8eee12486d Added 'devicePixelRatio' option to override the window's DPR setting (#4270) 2017-06-04 18:57:55 +02:00
Jerome Touffe-Blin
fa6be2f772 Fix inconsistent aspect ratio 2017-06-04 09:41:13 -04:00
Andrew
f7f177f5ad Implemented aligment by senior unit in time axis. (#4267)
Implemented alignment by major unit in the time scale. This allows showing the first tick of a larger unit like days in a special way and is part of the basis of the time series scale.
2017-05-29 18:40:10 -04:00
ApoorvA
394382b931 Add tooltip textLabelColor callback (#4199)
Add a new tooltip callback `labelTextColor` that returns the colour for each item in the body of the tooltip.

Fixes issue #4191
2017-05-28 08:39:29 -04:00
Simon Brunel
f0c6b3f834 Fix legend and title layout options update 2017-04-29 11:38:42 -04:00
Simon Brunel
f7d2d7536a Fix failing instanceof when reading context
`instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is inside an iframe or when running in a protected environment. We could guess the types from their toString() value but let's keep things flexible and assume it's a sufficient condition if the item has a context2D which has item as `canvas`.
2017-04-22 13:14:16 -04:00
Thomas Redston
3ec6377f11 Fix hidden charts hanging the browser
Ensure width cannot be greater than maxWidth. Similar to `minSize.height` calculation.
2017-04-22 11:25:09 -04:00
Eric Nikolay Katz
205cedc0ef Enhancement: adds step-after functionality, true defaults to step-before (#4065)
* Adds step-after functionality, true defaults to step-before

* Update stepped line sample to include all variations of steppedLine configurations

* Update documentation on steppedLine values

* Add tests for new steppedLine values 'before' and 'after'
2017-04-16 16:13:13 -04:00
etimberg
19d6df21e3 Fix pointRadius and pointHitRadius settings for radar charts 2017-04-16 16:12:45 -04:00
GabrielMancik
254bd4bf86 Fixed calculation of scale min and max when dataset contains no values (#4064)
* Fixed different calculation of scale min and max when dataset contains no values
* Removed trailing spaces
* Added test for correct min/max calculation
* Removed trailing spaces
2017-04-15 12:37:49 -04:00
Simon Brunel
50a80da1e9 Fix and refactor bar controllers
Merge most of the horizontalBar controller into the bar one but also fix stack groups and bar positioning when scales are stacked or when a min and/or max tick values are explicitly defined. Note that this is a breaking change for derived controllers that rely on the following removed methods: `calculateBarBase`, `calculateBarX`, `calculateBarY`, `calculateBarWidth` and `calculateBarHeight`.
2017-04-08 13:40:21 -04:00
cizmiak
69dd0bde6c scale service - respect new weight scale option for axes ordering (#4094)
* respect new scale option 'order' when ordering scales

* scale service - respect new weight scale option for axes ordering

* added test for scale ordering by weight

* removed trailing spaces from layout weight scale order test
2017-04-04 19:42:25 -04:00
etimberg
06383669be Adds a better error message when the chart type is incorrect. Previously the user got a message about type being undefined.
This gives something that's easier to understand and debug.
2017-04-03 17:39:09 -04:00
Thomas Redston
35dcfe00b1 Time scale improvements to improve performance and reliability
* Make parseTime private
* start on fixing time scale
* Reimplement existing functionality
* Tidy tests
* Fix labels for non-linearly sized units

Months, quarters and years have non-constant numbers of seconds. A scale that's linear WRT milliseconds produces incorrect tick labels due to the label formatting losing precision (eg year labels lose month and day so a label of 2016-12-32 displays as 2016 instead of 2017).

* Re-implement tick generation

As in v2.5
2017-04-02 08:49:00 -04:00
etimberg
222479c5c7 Update the tooltip with a new caretPadding setting. Previously this value was essentially hard coded to
2 because of a typo that read it from the positioner output. Based on #3599 we agreed to make this into
a config setting.
2017-03-28 18:17:26 -04:00
Simon Brunel
f3816b560c Move legend and title in the plugins folder (#4076) 2017-03-25 18:28:54 +01:00
Lee N Dobryden
20a832809e Zero line dash options (#4019)
* Add of zero line border dash options
* Update Readme with zero line border dash config options
2017-03-21 06:38:09 -04:00
Hiroshi Shirosaki
cffa9447a1 Fix radar chart horizontal position (#4032)
Radar chart position is not center horizontally with v2.5.0.

Right and left of `furthestLimits` would be switched wrongly on
this refactoring commit.
e1606f88ed
2017-03-20 20:39:18 -04:00