Browse Source

UI: Refactoring for touch event

pull/7793/head
Artem Dzhereleiko 3 years ago
parent
commit
5102e5fda7
  1. 4
      ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts
  2. 28
      ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts
  3. 22
      ui-ngx/src/app/modules/home/components/widget/lib/settings/chart/flot-widget-settings.component.html
  4. 4
      ui-ngx/src/app/modules/home/components/widget/lib/settings/chart/flot-widget-settings.component.ts
  5. 5
      ui-ngx/src/assets/locale/locale.constant-en_US.json
  6. 1
      ui-ngx/src/typings/jquery.flot.typings.d.ts

4
ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts

@ -136,7 +136,7 @@ export interface TbFlotYAxisSettings {
export interface TbFlotBaseSettings { export interface TbFlotBaseSettings {
stack: boolean; stack: boolean;
enableSelection: FlotSelection; enableSelection: boolean;
shadowSize: number; shadowSize: number;
fontColor: string; fontColor: string;
fontSize: number; fontSize: number;
@ -183,8 +183,6 @@ export interface TbFlotGraphSettings extends TbFlotBaseSettings,
export declare type BarAlignment = 'left' | 'right' | 'center'; export declare type BarAlignment = 'left' | 'right' | 'center';
export declare type FlotSelection = 'enable' | 'disable' | 'mobile' | 'desktop';
export interface TbFlotBarSettings extends TbFlotBaseSettings, export interface TbFlotBarSettings extends TbFlotBaseSettings,
TbFlotThresholdsSettings, TbFlotComparisonSettings, TbFlotCustomLegendSettings { TbFlotThresholdsSettings, TbFlotComparisonSettings, TbFlotCustomLegendSettings {
defaultBarWidth: number; defaultBarWidth: number;

28
ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts

@ -37,7 +37,7 @@ import {
widgetType widgetType
} from '@app/shared/models/widget.models'; } from '@app/shared/models/widget.models';
import { import {
ChartType, FlotSelection, ChartType,
TbFlotAxisOptions, TbFlotAxisOptions,
TbFlotHoverInfo, TbFlotHoverInfo,
TbFlotKeySettings, TbFlotKeySettings,
@ -117,7 +117,7 @@ export class TbFlot {
private mouseleaveHandler = this.onFlotMouseLeave.bind(this); private mouseleaveHandler = this.onFlotMouseLeave.bind(this);
private flotClickHandler = this.onFlotClick.bind(this); private flotClickHandler = this.onFlotClick.bind(this);
private enableSelection: FlotSelection; private enableSelection: boolean;
private selectionMode: 'x' | null; private selectionMode: 'x' | null;
private readonly showTooltip: boolean; private readonly showTooltip: boolean;
@ -134,8 +134,8 @@ export class TbFlot {
this.chartType = this.chartType || 'line'; this.chartType = this.chartType || 'line';
this.settings = ctx.settings as TbFlotSettings; this.settings = ctx.settings as TbFlotSettings;
this.utils = this.ctx.$injector.get(UtilsService); this.utils = this.ctx.$injector.get(UtilsService);
this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : 'enable'; this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : true;
this.checkSelectionMode(); this.selectionMode = this.enableSelection ? 'x' : null;
this.showTooltip = isDefined(this.settings.showTooltip) ? this.settings.showTooltip : true; this.showTooltip = isDefined(this.settings.showTooltip) ? this.settings.showTooltip : true;
this.tooltip = this.showTooltip ? $('#flot-series-tooltip') : null; this.tooltip = this.showTooltip ? $('#flot-series-tooltip') : null;
if (this.tooltip?.length === 0) { if (this.tooltip?.length === 0) {
@ -172,7 +172,7 @@ export class TbFlot {
}; };
if (this.chartType === 'line' || this.chartType === 'bar' || this.chartType === 'state') { if (this.chartType === 'line' || this.chartType === 'bar' || this.chartType === 'state') {
this.options.selection = { mode: this.selectionMode }; this.options.selection = { mode: this.selectionMode, touch: true };
this.options.xaxes = []; this.options.xaxes = [];
this.xaxis = { this.xaxis = {
mode: 'time', mode: 'time',
@ -589,22 +589,6 @@ export class TbFlot {
this.createPlot(); this.createPlot();
} }
mobileModeChanged() {
this.checkSelectionMode();
this.options.selection = { mode: this.selectionMode };
this.redrawPlot();
}
private checkSelectionMode() {
if (this.enableSelection === 'enable' ||
this.enableSelection === 'mobile' && this.ctx.isMobile ||
this.enableSelection === 'desktop' && !this.ctx.isMobile) {
this.selectionMode = 'x';
} else {
this.selectionMode = null;
}
}
public update() { public update() {
if (this.updateTimeoutHandle) { if (this.updateTimeoutHandle) {
clearTimeout(this.updateTimeoutHandle); clearTimeout(this.updateTimeoutHandle);
@ -1272,7 +1256,7 @@ export class TbFlot {
this.$element.css('pointer-events', ''); this.$element.css('pointer-events', '');
this.$element.addClass('mouse-events'); this.$element.addClass('mouse-events');
if (this.chartType !== 'pie') { if (this.chartType !== 'pie') {
this.options.selection = {mode: this.selectionMode}; this.options.selection = {mode: this.selectionMode, touch: true};
this.$element.bind('plotselected', this.flotSelectHandler); this.$element.bind('plotselected', this.flotSelectHandler);
this.$element.bind('dblclick', this.dblclickHandler); this.$element.bind('dblclick', this.dblclickHandler);
} }

22
ui-ngx/src/app/modules/home/components/widget/lib/settings/chart/flot-widget-settings.component.html

@ -19,26 +19,12 @@
<fieldset class="fields-group"> <fieldset class="fields-group">
<legend class="group-title" translate>widgets.chart.common-settings</legend> <legend class="group-title" translate>widgets.chart.common-settings</legend>
<section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px" style="margin-bottom: 16px;"> <section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px" style="margin-bottom: 16px;">
<mat-checkbox formControlName="stack"> <mat-checkbox fxFlex formControlName="stack">
{{ 'widgets.chart.enable-stacking-mode' | translate }} {{ 'widgets.chart.enable-stacking-mode' | translate }}
</mat-checkbox> </mat-checkbox>
<mat-form-field fxFlex class="mat-block"> <mat-checkbox fxFlex formControlName="enableSelection">
<mat-label translate>widgets.chart.selection</mat-label> {{ 'widgets.chart.enable-selection-mode' | translate }}
<mat-select formControlName="enableSelection"> </mat-checkbox>
<mat-option [value]="'enable'">
{{ 'widgets.chart.selection-enable' | translate }}
</mat-option>
<mat-option [value]="'disable'">
{{ 'widgets.chart.selection-disable' | translate }}
</mat-option>
<mat-option [value]="'mobile'">
{{ 'widgets.chart.selection-mobile' | translate }}
</mat-option>
<mat-option [value]="'desktop'">
{{ 'widgets.chart.selection-desktop' | translate }}
</mat-option>
</mat-select>
</mat-form-field>
</section> </section>
<section *ngIf="chartType === 'graph'" fxLayout="column" fxLayout.gt-xs="row" <section *ngIf="chartType === 'graph'" fxLayout="column" fxLayout.gt-xs="row"
fxLayoutGap.gt-xs="8px" fxLayoutAlign.gt-xs="start center"> fxLayoutGap.gt-xs="8px" fxLayoutAlign.gt-xs="start center">

4
ui-ngx/src/app/modules/home/components/widget/lib/settings/chart/flot-widget-settings.component.ts

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

5
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -4214,10 +4214,7 @@
"common-settings": "Common settings", "common-settings": "Common settings",
"enable-stacking-mode": "Enable stacking mode", "enable-stacking-mode": "Enable stacking mode",
"selection": "Time range selection", "selection": "Time range selection",
"selection-enable": "Enable", "enable-selection-mode": "Enable stacking mode",
"selection-disable": "Disable",
"selection-mobile": "Only mobile",
"selection-desktop": "Only desktop",
"line-shadow-size": "Line shadow size", "line-shadow-size": "Line shadow size",
"display-smooth-lines": "Display smooth (curved) lines", "display-smooth-lines": "Display smooth (curved) lines",
"default-bar-width": "Default bar width for non-aggregated data (milliseconds)", "default-bar-width": "Default bar width for non-aggregated data (milliseconds)",

1
ui-ngx/src/typings/jquery.flot.typings.d.ts

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

Loading…
Cancel
Save