Superset二次开发之XAxis 功能优化

embedded/2024/9/25 2:11:32/

背景:

以柱状图(来自Echarts 插件)为例,如果X轴data数据过长,影响图表体验,为此需要省略部分内容

superset-frontend\plugins\plugin-chart-echarts\src\Timeseries\transformProps.ts

import {getBaselineSeriesForStream,getPadding,getTooltipTimeFormatter,getXAxisFormatter,getXAxisEllipsisFormatter,transformEventAnnotation,transformFormulaAnnotation,transformIntervalAnnotation,transformSeries,transformTimeseriesAnnotation,
} from './transformers';-----------------------------------------------------------------------------
let xAxis: any = {type: xAxisType,name: xAxisTitle,nameGap: convertInteger(xAxisTitleMargin),nameLocation: 'middle',axisLabel: {hideOverlap: true,formatter: xAxisFormatter,rotate: xAxisLabelRotation,// overflow: 'truncate',// width: 80,},minInterval:xAxisType === 'time' && timeGrainSqla? TIMEGRAIN_TO_TIMESTAMP[timeGrainSqla]: 0,};

superset-frontend\plugins\plugin-chart-echarts\src\Timeseries\transformers.ts

export function getXAxisEllipsisFormatter(maxLength: number = 10) {return function(value: string | number | null) {const strValue = String(value);if (isNaN(maxLength) || maxLength <= 0 || maxLength >= strValue.length) {return strValue; }if (strValue.length > maxLength && maxLength > 3) {const partLength = Math.floor((maxLength - 3) / 2); const start = strValue.substring(0, partLength);const end = strValue.substring(strValue.length - partLength); return `${start}...${end}`; }return strValue;};
}

superset-frontend\plugins\plugin-chart-echarts\src\Timeseries\Regular\Bar\controlPanel.tsx


const {logAxis,minorSplitLine,truncateYAxis,yAxisBounds,zoomable,xAxisLabelRotation,xAxisLabelEllipsis,orientation,
} = DEFAULT_FORM_DATA;
--------------------------------------------------------------------------------[{name: 'xAxisLabelEllipsis',config: {type: 'TextControl',label: t('Ellipsis axis label'),// default: xAxisLabelRotation,renderTrigger: true,isInt: true,description: t('If the axis label content is too long, use ... hide the middle content.',),visibility: ({ controls }: ControlPanelsContainerProps) =>isXAxis ? isVertical(controls) : isHorizontal(controls),},},],

superset\translations\zh\LC_MESSAGES\messages.json

"If the axis label content is too long, use ... hide the middle content.": ["如果坐标轴文本内容过长,就用...隐藏中间的内容"
],

superset\translations\zh\LC_MESSAGES\messages.po

msgid "If the axis label content is too long, use ... hide the middle content."
msgstr "如果坐标轴文本内容过长,就用...隐藏中间的内容"

superset\translations\en\LC_MESSAGES\messages.json

"If the axis label content is too long, use ... hide the middle content.": [""
],

superset\translations\en\LC_MESSAGES\messages.po

msgid "If the axis label content is too long, use ... hide the middle content."
msgstr ""

superset-frontend\plugins\plugin-chart-echarts\src\Timeseries\transformProps.ts

1. EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; 加入‘xAxisLabelEllipsis,’

2.修改xAxis 的逻辑

  const axisFormatter = xAxisLabelEllipsis ? getXAxisEllipsisFormatter(xAxisLabelEllipsis) : xAxisFormatterlet xAxis: any = {type: xAxisType,name: xAxisTitle,nameGap: convertInteger(xAxisTitleMargin),nameLocation: 'middle',axisLabel: {hideOverlap: true,// formatter: xAxisFormatter,formatter: axisFormatter,rotate: xAxisLabelRotation,},minInterval:xAxisType === 'time' && timeGrainSqla? TIMEGRAIN_TO_TIMESTAMP[timeGrainSqla]: 0,};

效果图

x轴


http://www.ppmy.cn/embedded/38565.html

相关文章

分类任务的基础学习

1.什么是分类&#xff1f; 2.局限性&#xff1a; 当样本量逐渐变大的时候&#xff0c;准确率会下降——>因为线性回归曲线距离我们的原点越远&#xff0c;预测就会开始不准确&#xff0c;因为 x前面的倍数就会越来越小&#xff0c;这就导致了样本量变大&#xff0c;但是那些…

C++学习笔记——仿函数

文章目录 仿函数——思维导图仿函数是什么仿函数的优势理解仿函数仿函数的原理举例 仿函数——思维导图 仿函数是什么 使用对象名调用operator&#xff08;&#xff09;函数看起来像是在使用函数一样&#xff0c;因此便有了仿函数的称呼&#xff1b;仿函数存在的意义是&#x…

thinkphp5 配合阿里直播实现直播功能流程

要为你提供一个更详细的教程来结合ThinkPHP 5和阿里直播SDK实现直播功能&#xff0c;需要涵盖的内容相对较多。不过&#xff0c;我可以为你提供一个大致的、更详细的步骤指南&#xff0c;供你参考和扩展&#xff1a; 1. 准备工作 a. 注册阿里云账号 前往阿里云官网注册账号&…

【Docker】如何注册Hub账号并上传镜像到Hub仓库

一、创建Hub账户 浏览器访问&#xff1a;hub.docker.com 点击【Sign up】注册账号 输入【邮箱】【用户名】【密码】 ps&#xff1a;用户名要有字母数字&#xff1b;订阅不用勾选 点击【Sign up】注册即可 点击【Sign in】登录账号 输入【邮箱】【密码】 点击【Continue】登录 二…

vue3+vite+ts 自定义指令详解

directive-自定义指令&#xff08;属于破坏性更新&#xff09; Vue中有v-if,v-for,v-bind&#xff0c;v-show,v-model 等等一系列方便快捷的指令 今天一起来了解一下vue里提供的自定义指令 Vue3指令的钩子函数 created 元素初始化的时候 beforeMount 指令绑定到元素后调用 只调…

Spring IoCDI

一.引言 1.什么是Spring 前面我们说Spring是一个开源框架&#xff0c;它让我们的开发更为简单&#xff0c;它支持广泛的应用场景&#xff0c;有活跃庞大的社区。但这样说还是很抽象。今天我们就对他进行具象的描述 一句话说&#xff0c;Spring就是包含了众多工具的IoC容器。…

java io模型

目录 BIO 模型模型一&#xff1a;单线程服务器模型二&#xff1a;多线程服务器 NIO 模型模型一&#xff1a;遍历轮训 select/poll模型二&#xff1a;基于事件响应机制的 epoll BIO BIO 模型 模型一&#xff1a;单线程服务器 执行过程&#xff1a;阻塞等待 connection&#xff…

vue3引入vant完整步骤

在Vue 3中引入Vant&#xff08;一个基于Vue的移动端UI组件库&#xff09;的完整步骤通常包括以下几个部分&#xff1a; 安装Vue CLI&#xff08;如果你还没有安装的话&#xff09;&#xff1a; npm install -g vue/cli 创建一个新的Vue项目&#xff1a; 假设你希望项目名为my…