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

962 add tooltip.trigger to scatter-chart #963

Merged
merged 4 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "9.4.0",
"version": "9.5.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "9.4.0",
"version": "9.5.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { Control, UseFormWatch } from 'react-hook-form';
import { Control, Controller, UseFormWatch } from 'react-hook-form';
import { IScatterChartConf } from '../../type';
import { TooltipMetricsField } from './metrics';
import { Divider, Select, Stack } from '@mantine/core';

const TooltipTriggerOptions = [
{
label: 'Scatter Point',
value: 'item',
},
{
label: 'X Axis',
value: 'axis',
},
];

interface ITooltipField {
control: Control<IScatterChartConf, $TSFixMe>;
watch: UseFormWatch<IScatterChartConf>;
data: TVizData;
}
export function TooltipField({ data, control, watch }: ITooltipField) {
return <TooltipMetricsField control={control} watch={watch} data={data} />;
watch('tooltip.trigger');
return (
<Stack>
<Controller
name="tooltip.trigger"
control={control}
render={({ field }) => <Select label="Trigger" data={TooltipTriggerOptions} sx={{ flexGrow: 1 }} {...field} />}
/>
<Divider variant="dashed" />
<TooltipMetricsField control={control} watch={watch} data={data} />
</Stack>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Divider, Group, Tabs, Text } from '@mantine/core';
import { Group, Tabs, Text } from '@mantine/core';
import { useEffect, useState } from 'react';
import { Control, useFieldArray, UseFormWatch } from 'react-hook-form';
import { Control, UseFormWatch, useFieldArray } from 'react-hook-form';
import { InfoCircle, Plus } from 'tabler-icons-react';
import { IScatterChartConf } from '../../type';
import { TooltipMetricField } from './metric';
Expand Down Expand Up @@ -48,7 +48,6 @@ export const TooltipMetricsField = ({ control, watch, data }: ITooltipMetricsFie
Configure additional metrics to show in tooltip
</Text>
</Group>
<Divider variant="dashed" my={10} />
<Tabs
value={tab}
onTabChange={(t) => setTab(t)}
Expand Down
13 changes: 11 additions & 2 deletions dashboard/src/plugins/viz-components/scatter-chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ function v7(legacyConf: $TSFixMe): IScatterChartConf {
};
}

function v8(legacyConf: $TSFixMe): IScatterChartConf {
const patch = { tooltip: { trigger: 'item' } };
return _.defaultsDeep({}, legacyConf, patch);
}

class VizScatterChartMigrator extends VersionBasedMigrator {
readonly VERSION = 7;
readonly VERSION = 8;

configVersions(): void {
this.version(1, (data: any) => {
Expand Down Expand Up @@ -109,6 +114,10 @@ class VizScatterChartMigrator extends VersionBasedMigrator {
const { config } = data;
return { ...data, version: 7, config: v7(config) };
});
this.version(8, (data) => {
const { config } = data;
return { ...data, version: 8, config: v8(config) };
});
}
}

Expand All @@ -121,7 +130,7 @@ export const ScatterChartVizComponent: VizComponent = {
configRender: VizScatterChartEditor,
createConfig() {
return {
version: 7,
version: 8,
config: cloneDeep(DEFAULT_CONFIG) as IScatterChartConf,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { IYAxisConf } from '../../cartesian/type';
import { getEchartsDataZoomOption } from '../../cartesian/editors/echarts-zooming-field/get-echarts-data-zoom-option';

const defaultOption = {
tooltip: {
trigger: 'axis',
},
xAxis: [
{
type: 'category',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ import { AnyObject } from '~/types';
import { getEchartsXAxisLabel } from '../editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label';
import { IScatterChartConf } from '../type';

function formatXAxisLabel(value: string | number, index: number, conf: IScatterChartConf) {
const { x_axis } = conf;
if (!x_axis.axisLabel.formatter.enabled) {
return value;
}
return getEchartsXAxisLabel(x_axis.axisLabel.formatter)(value, index);
}

function getXAxisLabel(params: AnyObject[], conf: IScatterChartConf) {
const { x_axis, tooltip } = conf;
if (tooltip.trigger === 'item') {
const axisValue = params[0].data[x_axis.data_key];
const axisIndex = 0;
return formatXAxisLabel(axisValue, axisIndex, conf);
}

const basis = params.find((p) => p.axisDim === 'x' && p.axisId === 'main-x-axis');
if (!basis) {
return '';
}
const { name, axisValue, axisIndex } = basis;
if (!conf.x_axis.axisLabel.formatter.enabled) {
return axisValue;
}
return getEchartsXAxisLabel(conf.x_axis.axisLabel.formatter)(axisValue, axisIndex);
const { axisValue, axisIndex } = basis;
return formatXAxisLabel(axisValue, axisIndex, conf);
}

const formatAdditionalMetric = (v: number) => {
Expand All @@ -29,9 +41,10 @@ const formatAdditionalMetric = (v: number) => {
};

export function getTooltip(conf: IScatterChartConf, labelFormatters: Record<string, (p: $TSFixMe) => string>) {
const { scatter } = conf;
const { scatter, tooltip } = conf;
return {
confine: true,
trigger: tooltip.trigger,
formatter: function (params: TopLevelFormatterParams) {
const yLabelFormatter = labelFormatters[0] ?? labelFormatters.default;
const arr = Array.isArray(params) ? params : [params];
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/plugins/viz-components/scatter-chart/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface IScatterChartConf {
};
};
tooltip: {
trigger: 'item' | 'axis' | 'none';
metrics: IEchartsTooltipMetric[];
};
reference_lines: ICartesianReferenceLine[];
Expand Down Expand Up @@ -89,6 +90,7 @@ export const DEFAULT_CONFIG: IScatterChartConf = {
},
],
tooltip: {
trigger: 'item',
metrics: [],
},
reference_lines: [],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "9.4.0",
"version": "9.5.0",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "9.4.0",
"version": "9.5.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
6 changes: 3 additions & 3 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "9.4.0",
"version": "9.5.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@ahooksjs/use-url-state": "^3.3.11",
"@devtable/dashboard": "9.4.0",
"@devtable/settings-form": "9.4.0",
"@devtable/dashboard": "9.5.0",
"@devtable/settings-form": "9.5.0",
"@emotion/react": "11.10.6",
"@faker-js/faker": "7.6.0",
"@mantine/core": "5.9.5",
Expand Down