3
0

Sync compose and reporter chart configurator options

This commit is contained in:
Jože Fortun 2022-12-20 15:37:37 +01:00
parent ef04afeeb6
commit 74e70f9ad4
6 changed files with 439 additions and 79 deletions

View File

@ -8,7 +8,10 @@
</h5> </h5>
<b-row> <b-row>
<b-col> <b-col
cols="12"
sm="6"
>
<b-form-group <b-form-group
:label="$t('display-element:chart.configurator.type')" :label="$t('display-element:chart.configurator.type')"
label-class="text-primary" label-class="text-primary"
@ -20,7 +23,11 @@
/> />
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col>
<b-col
cols="12"
sm="6"
>
<b-form-group <b-form-group
:label="$t('display-element:chart.configurator.chart-title')" :label="$t('display-element:chart.configurator.chart-title')"
label-class="text-primary" label-class="text-primary"
@ -33,7 +40,10 @@
</b-row> </b-row>
<b-row> <b-row>
<b-col> <b-col
cols="12"
sm="6"
>
<b-form-group <b-form-group
:label="$t('display-element:chart.configurator.color-scheme')" :label="$t('display-element:chart.configurator.color-scheme')"
label-class="text-primary" label-class="text-primary"
@ -48,7 +58,8 @@
option-text="label" option-text="label"
option-value="value" option-value="value"
clearable clearable
class="h-100 w-100" class="mw-100"
style="min-width: 100%;"
> >
<template #option="option"> <template #option="option">
<p <p
@ -64,6 +75,7 @@
/> />
</template> </template>
</vue-select> </vue-select>
<template <template
v-if="currentColorScheme" v-if="currentColorScheme"
> >
@ -76,22 +88,6 @@
</template> </template>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col
align-self="center"
>
<b-form-checkbox
v-model="options.showTooltips"
class="pb-2"
>
{{ $t('display-element:chart.configurator.show.tooltips') }}
</b-form-checkbox>
<b-form-checkbox
v-model="options.showLegend"
class="pb-2"
>
{{ $t('display-element:chart.configurator.show.legend') }}
</b-form-checkbox>
</b-col>
</b-row> </b-row>
<hr> <hr>
</div> </div>
@ -194,22 +190,15 @@
</b-col> </b-col>
<b-col> <b-col>
<b-form-group <b-form-group
v-if="options.xAxis.type === 'time'" :label="$t('display-element:chart.configurator.x-axis.labelRotation.label')"
:label="$t('display-element:chart.configurator.time.unit.label')"
label-class="text-primary" label-class="text-primary"
class="mb-1"
> >
<b-form-select <b-input
v-model="options.xAxis.unit" v-model="options.xAxis.labelRotation"
:options="timeUnits" type="number"
> number
<template #first> />
<b-form-select-option
:value="undefined"
>
{{ $t('display-element:chart.configurator.default') }}
</b-form-select-option>
</template>
</b-form-select>
</b-form-group> </b-form-group>
</b-col> </b-col>
</b-row> </b-row>
@ -243,6 +232,19 @@
/> />
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col>
<b-form-group
:label="$t('display-element:chart.configurator.y-axis.labelRotation.label')"
label-class="text-primary"
class="mb-1"
>
<b-input
v-model="options.yAxis.labelRotation"
type="number"
number
/>
</b-form-group>
</b-col>
</b-row> </b-row>
<b-row> <b-row>
@ -254,6 +256,7 @@
<b-form-input <b-form-input
v-model="options.yAxis.min" v-model="options.yAxis.min"
type="number" type="number"
number
/> />
</b-form-group> </b-form-group>
</b-col> </b-col>
@ -283,12 +286,6 @@
<b-row> <b-row>
<b-col> <b-col>
<b-form-group> <b-form-group>
<b-form-checkbox
v-model="options.yAxis.beginAtZero"
>
{{ $t('display-element:chart.configurator.begin-axis-at-zero') }}
</b-form-checkbox>
<b-form-checkbox <b-form-checkbox
v-model="options.yAxis.type" v-model="options.yAxis.type"
value="logarithmic" value="logarithmic"
@ -297,6 +294,12 @@
{{ $t('display-element:chart.configurator.logarithmic-scale') }} {{ $t('display-element:chart.configurator.logarithmic-scale') }}
</b-form-checkbox> </b-form-checkbox>
<b-form-checkbox
v-model="options.yAxis.beginAtZero"
>
{{ $t('display-element:chart.configurator.begin-axis-at-zero') }}
</b-form-checkbox>
<b-form-checkbox <b-form-checkbox
v-model="options.yAxis.position" v-model="options.yAxis.position"
value="right" value="right"
@ -309,6 +312,249 @@
</b-row> </b-row>
</div> </div>
</div> </div>
<hr>
<div>
<h5 class="text-primary mb-2">
{{ $t('display-element:chart.configurator.legend.name') }}
</h5>
<b-form-checkbox
v-model="options.legend.hide"
class="mb-3"
>
{{ $t('display-element:chart.configurator.legend.hide') }}
</b-form-checkbox>
<b-row v-if="!options.legend.hide">
<b-col
cols="12"
sm="6"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.align.label')"
label-class="text-primary"
class="mb-1"
>
<b-form-select
v-model="options.legend.align"
:options="alignments"
:disabled="!options.legend.position.default"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.orientation.label')"
label-class="text-primary"
class="mb-1"
>
<b-form-select
v-model="options.legend.orientation"
:options="orientations"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
>
<b-form-checkbox
v-model="options.legend.position.default"
:class="{ 'mb-3': !options.legend.position.default }"
>
{{ $t('display-element:chart.configurator.legend.position.default') }}
</b-form-checkbox>
</b-col>
<b-col
cols="12"
sm="6"
>
<b-form-checkbox
v-model="options.legend.scrollable"
:disabled="options.legend.orientation !== 'horizontal'"
>
{{ $t('display-element:chart.configurator.legend.scrollable') }}
</b-form-checkbox>
</b-col>
<template
v-if="!options.legend.position.default"
>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.position.top')"
label-class="text-primary"
>
<b-input
v-model="options.legend.position.top"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.position.right')"
label-class="text-primary"
>
<b-input
v-model="options.legend.position.right"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.position.bottom')"
label-class="text-primary"
>
<b-input
v-model="options.legend.position.bottom"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.legend.position.left')"
label-class="text-primary"
>
<b-input
v-model="options.legend.position.left"
/>
</b-form-group>
</b-col>
<b-col>
<small>{{ $t('display-element:chart.configurator.position-description') }}</small>
</b-col>
</template>
</b-row>
</div>
<hr>
<div>
<h5 class="text-primary mb-2">
{{ $t('display-element:chart.configurator.tooltips.name') }}
</h5>
<b-row>
<b-col>
<b-form-checkbox
v-model="options.showTooltipsAlways"
>
{{ $t('display-element:chart.configurator.tooltips.show.always') }}
</b-form-checkbox>
</b-col>
</b-row>
</div>
<hr>
<div class="mb-2">
<h5 class="text-primary mb-2">
{{ $t('display-element:chart.configurator.offset.name') }}
</h5>
<b-form-checkbox
v-model="options.offset.default"
class="mb-3"
>
{{ $t('display-element:chart.configurator.offset.default') }}
</b-form-checkbox>
<b-row v-if="!options.offset.default">
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.offset.top')"
label-class="text-primary"
>
<b-input
v-model="options.offset.top"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.offset.right')"
label-class="text-primary"
>
<b-input
v-model="options.offset.right"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.offset.bottom')"
label-class="text-primary"
>
<b-input
v-model="options.offset.bottom"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
sm="6"
xl="3"
>
<b-form-group
:label="$t('display-element:chart.configurator.offset.left')"
label-class="text-primary"
>
<b-input
v-model="options.offset.left"
/>
</b-form-group>
</b-col>
<b-col
cols="12"
>
<small>{{ $t('display-element:chart.configurator.position-description') }}</small>
</b-col>
</b-row>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -350,6 +596,17 @@ export default {
{ value: 'center', text: this.$t('display-element:chart.configurator.y-axis.labelPosition.center') }, { value: 'center', text: this.$t('display-element:chart.configurator.y-axis.labelPosition.center') },
{ value: 'start', text: this.$t('display-element:chart.configurator.y-axis.labelPosition.bottom') }, { value: 'start', text: this.$t('display-element:chart.configurator.y-axis.labelPosition.bottom') },
], ],
orientations: [
{ value: 'horizontal', text: this.$t('display-element:chart.configurator.legend.orientation.horizontal') },
{ value: 'vertical', text: this.$t('display-element:chart.configurator.legend.orientation.vertical') },
],
alignments: [
{ value: 'left', text: this.$t('display-element:chart.configurator.legend.align.left') },
{ value: 'center', text: this.$t('display-element:chart.configurator.legend.align.center') },
{ value: 'right', text: this.$t('display-element:chart.configurator.legend.align.right') },
],
} }
}, },

View File

@ -61,7 +61,6 @@ th {
.v-select { .v-select {
min-width: 20vw; min-width: 20vw;
max-width: 300px;
&:not(.vs--open) .vs__selected + .vs__search { &:not(.vs--open) .vs__selected + .vs__search {
width: 0; width: 0;

View File

@ -12,11 +12,13 @@ interface XAxisOptions {
unit?: string; unit?: string;
skipMissing: boolean; skipMissing: boolean;
defaultValue?: any; defaultValue?: any;
labelRotation: number;
} }
interface YAxisOptions { interface YAxisOptions {
label?: string; label?: string;
labelPosition?: string; labelPosition?: string;
labelRotation: number;
type?: string; type?: string;
position?: string; position?: string;
beginAtZero?: boolean; beginAtZero?: boolean;
@ -25,32 +27,77 @@ interface YAxisOptions {
max?: string; max?: string;
} }
interface Legend {
hide: boolean;
orientation: string;
align: string;
scrollable: boolean;
position: Offset;
}
interface Tooltips {
showAlways: boolean;
}
interface Offset {
default: boolean;
top?: string;
right?: string;
bottom?: string;
left?: string;
}
export class ChartOptions { export class ChartOptions {
public title = '' public title = ''
public type = 'bar' public type = 'bar'
public colorScheme = '' public colorScheme = ''
public source = '' public source = ''
public datasources: Array<FrameDefinition> = [] public datasources: Array<FrameDefinition> = []
public showTooltips = true
public showLegend = true
public xAxis: XAxisOptions = { public xAxis: XAxisOptions = {
type: '', type: '',
skipMissing: true, skipMissing: true,
labelRotation: 0,
} }
public yAxis: YAxisOptions = { public yAxis: YAxisOptions = {
type: 'linear', type: 'linear',
position: 'left', position: 'left',
labelPosition: 'end', labelPosition: 'end',
labelRotation: 0,
beginAtZero: true, beginAtZero: true,
} }
public legend: Legend = {
hide: false,
orientation: 'horizontal',
align: 'center',
scrollable: true,
position: {
default: true,
top: undefined,
right: undefined,
bottom: undefined,
left: undefined,
}
}
public tooltips: Tooltips = {
showAlways: false,
}
public offset: Offset = {
default: true,
top: undefined,
right: undefined,
bottom: undefined,
left: undefined,
}
constructor (o: PartialChartOptions = {}) { constructor (o: PartialChartOptions = {}) {
if (!o) return if (!o) return
Apply(this, o, String, 'title', 'type', 'colorScheme', 'source') Apply(this, o, String, 'title', 'type', 'colorScheme', 'source')
Apply(this, o, Boolean, 'showTooltips', 'showLegend')
if (o.datasources) { if (o.datasources) {
this.datasources = o.datasources this.datasources = o.datasources
@ -63,6 +110,18 @@ export class ChartOptions {
if (o.yAxis) { if (o.yAxis) {
this.yAxis = { ...this.yAxis, ...o.yAxis } this.yAxis = { ...this.yAxis, ...o.yAxis }
} }
if (o.legend) {
this.legend = { ...this.legend, ...o.legend }
}
if (o.tooltips) {
this.tooltips = { ...this.tooltips, ...o.tooltips }
}
if (o.offset) {
this.offset = { ...this.offset, ...o.offset }
}
} }
} }

View File

@ -27,7 +27,7 @@ export class BasicChartOptions extends ChartOptions {
xAxis: [], xAxis: [],
yAxis: [], yAxis: [],
tooltip: { tooltip: {
show: this.showTooltips, show: true,
appendToBody: true, appendToBody: true,
}, },
} }
@ -52,11 +52,11 @@ export class BasicChartOptions extends ChartOptions {
formatter: '{a}<br />{b} : {c} ({d}%)', formatter: '{a}<br />{b} : {c} ({d}%)',
}, },
label: { label: {
show: false, show: this.showTooltipsAlways,
position: 'inside', position: 'inside',
align: 'center', align: 'center',
verticalAlign: 'middle', verticalAlign: 'middle',
fontSize: 14, formatter: '{c} ({d}%)',
}, },
itemStyle: { itemStyle: {
borderRadius: 5, borderRadius: 5,
@ -73,12 +73,20 @@ export class BasicChartOptions extends ChartOptions {
data: labels.map((name, i) => { data: labels.map((name, i) => {
return { name, value: data[i] } return { name, value: data[i] }
}), }),
top: this.offset.default ? undefined : this.offset.top,
right: this.offset.default ? undefined : this.offset.right,
bottom: this.offset.default ? undefined : this.offset.bottom,
left: this.offset.default ? undefined : this.offset.left,
} }
}) })
} else if (['bar', 'line'].includes(this.type)) { } else if (['bar', 'line'].includes(this.type)) {
options.tooltip.trigger = 'axis' options.tooltip.trigger = 'axis'
const { label: xLabel, type: xType = 'category' } = this.xAxis const {
label: xLabel,
type: xType = 'category',
labelRotation: xLabelRotation = 0
} = this.xAxis
options.xAxis = [ options.xAxis = [
{ {
@ -91,20 +99,22 @@ export class BasicChartOptions extends ChartOptions {
interval: 0, interval: 0,
overflow: 'truncate', overflow: 'truncate',
hideOverlap: true, hideOverlap: true,
rotate: xLabelRotation,
}, },
}, },
] ]
options.grid = { options.grid = {
top: this.title ? 70 : 45, top: this.offset.default ? (this.title ? 70 : 45) : this.offset.top,
bottom: xLabel ? 30 : 25, right: this.offset.default ? 30 : this.offset.right,
left: 40, bottom: this.offset.default ? (xLabel ? 30 : 25) : this.offset.bottom,
right: 40, left: this.offset.default ? 30 : this.offset.left,
containLabel: true, containLabel: true,
} }
const { const {
label: yLabel, label: yLabel,
labelRotation: yLabelRotation = 0,
type: yType = 'linear', type: yType = 'linear',
position = 'left', position = 'left',
labelPosition = 'end', labelPosition = 'end',
@ -125,6 +135,7 @@ export class BasicChartOptions extends ChartOptions {
interval: 0, interval: 0,
overflow: 'truncate', overflow: 'truncate',
hideOverlap: true, hideOverlap: true,
rotate: yLabelRotation,
}, },
axisLine: { axisLine: {
show: true, show: true,
@ -152,11 +163,10 @@ export class BasicChartOptions extends ChartOptions {
areaStyle: {}, areaStyle: {},
left: 'left', left: 'left',
label: { label: {
show: false, show: this.showTooltipsAlways,
position: 'inside', position: 'inside',
align: 'center', align: 'center',
verticalAlign: 'middle', verticalAlign: 'middle',
fontSize: 14,
}, },
data: xType === 'time' ? labels.map((name, i) => { data: xType === 'time' ? labels.map((name, i) => {
return [moment(name).valueOf() || undefined, data[i]] return [moment(name).valueOf() || undefined, data[i]]
@ -178,9 +188,13 @@ export class BasicChartOptions extends ChartOptions {
fontFamily: 'Poppins-Regular', fontFamily: 'Poppins-Regular',
}, },
legend: { legend: {
show: this.showLegend, show: !this.legend.hide,
top: this.title ? 25 : undefined, type: this.legend.scrollable ? 'scroll' : 'plain',
type: 'scroll', top: (this.legend.position.default ? (this.title ? 25 : undefined) : this.legend.position.top) || undefined,
right: (this.legend.position.default ? undefined : this.legend.position.right) || undefined,
bottom: (this.legend.position.default ? undefined : this.legend.position.bottom) || undefined,
left: (this.legend.position.default ? this.legend.align || 'center' : this.legend.position.left) || 'auto',
orient: this.legend.orientation || 'horizontal'
}, },
...options, ...options,
} }

View File

@ -36,42 +36,40 @@ export class FunnelChartOptions extends ChartOptions {
fontFamily: 'Poppins-Regular', fontFamily: 'Poppins-Regular',
}, },
tooltip: { tooltip: {
show: this.showTooltips, show: true,
trigger: 'item', trigger: 'item',
formatter: '{b} : {c} ({d}%)', formatter: '{b} : {c} ({d}%)',
appendToBody: true, appendToBody: true,
}, },
legend: { legend: {
show: this.showLegend, show: !this.legend.hide,
top: this.title ? 25 : undefined, type: this.legend.scrollable ? 'scroll' : 'plain',
type: 'scroll', top: (this.legend.position.default ? (this.title ? 25 : undefined) : this.legend.position.top) || undefined,
right: (this.legend.position.default ? undefined : this.legend.position.right) || undefined,
bottom: (this.legend.position.default ? undefined : this.legend.position.bottom) || undefined,
left: (this.legend.position.default ? this.legend.align || 'center' : this.legend.position.left) || 'auto',
orient: this.legend.orientation || 'horizontal'
}, },
series: [ series: [
{ {
type: 'funnel', type: 'funnel',
name: this.labelColumn, name: this.labelColumn,
sort: 'descending', sort: 'descending',
min: 1,
top: this.title ? 60 : 35,
left: '5%',
bottom: '5%',
width: '90%', width: '90%',
label: { label: {
show: false, show: this.showTooltipsAlways,
position: 'inside', position: 'inside',
align: 'center', align: 'center',
verticalAlign: 'middle', verticalAlign: 'middle',
}, formatter: '{c} ({d}%)',
emphasis: {
label: {
show: !this.showTooltips,
fontSize: 14,
formatter: '{c} ({d}%)',
},
}, },
data: labels.map((name, i) => { data: labels.map((name, i) => {
return { name, value: data[i], itemStyle: { color: colors[i] } } return { name, value: data[i], itemStyle: { color: colors[i] } }
}), }),
top: this.offset.default ? (this.title ? 60 : 35) : this.offset.top,
right: this.offset.default ? '5%' : this.offset.right,
bottom: this.offset.default ? '5%' : this.offset.bottom,
left: this.offset.default ? '5%' : this.offset.left,
}, },
], ],
} }

View File

@ -10,16 +10,14 @@ chart:
general: General general: General
label-column: Label column label-column: Label column
logarithmic-scale: Logarithmic scale logarithmic-scale: Logarithmic scale
position-description: Values can be set as pixels (20) or as percentages (20%)
none: None none: None
place-axis-on-right-side: Place axis on the right side place-axis-on-right-side: Place axis on the right side
show:
tooltips: Show tooltips
legend: Show legend
skip-missing-values: Skip missing values skip-missing-values: Skip missing values
step-size: Step size step-size: Step size
time: time:
label: Time label: Time
unit: unit:
label: Time unit label: Time unit
types: types:
date: Date date: Date
@ -37,10 +35,12 @@ chart:
value: value:
max: Max value max: Max value
min: Min value min: Min value
x-axis: x-axis:
name: X-Axis name: X-Axis
label: Axis label label: Axis label
type: Axis type type: Axis type
labelRotation:
label: Rotate labels
y-axis: y-axis:
name: Y-Axis name: Y-Axis
label: Axis label label: Axis label
@ -49,6 +49,39 @@ chart:
top: Top top: Top
center: Center center: Center
bottom: Bottom bottom: Bottom
labelRotation:
label: Rotate labels
legend:
name: Legend
hide: Hide legend
scrollable: Scrollable
orientation:
label: Orientation
horizontal: Horizontal
vertical: Vertical
align:
label: Align
left: Left
right: Right
center: Center
position:
description: Values c
default: Default position
top: Top
right: Right
bottom: Bottom
left: Left
tooltips:
name: Tooltips
show:
always: Always show tooltips
offset:
name: Offset
default: Default offset
top: Top
right: Right
bottom: Bottom
left: Left
metric: metric:
configurator: configurator:
color: color:
@ -70,7 +103,7 @@ table:
light: Light light: Light
none: None none: None
table: table:
options: options:
bordered: Bordered bordered: Bordered
borderless: Borderless borderless: Borderless
dark: Dark dark: Dark