3
0

Extend configuration for generic charts

This commit is contained in:
Katrin Yordanova
2022-11-18 16:17:40 +02:00
parent 29ab1c713b
commit 16082d1766
7 changed files with 463 additions and 24 deletions
@@ -9,7 +9,7 @@
<template #dimension-options="{ dimension }">
<b-form-group
:label="$t('edit.dimension.gaugeSteps')"
:label-cols="2"
:label-cols="3"
>
<b-input-group
v-for="(step, i) in dimension.meta.steps"
@@ -8,6 +8,19 @@
{{ $t('edit.yAxis.label') }}
</h4>
<b-form-group
horizontal
:label-cols="3"
class="mt-2"
breakpoint="md"
:label="$t('edit.yAxis.labelPosition.label')"
>
<b-form-select
v-model="report.yAxis.labelPosition"
:options="axisLabelPositions"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
@@ -34,20 +47,22 @@
<b-form-group
horizontal
:label-cols="3"
class="mt-2"
breakpoint="md"
:label="$t('edit.yAxis.labelPosition.label')"
:label-cols="3"
:label="$t('edit.yAxis.rotate.label')"
:description="$t('edit.yAxis.rotate.description')"
>
<b-form-select
v-model="report.yAxis.labelPosition"
:options="axisLabelPositions"
<b-input
v-model="report.yAxis.rotateLabel"
type="number"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
class="mt-1"
breakpoint="md"
:label="$t('edit.yAxis.minLabel')"
>
@@ -56,10 +71,10 @@
:placeholder="$t('edit.yAxis.minPlaceholder')"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
class="mt-1"
breakpoint="md"
:label="$t('edit.yAxis.maxLabel')"
>
@@ -105,6 +120,7 @@
<b-form-group
horizontal
:label-cols="3"
class="mt-1"
breakpoint="md"
:label="$t('edit.metric.labelLabel')"
>
@@ -182,7 +198,6 @@
{{ $t('edit.metric.fillArea') }}
</b-form-checkbox>
</template>
<b-form-checkbox
v-model="metric.fixTooltips"
:value="true"
@@ -192,6 +207,286 @@
</b-form-checkbox>
</b-form-group>
</template>
<template #additional-config="{ report, metrics }">
<hr>
<div
v-for="(m, i) in metrics"
:key="i"
>
<template
v-if="m.type === 'pie' || m.type === 'doughnut'"
>
<h5
v-if="metrics.length > 1"
class="d-flex align-items-center mb-3"
>
<font-awesome-icon
class="grab metric-handle align-baseline text-secondary mr-2"
:icon="['fas', 'grip-vertical']"
/>
{{ $t('edit.metric.label') }} {{ i + 1 }}
</h5>
<h4 class="mb-3">
{{ $t('edit.additionalConfig.legend.label') }}
</h4>
<b-form-group
horizontal
breakpoint="md"
>
<b-form-checkbox
v-model="report.legend.isHidden"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.legend.hide') }}
</b-form-checkbox>
<b-form-checkbox
v-model="report.legend.isList"
:disabled="report.legend.isHidden"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.legend.showAsList') }}
</b-form-checkbox>
<b-form-checkbox
v-model="report.legend.isCustomized"
:disabled="report.legend.isHidden"
class="mb-3"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.legend.position.customize') }}
</b-form-checkbox>
<template
v-if="report.legend.isCustomized"
>
<b-form-group
horizontal
:label-cols="3"
breakpoint="md"
:label="$t('edit.additionalConfig.legend.position.top')"
class="mt-1"
>
<b-input
v-model="report.legend.position.top"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.legend.position.right')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.legend.position.right"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.legend.position.bottom')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.legend.position.bottom"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
breakpoint="md"
class="mt-1"
:label-cols="3"
:label="$t('edit.additionalConfig.legend.position.left')"
:description="$t('edit.additionalConfig.legend.valueRange')"
>
<b-input
v-model="report.legend.position.left"
placeholder="0"
/>
</b-form-group>
</template>
</b-form-group>
<h4 class="mb-3">
{{ $t('edit.additionalConfig.tooltip.label') }}
</h4>
<b-form-group
horizontal
breakpoint="md"
>
<b-form-checkbox
v-model="report.tooltip.labelsNextToPartition"
class="mb-3"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.tooltip.labelNextToChartPartition') }}
</b-form-checkbox>
<b-form-group
horizontal
:label-cols="3"
breakpoint="md"
:label="$t('edit.additionalConfig.tooltip.formatting.label')"
:description="$t('edit.additionalConfig.tooltip.formatting.description')"
class="mt-1"
>
<b-input
v-model="report.tooltip.formatting"
:placeholder="$t('edit.additionalConfig.tooltip.formatting.placeholder')"
/>
</b-form-group>
</b-form-group>
<h4 class="mb-3">
{{ $t('edit.additionalConfig.offset.label') }}
</h4>
<b-form-checkbox
v-model="report.offset.isDefault"
class="mb-3"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.offset.default') }}
</b-form-checkbox>
<b-form-group
v-if="!report.offset.isDefault"
horizontal
breakpoint="md"
>
<b-form-group
horizontal
:label-cols="3"
breakpoint="md"
:label="$t('edit.additionalConfig.offset.position.top')"
class="mt-1"
>
<b-input
v-model="report.offset.top"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.right')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.offset.right"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.bottom')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.offset.bottom"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.left')"
breakpoint="md"
:description="$t('edit.additionalConfig.offset.valueRange')"
class="mt-1"
>
<b-input
v-model="report.offset.left"
placeholder="0"
/>
</b-form-group>
</b-form-group>
<hr>
</template>
<template v-if="m.type === 'bar' || m.type === 'line'">
<h4 class="mb-3">
{{ $t('edit.additionalConfig.offset.label') }}
</h4>
<b-form-checkbox
v-model="report.offset.isDefault"
class="mb-3"
:value="true"
:unchecked-value="false"
>
{{ $t('edit.additionalConfig.offset.default') }}
</b-form-checkbox>
<b-form-group
v-if="!report.offset.isDefault"
horizontal
breakpoint="md"
>
<b-form-group
horizontal
:label-cols="3"
breakpoint="md"
:label="$t('edit.additionalConfig.offset.position.top')"
class="mt-1"
>
<b-input
v-model="report.offset.top"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.right')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.offset.right"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.bottom')"
breakpoint="md"
class="mt-1"
>
<b-input
v-model="report.offset.bottom"
placeholder="0"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
:label="$t('edit.additionalConfig.offset.position.left')"
breakpoint="md"
:description="$t('edit.additionalConfig.offset.valueRange')"
class="mt-1"
>
<b-input
v-model="report.offset.left"
placeholder="0"
/>
</b-form-group>
</b-form-group>
</template>
</div>
</template>
</report-edit>
</template>
@@ -142,6 +142,19 @@
:type="defaultValueInputType(d)"
/>
</b-form-group>
<b-form-group
horizontal
:label-cols="3"
breakpoint="md"
:label="$t('edit.dimension.rotate.label')"
:description="$t('edit.dimension.rotate.description')"
>
<b-input
v-model="d.rotateLabel"
type="number"
placeholder="0"
/>
</b-form-group>
</template>
</template>
@@ -246,6 +259,12 @@
</fieldset>
</draggable>
</div>
<slot
name="additional-config"
:report="editReport"
:metrics="metrics"
/>
</div>
</template>
+22 -1
View File
@@ -252,7 +252,12 @@ export class BaseChart {
}
defDimension (): Dimension {
return Object.assign({}, { conditions: {}, meta: {} })
return Object.assign({},
{
conditions: {},
meta: {},
labels: { rotateXAxisLabel: 0 }
})
}
defMetrics (): Metric {
@@ -270,6 +275,22 @@ export class BaseChart {
axisPosition: 'left',
labelPosition: 'end',
},
tooltip: {},
legend: {
position: {
top: '0',
right: '0',
bottom: '0',
left: '0',
},
},
offset: {
top: '0',
right: '0',
bottom: '0',
left: '0',
isDefault: true,
},
})
}
+50 -13
View File
@@ -105,7 +105,13 @@ export default class Chart extends BaseChart {
}
const { labels, datasets = [] } = data
const { dimensions: [dimension] = [], yAxis } = reports[0] || {}
const {
dimensions: [dimension] = [],
yAxis, metrics: [metric] = [],
offset,
tooltip: t,
legend: l,
} = reports[0] || {}
const hasAxis = datasets.some(({ type }: any) => ['bar', 'line'].includes(type))
const timeDimension = (dimensionFunctions.lookup(dimension) || {}).time
@@ -135,6 +141,7 @@ export default class Chart extends BaseChart {
interval: 0,
overflow: 'truncate',
hideOverlap: true,
rotate: yAxis.rotateLabel,
},
axisLine: {
show: true,
@@ -143,7 +150,7 @@ export default class Chart extends BaseChart {
nameTextStyle: {
align: labelPosition === 'center' ? 'center' : position,
padding: labelPosition !== 'center' ? (position === 'left' ? [0, 0, 2, -20] : [0, -20, 2, 0]) : undefined,
}
},
}
// If we provide undefined, log scale breaks
@@ -156,6 +163,8 @@ export default class Chart extends BaseChart {
}
}
let pieLegend = {}
options.series = datasets.map(({ type, label, data, fill, tooltip }: any, index: number) => {
const { fixed, relative } = tooltip
@@ -164,6 +173,30 @@ export default class Chart extends BaseChart {
options.tooltip.trigger = 'item'
let lbl = {}
if (t?.labelsNextToPartition) {
lbl = { show: true }
} else {
lbl = {
show: fixed,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
}
}
const formatter = t?.formatting
? t.formatting
: `{a}<br />{b} : {c}${relative ? ' ({d}%)' : ''}`
pieLegend = {
top: l?.position?.top || 'auto',
right: l?.position?.right || 'auto',
bottom: l?.position?.bottom || 'auto',
left: l?.position?.left || 'auto',
}
return {
z: index,
name: label,
@@ -172,13 +205,10 @@ export default class Chart extends BaseChart {
center: ['50%', '55%'],
tooltip: {
trigger: 'item',
formatter: `{a}<br />{b} : {c}${relative ? ' ({d}%)' : ''}`,
formatter,
},
label: {
show: fixed,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
...lbl,
fontSize: 14,
},
itemStyle: {
@@ -196,6 +226,10 @@ export default class Chart extends BaseChart {
data: labels.map((name: string, i: number) => {
return { name, value: data[i] }
}),
top: offset?.isDefault ? 45 : offset?.top,
right: offset?.isDefault ? 25 : offset?.right,
bottom: offset?.isDefault ? 40 : offset?.bottom,
left: offset?.isDefault ? 40 : offset?.left,
}
} else if (['bar', 'line'].includes(type)) {
options.tooltip.trigger = 'axis'
@@ -209,15 +243,17 @@ export default class Chart extends BaseChart {
interval: 0,
overflow: 'truncate',
hideOverlap: true,
rotate: dimension.rotateLabel,
},
})
}
options.grid = {
top: 45,
bottom: 25,
left: 40,
right: 40,
top: offset?.isDefault ? 45 : offset?.top,
right: offset?.isDefault ? 25 : offset?.right,
bottom: offset?.isDefault ? 40 : offset?.bottom,
left: offset?.isDefault ? 40 : offset?.left,
// prevents long labels like dates from being cut off
containLabel: true,
}
@@ -247,8 +283,9 @@ export default class Chart extends BaseChart {
fontFamily: 'Poppins-Regular',
},
legend: {
show: true,
type: 'scroll',
show: !l?.isHidden,
type: l?.isList ? 'plain' : 'scroll',
...pieLegend,
},
...options,
}
+33
View File
@@ -30,6 +30,7 @@ export interface Dimension {
default?: string;
skipMissing?: boolean;
autoSkip?: boolean;
rotateLabel?: string;
}
export interface Metric {
@@ -55,6 +56,34 @@ export interface YAxis {
labelPosition?: string;
min?: string;
max?: string;
rotateLabel?: string;
}
export interface ChartOffset {
top?: string;
right?: string;
bottom?: string;
left?: string;
isDefault?: boolean;
}
export interface Position {
top?: string;
right?: string;
bottom?: string;
left?: string;
}
export interface Legend {
isHidden?: boolean;
isList?: boolean;
isCustomized?: boolean;
position?: Position;
}
export interface Tooltip {
formatting?: string;
labelsNextToPartition?: boolean;
}
export interface Report {
@@ -63,6 +92,9 @@ export interface Report {
dimensions?: Array<Dimension>;
metrics?: Array<Metric>;
yAxis?: YAxis;
tooltip?: Tooltip;
legend?: Legend;
offset?: ChartOffset;
}
export interface ChartConfig {
@@ -212,3 +244,4 @@ const chartUtil = {
export {
chartUtil,
}
+35 -1
View File
@@ -38,6 +38,9 @@ edit:
selectedItems: Selected options
unselectAllItems: Unselect all
noItemsFound: No options found
rotate:
label: Rotate label
description: Labels can be rotated from -90 to 90 degrees. Applied to bar and line charts
filter:
customize: Customize filter
label: Filters
@@ -54,7 +57,7 @@ edit:
fieldLabel: Field
fieldPlaceholder: Select metric field
fillArea: Fill area below the line
fixTooltips: Always show tooltips
fixTooltips: Show tooltips
function:
avg: AVG
label: Function
@@ -104,6 +107,9 @@ edit:
axisOnRight: Place axis on the right side
axisScaleFromZero: Always begin axis scale at zero
label: Y-axis
rotate:
label: Rotate label
description: Labels can be rotated from -90 to 90 degrees. Applied to bar and line charts
labelLabel: Axis label
labelPlaceholder: Axis label
labelPosition:
@@ -116,6 +122,34 @@ edit:
maxPlaceholder: Maximum value
minLabel: Min value
minPlaceholder: Minimum value
additionalConfig:
legend:
label: Legend
hide: Hide legend
showAsList: Show as list
position:
customize: Customize position
top: Top
right: Right
bottom: Bottom
left: Left
valueRange: Values can be set a pixels 20 or as percentages 20%
tooltip:
label: Tooltip
labelNextToChartPartition: Show labels next to chart partition
formatting:
label: Formatting
description: '{a} - metrics field value, {b} - dimension field value, {c} - value of dimension field, {d} - percentage'
placeholder: '{a}<br />{b} : {c} ({d}%)'
offset:
label: Offset
default: Default offset
position:
top: Top
right: Right
bottom: Bottom
left: Left
valueRange: Values can be set a pixels 20 or as percentages 20%
import: 'Import chart(s):'
newLabel: 'Create a new chart:'
name: Chart name *