Merge pull request #7793 from ArtemDzhereleiko/AD/feature/flot-selection

Add "Enable selection mode" settings with touch event for bar/state/line chart-widgets
This commit is contained in:
Igor Kulikov 2023-06-28 13:02:15 +03:00 committed by GitHub
commit c10531f53c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 6 deletions

View File

@ -208,4 +208,4 @@
}
}
]
}
}

View File

@ -136,6 +136,7 @@ export interface TbFlotYAxisSettings {
export interface TbFlotBaseSettings {
stack: boolean;
enableSelection: boolean;
shadowSize: number;
fontColor: string;
fontSize: number;

View File

@ -117,6 +117,9 @@ export class TbFlot {
private mouseleaveHandler = this.onFlotMouseLeave.bind(this);
private flotClickHandler = this.onFlotClick.bind(this);
private enableSelection: boolean;
private selectionMode: 'x' | null;
private readonly showTooltip: boolean;
private readonly animatedPie: boolean;
private pieDataAnimationDuration: number;
@ -131,6 +134,8 @@ export class TbFlot {
this.chartType = this.chartType || 'line';
this.settings = ctx.settings as TbFlotSettings;
this.utils = this.ctx.$injector.get(UtilsService);
this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : true;
this.selectionMode = this.enableSelection ? 'x' : null;
this.showTooltip = isDefined(this.settings.showTooltip) ? this.settings.showTooltip : true;
this.tooltip = this.showTooltip ? $('#flot-series-tooltip') : null;
if (this.tooltip?.length === 0) {
@ -167,7 +172,7 @@ export class TbFlot {
};
if (this.chartType === 'line' || this.chartType === 'bar' || this.chartType === 'state') {
this.options.selection = { mode : 'x' };
this.options.selection = { mode: this.selectionMode, touch: true };
this.options.xaxes = [];
this.xaxis = {
mode: 'time',
@ -1251,7 +1256,7 @@ export class TbFlot {
this.$element.css('pointer-events', '');
this.$element.addClass('mouse-events');
if (this.chartType !== 'pie') {
this.options.selection = {mode: 'x'};
this.options.selection = {mode: this.selectionMode, touch: true};
this.$element.bind('plotselected', this.flotSelectHandler);
this.$element.bind('dblclick', this.dblclickHandler);
}

View File

@ -18,9 +18,14 @@
<section class="tb-widget-settings" [formGroup]="flotSettingsFormGroup" fxLayout="column">
<fieldset class="fields-group">
<legend class="group-title" translate>widgets.chart.common-settings</legend>
<mat-checkbox formControlName="stack">
{{ 'widgets.chart.enable-stacking-mode' | translate }}
</mat-checkbox>
<section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px" style="margin-bottom: 16px;">
<mat-checkbox fxFlex formControlName="stack">
{{ 'widgets.chart.enable-stacking-mode' | translate }}
</mat-checkbox>
<mat-checkbox fxFlex formControlName="enableSelection">
{{ 'widgets.chart.enable-selection-mode' | translate }}
</mat-checkbox>
</section>
<section *ngIf="chartType === 'graph'" fxLayout="column" fxLayout.gt-xs="row"
fxLayoutGap.gt-xs="8px" fxLayoutAlign.gt-xs="start center">
<mat-form-field fxFlex class="mat-block">

View File

@ -45,6 +45,7 @@ import { defaultLegendConfig, widgetType } from '@shared/models/widget.models';
export const flotDefaultSettings = (chartType: ChartType): Partial<TbFlotSettings> => {
const settings: Partial<TbFlotSettings> = {
stack: false,
enableSelection: true,
fontColor: '#545454',
fontSize: 10,
showTooltip: true,
@ -148,6 +149,7 @@ export class FlotWidgetSettingsComponent extends PageComponent implements OnInit
// Common settings
stack: [false, []],
enableSelection: [true, []],
fontSize: [10, [Validators.min(0)]],
fontColor: ['#545454', []],

View File

@ -4264,6 +4264,8 @@
"chart": {
"common-settings": "Common settings",
"enable-stacking-mode": "Enable stacking mode",
"selection": "Time range selection",
"enable-selection-mode": "Enable selection mode",
"line-shadow-size": "Line shadow size",
"display-smooth-lines": "Display smooth (curved) lines",
"default-bar-width": "Default bar width for non-aggregated data (milliseconds)",

View File

@ -119,6 +119,7 @@ interface JQueryPlotSelection {
color?: string;
shape?: JQueryPlotSelectionShape;
minSize?: number;
touch?: boolean;
}
interface JQueryPlotSelectionRanges {