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

Feature/active elements on top #9920

Merged
merged 7 commits into from Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/charts/bubble.md
Expand Up @@ -63,6 +63,7 @@ The bubble chart allows a number of properties to be specified for each dataset.
| [`pointStyle`](#styling) | [`pointStyle`](../configuration/elements.md#types) | Yes | Yes | `'circle'`
| [`rotation`](#styling) | `number` | Yes | Yes | `0`
| [`radius`](#styling) | `number` | Yes | Yes | `3`
| [`drawActiveElementsOnTop`](#styling) | `boolean` | Yes | Yes | `true`

All these values, if `undefined`, fallback to the scopes described in [option resolution](../general/options)

Expand All @@ -86,6 +87,7 @@ The style of each bubble can be controlled with the following properties:
| `pointStyle` | bubble [shape style](../configuration/elements.md#point-styles).
| `rotation` | bubble rotation (in degrees).
| `radius` | bubble radius (in pixels).
| `drawActiveElementsOnTop` | Draw the active bubbles of a dataset over the other bubbles of the dataset

All these values, if `undefined`, fallback to the associated [`elements.point.*`](../configuration/elements.md#point-configuration) options.

Expand Down
2 changes: 2 additions & 0 deletions docs/charts/line.md
Expand Up @@ -84,6 +84,7 @@ The line chart allows a number of properties to be specified for each dataset. T
| [`tension`](#line-styling) | `number` | - | - | `0`
| [`xAxisID`](#general) | `string` | - | - | first x axis
| [`yAxisID`](#general) | `string` | - | - | first y axis
| [`drawActiveElementsOnTop`](#point-styling) | `boolean` | Yes | Yes | `true`

All these values, if `undefined`, fallback to the scopes described in [option resolution](../general/options)

Expand Down Expand Up @@ -112,6 +113,7 @@ The style of each point can be controlled with the following properties:
| `pointRadius` | The radius of the point shape. If set to 0, the point is not rendered.
| `pointRotation` | The rotation of the point in degrees.
| `pointStyle` | Style of the point. [more...](../configuration/elements.md#point-styles)
| `drawActiveElementsOnTop` | Draw the active points of a dataset over the other points of the dataset

All these values, if `undefined`, fallback first to the dataset options then to the associated [`elements.point.*`](../configuration/elements.md#point-configuration) options.

Expand Down
3 changes: 2 additions & 1 deletion src/core/core.datasetController.js
Expand Up @@ -678,6 +678,7 @@ export default class DatasetController {
const active = [];
const start = this._drawStart || 0;
const count = this._drawCount || (elements.length - start);
const drawActiveElementsOnTop = this.options.drawActiveElementsOnTop;
let i;

if (meta.dataset) {
Expand All @@ -689,7 +690,7 @@ export default class DatasetController {
if (element.hidden) {
continue;
}
if (element.active) {
if (element.active && drawActiveElementsOnTop) {
active.push(element);
} else {
element.draw(ctx, area);
Expand Down
1 change: 1 addition & 0 deletions src/core/core.defaults.js
Expand Up @@ -73,6 +73,7 @@ export class Defaults {
this.scale = undefined;
this.scales = {};
this.showLine = true;
this.drawActiveElementsOnTop = true;

this.describe(_descriptors);
}
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/core.interaction/drawActiveElementsOnTop-false.js
@@ -0,0 +1,34 @@
module.exports = {
tolerance: 0.002,
config: {
type: 'bubble',
data: {
datasets: [{
data: [
{x: 1, y: 1, r: 80},
{x: 1, y: 1, r: 20}
],
drawActiveElementsOnTop: false,
backgroundColor: (ctx) => (ctx.dataIndex === 1 ? 'red' : 'blue'),
hoverBackgroundColor: 'yellow',
hoverRadius: 0,
}]
},
options: {
plugins: {
tooltip: false,
legend: false
},
}
},
options: {
canvas: {
width: 600,
height: 400
},
async run(chart) {
const point = chart.getDatasetMeta(0).data[0];
await jasmine.triggerMouseEvent(chart, 'click', {y: point.y, x: point.x + 25});
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions types/index.esm.d.ts
Expand Up @@ -1838,6 +1838,11 @@ export interface PointOptions extends CommonElementOptions {
* @default 0
*/
rotation: number;
/**
* Draw the active elements over the other elements of the dataset,
* @default true
*/
drawActiveElementsOnTop: boolean;
}

export interface PointHoverOptions extends CommonHoverOptions {
Expand Down