gpt4 book ai didi

ironpython - spotfire 获取格子面板的名称

转载 作者:行者123 更新时间:2023-12-03 23:54:47 49 4
gpt4 key购买 nike

假设我有一个可视化,它由面板按一些分类变量网格化,每页一个面板。我想遍历面板并将每个图像导出到一个文件,文件名与分类变量匹配。

按照一些已发布的示例,图像导出工作完全正常。但是,我在实际获取当前面板的名称时遇到了很多麻烦,以便我可以正确命名图像。

这是我的代码:

from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Drawing import Bitmap, Graphics, Rectangle, Point
from System.IO import Path
import re

vc=viz.As[VisualContent]() #viz is the visualization parameter passed to the script
trellis=vc.Trellis

originalIndex=trellis.ActivePageIndex

outputDir=Document.Properties["imageOutputDir"]

for i in range(trellis.PageCount):
#move to the right page
trellis.ActivePageIndex=i

#make the actual image -
viz_r = Document.ActivePageReference.GetVisualBounds(viz)
width=viz_r.Width
height=viz_r.Height
bm = Bitmap(width,height)
g = Graphics.FromImage(bm)
g.TextRenderingHint = g.TextRenderingHint.AntiAlias
r=Rectangle(0, 0, width,height)
vc.Render(g, r)

#save the image

name="%d"%i
#here we would like to instead get the current value of the trellis variable!
#name=?

clean_name=re.sub(r'[/\\:*?"<>|]', '_',name)
tempFilename = outputDir+"\\%s.png"%clean_name
bm.Save(tempFilename)
print "image saved as " + tempFilename

trellis.ActivePageIndex=originalIndex

我似乎已经浏览了 VisualContent 的所有方法和 Trellis而且还没有找到。

另一种方法是遍历数据并仅获取分类变量的值。但是,顺序不一定会保留,因此效果不佳。如果我能得到每个格子面板对应的数据,我当然可以从中工作。

最佳答案

这就是我最终的结果。当变量的类型为 string 并且排序为 standard sort order for datatype 时,这似乎有效。

如果有人可以使排序更加健壮,那肯定会受到赞赏。我基本上必须通过加载文本数据并检查排序来找出 Spotfire 使用的字母数字排序。我可能忘记了一些字符——这对于我的数据现在似乎有效。

我无法访问 Niko 建议的 TryGetCustomSortOrder 方法——我在 Spotfire 6.5 中工作,它仅在 7.0 中可用

from Spotfire.Dxp.Application.Visuals import VisualContent
import Spotfire.Dxp.Data.DataTable
from Spotfire.Dxp.Data import *
from System.Drawing import Bitmap, Graphics, Rectangle, Point
from System.IO import Path
import re

vc=viz.As[VisualContent]()
trellis=vc.Trellis
name_column=trellis.PanelAxis.Expression.Trim('<').Trim('>').Trim('[').Trim(']')
#get the unique column values
myTable = Document.ActiveDataTableReference
rowCount = myTable.RowCount
rowsToInclude = Document.ActiveFilteringSelectionReference.GetSelection(myTable).AsIndexSet()
cursor1 = DataValueCursor.Create(myTable.Columns[name_column])

S=set()
for row in myTable.GetRows(rowsToInclude,cursor1):
x=cursor1.CurrentDataValue.Value
if x not in S:
S.add(x)
L=list(S)

alphabet=r' _-,;:!.\'"(){}@*/\&#%`^+<=>|~$0123456789abcdefghijklmnopqrstuvwxyz'

L=sorted(L,key=lambda s:[alphabet.index(c) if c in alphabet else -1 for c in s.lower()])
#things not in alphabet probably unicode characters that get sorted to the beginning

originalIndex=trellis.ActivePageIndex
outputDir=Document.Properties["imageOutputDir"]

for i,name in enumerate(L):
trellis.ActivePageIndex=i
viz_r = Document.ActivePageReference.GetVisualBounds(viz)
width=viz_r.Width
height=viz_r.Height
bm = Bitmap(width,height)
g = Graphics.FromImage(bm)
g.TextRenderingHint = g.TextRenderingHint.AntiAlias

r=Rectangle(0, 0, width,height)
vc.Render(g, r)

clean_name=re.sub(r'[/\\:*?"<>|]', '_',name)
tempFilename = outputDir+"\\%s.png"%clean_name
bm.Save(tempFilename)
print "image saved as " + tempFilename

trellis.ActivePageIndex=originalIndex

关于ironpython - spotfire 获取格子面板的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37800420/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com