惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
D
Docker
F
Full Disclosure
AI
AI
罗磊的独立博客
博客园 - 【当耐特】
U
Unit 42
S
SegmentFault 最新的问题
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
博客园_首页
H
Help Net Security
量子位
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog RSS Feed
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
爱范儿
爱范儿
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist

博客园 - 萝卜L

TIA 轨迹 Trace USB Device Tree Viewer & 设备管理器 - 通用串行总线控制器 树莓派 DT 西门子 PLC 1500 过程时间性能 树莓派5 GPIO 输出 PWM PD 协议 E-Marker芯片、私有协议,联想 ThinkPad 135W 电源 Slim方口 ThinkPlus电源 树莓派 RaspberryPi 5 硬件 设备(dev) 芯片(SoC) BCM 线路编号(line) GPIO 针脚 gpioinfo pinout Solid Edge 仿真 Dynamic Designer Motion (DDM) Solid Edge PMI 智能尺寸 尺寸平面 Solid_Edge,尺寸、测量,从动、驱动,同步、顺序建模,变量表 变量类型 Dim Var SolidWorks & Solid Edge 装配体 零件 部件 移动 通过批处理快捷方式参数化调用 Lua 脚本:完整方案与备选方式 Win10 隐藏的 占用空间的 大文件 组态王 7.5 西门子 驱动 各版本 严重 异常 PLC、上位(HMI)接口约定 Modbus RTU TCP 网关 拓扑 TIA SIM 授权 iup "creation only"的时刻 lua 5.3 glue srlua/wsrlua console/windows CMake Luarocks OCX(ActiveX COM) 控件测试容器(tstcon32) 失败 问题 解决 GitHub Desktop 连接 Gitee 失败 EPLAN P8 学习笔记 配图 20250114 TIA Portal V19 STEP 7 Professional WinCC - Setup 安装过程中出错 失败 笔记 配图 20250110 windows zeroBrane Studio(zbstudio/zbs)配置 iuplua V3 Lua 找不到指定模块 找不到指定的程序 V2 powershell 作服务端 响应网络(socket tcp)连接 提供文件夹大小查询服务 V1.1 网络 主机名 地址 解析 记戴尔/Dell U2913WM 显示器故障
Lua IUP Plot 柱状图 示例
萝卜L · 2025-02-12 · via 博客园 - 萝卜L

效果

Lua IUP Plot Bar Demo.gif

帮助文档笔记

自文档,描述Plot,非DEMO使用说明

控件对象结构

Control DS DataSet Sample Index Value
IUP Plot Control DS DataSet Sample Index Value

控件流程

Creation Auxiliary Callback Redraw
IUP Plot Creation Auxiliary Callback Redraw

属性结构

IUP Plot Atrributes

控件内像素坐标与控件轴坐标值换算

Cnv Position AXS MARGIN PADDING
IUP Plot Cnv Position AXS MARGIN PADDING

坐标转换:控件画布内部坐标与控件像素坐标

PLOTBUTTON_CB transform
IUP Plot PLOTBUTTON_CB transform

交互

Interaction
IUP Plot Interaction

代码

local iup=require("iuplua")
require'IUP'
require("iuplua_plot")
require"iupluacontrols"
--	to import IupMatrixEx (to enable "Data Set Values..." dialog)
local Button_CB_Parse=require[[LuaLibs\IUP\Interaction\Button_CB_Parse]]

local _

local function Plot()
	local function Set_Axis_Value_By_Position()
		local function Read_Axis_Value()
			local function Read_Axis_Value_Core(Padding,Margin_On_Min_Side,AXS_Min,Pos_Value,AXS_Max,Margin_On_Max_Side,Width)
				--print("Read_Axis_Value_Core",Padding,Margin_On_Min_Side,AXS_Min,Pos_Value,AXS_Max,Margin_On_Max_Side,Width)
				if Pos_Value<=(Margin_On_Min_Side+Padding) or (Width-Margin_On_Max_Side-Padding)<=Pos_Value then
					return false
				end
				local Pos_Value_Offset_Based_On_AXS_Min=Pos_Value-Margin_On_Min_Side-Padding
				local Axis_Value=(Pos_Value_Offset_Based_On_AXS_Min)/(Width-Margin_On_Min_Side-Margin_On_Max_Side-Padding*2)*(AXS_Max+1-AXS_Min)+AXS_Min
				return Axis_Value
			end;_=Read_Axis_Value_Core
			function Read_Axis_Value(Plot,CNV_X,CNV_Y)
				local CNV_X,CNV_Y=tonumber(CNV_X),tonumber(CNV_Y)
				local Padding_Width,Padding_Height=string.match(Plot.PADDING,'(%d)x(%d)')
				local CNV_Width,CNV_Height=string.match(Plot.RASTERSIZE,'(%d+)x(%d+)')
				local Axis_X_Value=Read_Axis_Value_Core(tonumber(Padding_Width),tonumber(Plot.MARGINLEFT),tonumber(Plot.AXS_XMIN),CNV_X,tonumber(Plot.AXS_XMAX),tonumber(Plot.MARGINRIGHT),tonumber(CNV_Width))
				local Axis_Y_Value=Read_Axis_Value_Core(tonumber(Padding_Height),tonumber(Plot.MARGINBOTTOM),tonumber(Plot.AXS_YMIN),CNV_Y,tonumber(Plot.AXS_YMAX),tonumber(Plot.MARGINTOP),tonumber(CNV_Height))
				return Axis_X_Value,Axis_Y_Value
			end;_=Read_Axis_Value
		end;Read_Axis_Value()
		function Set_Axis_Value_By_Position(Plot,X,Y)
			local Cnv_X,Cnv_Y=Plot:Transform(X,Y)
			local Axis_X_Value,Axis_Y_Value=Read_Axis_Value(Plot,Cnv_X,Cnv_Y)
			if Axis_X_Value and Axis_Y_Value then
				Axis_X_Value,Axis_Y_Value=math.floor(Axis_X_Value),math.floor(Axis_Y_Value)
				--print("",Axis_X_Value,Axis_Y_Value)
				Plot:SetSample(Plot.CURRENT,Axis_X_Value-1,Axis_X_Value,Axis_Y_Value)
				Plot.REDRAW=nil
			end
		end;_=Set_Axis_Value_By_Position
	end;Set_Axis_Value_By_Position()
	function _()end
	Plot=iup.plot{EXPAND='YES',READONLY='YES',MINSIZE='x150',
		AXS_XARROW='NO',AXS_YARROW='NO',
		AUTOTICK='NO',AXS_XTICKMINORDIVISION='NO',
		AXS_XDISCRETE='YES',
		MENUITEMPROPERTIES='YES',
		EDITABLEVALUES='YES',
		--SCREENTOLERANCE=50,
		--	not work?
		AXS_YMIN=0,AXS_YMAX=10,AXS_YAUTOMIN='NO',AXS_YAUTOMAX='NO',
		size = "300x100",
		clicksample_cb=function(Plot,ds_index, sample_index, x, y, button)
			print("clicksample_cb",ds_index, sample_index, x, y, button)
		end,--clicksample_cb
		clicksegment_cb=function(Plot,ds_index, sample_index1, x1, y1, sample_index2, x2, y2, button)
			print("clicksegment_cb",ds_index, sample_index1, x1, y1, sample_index2, x2, y2, button)
		end,--clicksegment_cb
		editsample_cb=function(Plot,DS_Index,Sample_Index,X,Y)
			print("editsample_cb",DS_Index,Sample_Index,X,Y)
		end,--editsample_cb
		select_cb=function(Plot,ds_index, sample_index, x, y, selected)
			print("select_cb",ds_index, sample_index, x, y, selected)
		end,--select_cb
		selectbegin_cb=function(Plot)
			print("selectbegin_cb")
		end,--selectbegin_cb
		selectend_cb=function(Plot)
			print("selectend_cb")
		end,--selectend_cb
		plotbutton_cb=function(Plot,Button,Pressed,X,Y,Status)
			--print("plotbutton_cb",Button,Pressed,X,Y,Status)
			if 'test'
				and false
				then
				local Cnv_X,Cnv_Y=Plot:Transform(X,Y)
				--print("",Cnv_X,Cnv_Y)
				print("",Plot:FindSample(Cnv_X,Cnv_Y))
				print("",iup.PlotFindSegment(Plot,Cnv_X,Cnv_Y))
				--	貌似正常
		--		print("",Plot:FindSegment(Cnv_X,Cnv_Y))
				assert(not Plot.FindSegment)
				--	`FindSegment` not work
			end
			Set_Axis_Value_By_Position(Plot,X,Y)
		end,--plotbutton_cb
		plotmotion_cb=function(Plot,X,Y,Status)
			--print("plotmotion_cb",X,Y,Button_CB_Parse(nil,nil,nil,nil,Status))
			if Button_CB_Parse(nil,nil,nil,nil,Status)=='Button1' then
				Set_Axis_Value_By_Position(Plot,X,Y)
			end
		end,--plotmotion_cb
		dspropertieschanged=function(Plot,DS_Index)
			print("dspropertieschanged",DS_Index)
		end,--dspropertieschanged
		dspropertiesvalidate_cb=function(Plot,param_dialog,DS_Index)
			print("dspropertiesvalidate_cb",DS_Index)
		end,--dspropertiesvalidate_cb
		propertieschanged_cb=function(Plot)
			print("propertieschanged_cb")
		end,--propertieschanged_cb
		propertiesvalidate_cb=function(Plot,Name,Value)
			print("propertiesvalidate_cb",Name,Value)
		end,--propertiesvalidate_cb
	}
end;Plot()

local dialog=iup.dialog{
	iup.vbox{
		iup.frame{
			TITLE='Plot',
			Plot,
		},
	},
}

dialog:showxy(iup.CENTER, iup.CENTER)

math.randomseed(os.time())
do
	Plot:Begin(0)
	local Count=50
	for Index=1,Count do
		Plot[math.random(Count)>(Count//2) and 'Add' or 'AddSegment'](Plot,Index,math.random(10))
	end
	local DS_Index=Plot:End()
	print(DS_Index==tonumber(Plot.CURRENT))
	Plot.DS_MODE='BAR'
	Plot.DS_COLOR='255 0 0 100'
	Plot.REDRAW='YES'
end

iup.MainLoop()