diff --git a/CHANGELOG.md b/CHANGELOG.md index ae61ad8..6bd958a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added Boxplot in Visual Editor (#327) - Updated Grafana 11.2 dependencies (#330) +- Added Scatter to Visual editor and limit selection to supported charts (#332) ## 6.3.0 (2024-08-26) diff --git a/echarts.volkovlabs.io/home.json b/echarts.volkovlabs.io/home.json index dd0c905..587c659 100644 --- a/echarts.volkovlabs.io/home.json +++ b/echarts.volkovlabs.io/home.json @@ -1061,6 +1061,7 @@ }, { "datasource": { + "default": true, "type": "marcusolsson-static-datasource", "uid": "4ytGZmF4k" }, @@ -1080,7 +1081,7 @@ "format": "auto", "height": 600 }, - "editorMode": "code", + "editorMode": "visual", "gaode": { "key": "", "plugin": "AMap.Scale,AMap.ToolBar" @@ -1098,13 +1099,76 @@ "name": "default" }, "visualEditor": { - "code": "console.log(context);\nreturn {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", + "code": "context.panel.chart.on('click', (params) => {\n context.grafana.locationService.replace('/d/U332C4K4z/scatter?orgId=1');\n});\n\n// See https://github.com/ecomfe/echarts-stat\ncontext.echarts.registerTransform(context.ecStat.transform.regression);\n\nreturn {\n grid: {\n bottom: \"3%\",\n containLabel: true,\n left: \"3%\",\n right: \"4%\",\n top: \"4%\"\n },\n dataset: context.editor.dataset,\n series: context.editor.series,\n tooltip: {\n trigger: 'axis',\n axisPointer: {\n type: 'cross'\n }\n },\n xAxis: {\n splitLine: {\n lineStyle: {\n type: 'dashed'\n }\n }\n },\n yAxis: {\n splitLine: {\n lineStyle: {\n type: 'dashed'\n }\n }\n },\n graphic: [\n {\n type: 'group',\n rotation: Math.PI / 4,\n bounding: 'raw',\n right: 110,\n bottom: 110,\n z: 100,\n children: [\n {\n type: 'rect',\n left: 'center',\n top: 'center',\n z: 100,\n shape: {\n width: 400,\n height: 50\n },\n style: {\n fill: 'rgba(0,0,0,0.3)'\n }\n },\n {\n type: 'text',\n left: 'center',\n top: 'center',\n z: 100,\n style: {\n fill: '#fff',\n text: 'CLICK FOR MORE',\n font: 'bold 26px sans-serif'\n }\n }\n ]\n }]\n}\n", "codeHeight": 600, - "dataset": [], - "series": [] + "dataset": [ + { + "name": "xAxis", + "source": "A" + }, + { + "name": "yAxis", + "source": "A" + } + ], + "series": [ + { + "encode": { + "x": ["A:xAxis"], + "y": ["A:yAxis"] + }, + "id": "Line", + "name": "Line", + "type": "line", + "uid": "a0096b03-9971-4890-835d-029716ec4521" + }, + { + "encode": { + "tooltip": [], + "x": ["A:xAxis"], + "y": ["A:yAxis"] + }, + "id": "Scatter", + "name": "", + "symbol": "circle", + "type": "scatter", + "uid": "4c88dedc-f52f-4eb9-bc10-6b3fcf67fbfc" + } + ] } }, "pluginVersion": "6.4.0", + "targets": [ + { + "datasource": { + "type": "marcusolsson-static-datasource", + "uid": "4ytGZmF4k" + }, + "frame": { + "fields": [ + { + "config": {}, + "name": "xAxis", + "type": "number", + "values": [] + }, + { + "config": {}, + "name": "yAxis", + "type": "number", + "values": [] + } + ], + "meta": { + "custom": { + "customCode": "const points = Array.from({ length: 18 }, (_, index) => index + 1)\nconst result = {\n ...frame,\n fields: frame.fields.map((field) => {\n \n if (field.name === 'xAxis') {\n return ({\n ...field,\n values: points\n })\n }\n\n const start = 4000;\n const end = 78000;\n const count = 18;\n\n const r = Math.pow(end / start, 1 / (count - 1));\n\n const numbers = Array.from({ length: count }, (_, index) => {\n return Math.round(start * Math.pow(r, index));\n });\n\n console.log(numbers);\n\n return ({\n ...field,\n values: numbers\n })\n })\n}\n\nreturn Promise.resolve(result);", + "valuesEditor": "custom" + } + } + }, + "refId": "A" + } + ], "title": "Scatter", "type": "volkovlabs-echarts-panel" }, diff --git a/echarts.volkovlabs.io/scatter.json b/echarts.volkovlabs.io/scatter.json index 4101f04..f112d45 100644 --- a/echarts.volkovlabs.io/scatter.json +++ b/echarts.volkovlabs.io/scatter.json @@ -24,7 +24,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 7, + "id": 11, "links": [ { "asDropdown": false, @@ -43,6 +43,7 @@ "panels": [ { "datasource": { + "default": true, "type": "marcusolsson-static-datasource", "uid": "4ytGZmF4k" }, @@ -62,7 +63,7 @@ "format": "auto", "height": 600 }, - "editorMode": "code", + "editorMode": "visual", "gaode": { "key": "", "plugin": "AMap.Scale,AMap.ToolBar" @@ -79,13 +80,141 @@ "name": "default" }, "visualEditor": { - "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", - "dataset": [], - "series": [] + "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n grid: {\n bottom: \"3%\",\n containLabel: true,\n left: \"3%\",\n right: \"4%\",\n top: \"4%\"\n },\n /**\n * Should be add to see tooltip\n */\n tooltip: {},\n xAxis: {\n type: \"category\"\n },\n yAxis: {\n type: \"value\"\n },\n}\n", + "dataset": [ + { + "name": "Yaxis", + "source": "A" + }, + { + "name": "Xaxis", + "source": "A" + }, + { + "name": "Size", + "source": "A" + } + ], + "series": [ + { + "encode": { + "tooltip": ["A:Size"], + "x": ["A:Xaxis"], + "y": ["A:Yaxis"] + }, + "id": "Scatter", + "name": "Scatter", + "sizeField": "A:Size", + "symbol": "circle", + "type": "scatter", + "uid": "08dcc113-7054-459e-9d36-9375f41c5b21" + } + ] } }, - "pluginVersion": "6.3.0", - "title": "Basic Scatter", + "pluginVersion": "6.4.0", + "targets": [ + { + "datasource": { + "type": "marcusolsson-static-datasource", + "uid": "4ytGZmF4k" + }, + "frame": { + "fields": [ + { + "config": {}, + "name": "Yaxis", + "type": "string", + "values": [ + "10", + "8.07", + "13.0", + "9.05", + "11", + "14", + "13.4", + "10", + "14", + "12.5", + "9.15", + "11.5", + "3.03", + "12.2", + "2.02", + "1.05", + "4.06", + "6.03", + "12.0", + "12.0", + "7.08", + "5.02" + ] + }, + { + "config": {}, + "name": "Xaxis", + "type": "string", + "values": [ + "8.04", + "6.95", + "7.58", + "8.81", + "8.33", + "7.66", + "6.81", + "6.33", + "8.96", + "6.82", + "7.20", + "7.2", + "4.23", + "7.83", + "4.47", + "3.33", + "4.96", + "7.24", + "8.84", + "6.26", + "5.82", + "5.68" + ] + }, + { + "config": {}, + "name": "Size", + "type": "string", + "values": [ + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "29", + "28", + "27", + "26", + "25", + "24", + "23", + "22", + "21", + "20", + "19" + ] + } + ], + "meta": {} + }, + "refId": "A" + } + ], + "title": "Basic Scatter Visual Editor ", "type": "volkovlabs-echarts-panel" }, { @@ -131,7 +260,7 @@ "series": [] } }, - "pluginVersion": "6.3.0", + "pluginVersion": "6.4.0", "title": "Anscombe's quartet", "type": "volkovlabs-echarts-panel" }, @@ -178,7 +307,7 @@ "series": [] } }, - "pluginVersion": "6.3.0", + "pluginVersion": "6.4.0", "title": "Clustering Process", "type": "volkovlabs-echarts-panel" }, @@ -225,12 +354,13 @@ "series": [] } }, - "pluginVersion": "6.3.0", + "pluginVersion": "6.4.0", "title": "Clustering Process", "type": "volkovlabs-echarts-panel" }, { "datasource": { + "default": true, "type": "marcusolsson-static-datasource", "uid": "4ytGZmF4k" }, @@ -250,7 +380,7 @@ "format": "auto", "height": 600 }, - "editorMode": "code", + "editorMode": "visual", "gaode": { "key": "", "plugin": "AMap.Scale,AMap.ToolBar" @@ -267,13 +397,87 @@ "name": "default" }, "visualEditor": { - "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", - "dataset": [], - "series": [] + "code": "// See https://github.com/ecomfe/echarts-stat\ncontext.echarts.registerTransform(context.ecStat.transform.regression);\nreturn {\n dataset: context.editor.dataset,\n series: context.editor.series,\n grid: {\n bottom: \"3%\",\n containLabel: true,\n left: \"3%\",\n right: \"4%\",\n top: \"4%\"\n },\n tooltip: {\n trigger: 'axis',\n axisPointer: {\n type: 'cross'\n }\n },\n xAxis: {\n splitLine: {\n lineStyle: {\n type: 'dashed'\n }\n }\n },\n yAxis: {\n splitLine: {\n lineStyle: {\n type: 'dashed'\n }\n }\n },\n};\n\n", + "dataset": [ + { + "name": "xAxis", + "source": "A" + }, + { + "name": "yAxis", + "source": "A" + }, + { + "name": "size", + "source": "A" + } + ], + "series": [ + { + "encode": { + "x": ["A:xAxis"], + "y": ["A:yAxis"] + }, + "id": "Line", + "name": "Line", + "type": "line", + "uid": "b03da6d0-fa2a-463f-ae6c-d559a4807084" + }, + { + "encode": { + "tooltip": [], + "x": ["A:xAxis"], + "y": ["A:yAxis"] + }, + "id": "Scatter", + "name": "Scatter", + "sizeField": "A:size", + "symbol": "pin", + "type": "scatter", + "uid": "ff7205b9-9724-47a4-9bb4-84d959b1cdb9" + } + ] } }, - "pluginVersion": "6.3.0", - "title": "Exponential Regression", + "pluginVersion": "6.4.0", + "targets": [ + { + "datasource": { + "type": "marcusolsson-static-datasource", + "uid": "4ytGZmF4k" + }, + "frame": { + "fields": [ + { + "config": {}, + "name": "xAxis", + "type": "number", + "values": [] + }, + { + "config": {}, + "name": "yAxis", + "type": "number", + "values": [] + }, + { + "config": {}, + "name": "size", + "type": "number", + "values": [] + } + ], + "meta": { + "custom": { + "customCode": "const points = Array.from({ length: 18 }, (_, index) => index + 1)\nconst sizes = Array.from({ length: 18 }, (_, index) => index + 3)\nconst result = {\n ...frame,\n fields: frame.fields.map((field) => {\n\n if (field.name === 'xAxis') {\n return ({\n ...field,\n values: points\n })\n }\n\n if (field.name === 'size') {\n return ({\n ...field,\n values: sizes\n })\n }\n\n const start = 4000;\n const end = 78000;\n const count = 18;\n\n const r = Math.pow(end / start, 1 / (count - 1));\n\n const numbers = Array.from({ length: count }, (_, index) => {\n return Math.round(start * Math.pow(r, index));\n });\n\n console.log(numbers);\n\n return ({\n ...field,\n values: numbers\n })\n })\n}\n\nreturn Promise.resolve(result);", + "valuesEditor": "custom" + } + } + }, + "refId": "A" + } + ], + "title": "Exponential Regression Vvisual editor", "type": "volkovlabs-echarts-panel" }, { @@ -319,7 +523,7 @@ "series": [] } }, - "pluginVersion": "6.3.0", + "pluginVersion": "6.4.0", "title": "Effect Scatter", "type": "volkovlabs-echarts-panel" }, @@ -355,8 +559,18 @@ "key": "" }, "map": "json", - "renderer": "canvas" + "renderer": "canvas", + "themeEditor": { + "config": "{}", + "name": "default" + }, + "visualEditor": { + "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", + "dataset": [], + "series": [] + } }, + "pluginVersion": "6.4.0", "title": "Linear Regression", "type": "volkovlabs-echarts-panel" }, @@ -392,8 +606,18 @@ "key": "" }, "map": "json", - "renderer": "canvas" + "renderer": "canvas", + "themeEditor": { + "config": "{}", + "name": "default" + }, + "visualEditor": { + "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", + "dataset": [], + "series": [] + } }, + "pluginVersion": "6.4.0", "title": "Polynomial Regression", "type": "volkovlabs-echarts-panel" }, @@ -429,8 +653,18 @@ "key": "" }, "map": "json", - "renderer": "canvas" + "renderer": "canvas", + "themeEditor": { + "config": "{}", + "name": "default" + }, + "visualEditor": { + "code": "return {\n dataset: context.editor.dataset,\n series: context.editor.series,\n xAxis: {\n type: 'time',\n },\n yAxis: {\n type: 'value',\n min: 'dataMin',\n },\n}\n", + "dataset": [], + "series": [] + } }, + "pluginVersion": "6.4.0", "title": "Punch Card of Github", "type": "volkovlabs-echarts-panel" } @@ -450,6 +684,6 @@ "timezone": "", "title": "Scatter", "uid": "U332C4K4z", - "version": 1, + "version": 3, "weekStart": "" } diff --git a/src/components/EchartsPanel/EchartsPanel.tsx b/src/components/EchartsPanel/EchartsPanel.tsx index ac937d6..4956b4e 100644 --- a/src/components/EchartsPanel/EchartsPanel.tsx +++ b/src/components/EchartsPanel/EchartsPanel.tsx @@ -214,7 +214,7 @@ export const EchartsPanel: React.FC = ({ options, data, width, height, re dataset: { source: getDatasetSource(data.series, options.visualEditor.dataset), }, - series: getDataSeries(options.visualEditor.series, data.series), + series: getDataSeries(options.visualEditor.series, data.series, options.visualEditor.dataset), radar: getRadarOptions(options.visualEditor, data.series), }, }) diff --git a/src/components/GraphEditors/ScatterEditor/ScatterEditor.tsx b/src/components/GraphEditors/ScatterEditor/ScatterEditor.tsx new file mode 100644 index 0000000..831a623 --- /dev/null +++ b/src/components/GraphEditors/ScatterEditor/ScatterEditor.tsx @@ -0,0 +1,157 @@ +import { SelectableValue } from '@grafana/data'; +import { InlineField, InlineFieldRow, Select } from '@grafana/ui'; +import React from 'react'; + +import { SCATTER_SYMBOL_OPTIONS, TEST_IDS } from '../../../constants'; +import { DatasetItem, SeriesByType, SeriesItem, SeriesType } from '../../../types'; +import { getDatasetItemUniqueName } from '../../../utils'; + +/** + * Label Width + */ +const labelWidth = 10; + +/** + * Scatter Item + */ +type ScatterSeriesItem = SeriesByType; + +/** + * Properties + */ +interface Props { + /** + * Value + * + * @type {ScatterSeriesItem} + */ + value: ScatterSeriesItem; + + /** + * On Change + */ + onChange: (value: SeriesItem) => void; + + /** + * Dataset + */ + dataset: DatasetItem[]; +} + +/** + * Scatter editor + */ +export const ScatterEditor: React.FC = ({ value, onChange, dataset }) => { + return ( + <> + + + ({ + value: getDatasetItemUniqueName(item), + label: getDatasetItemUniqueName(item), + }))} + isMulti={true} + isClearable={true} + onChange={(event) => { + const values = event as SelectableValue[]; + onChange({ + ...value, + encode: { + ...value.encode, + x: values.map((item) => item.value), + }, + }); + }} + aria-label={TEST_IDS.seriesEditor.scatterFieldEncodeX} + /> + + + + + { + const values = event as SelectableValue; + onChange({ + ...value, + symbol: values.value, + }); + }} + aria-label={TEST_IDS.seriesEditor.scatterFieldSymbolType} + /> + + + + +