如何动态调整svg中的文本大小?(How to resize text in svg dynamically?)
我正在编写一个包含嵌入式svg图表的报告。 该图是使用相对坐标绘制的,所以当浏览器窗口调整大小时,图表调整得相当好。 唯一的例外是文字 - 它仍然是一样的。 是否可以绘制可调整大小的svg文本?
I'm working on a report that includes an embedded svg diagram. The diagram is drawn using relative coordinates, so when a browser window resizes the diagram resizes pretty well. The only exception there is text - it remains the same. Is it possible to draw text in svg that is resizable?
原文:https://stackoverflow.com/questions/283346
最满意答案
>>> a = "15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC" >>> a = map(str.strip,a.split(';')) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'ZH0311', 'ZH0311', 'DOC'] >>> a = sorted(set(a),key=lambda x:a.index(x)) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'DOC'] >>> ";".join(a) '15-105;ZH0311;TZZGJJ;DOC'
我已经使用split来拆分它然后剥离以移除额外的空间。 我已经使用set来删除重复,但设置dosent关心秩序。 所以我需要按照原样排序
>>> def remove_duplication(my_list): ... my_newlist = [] ... for x in my_list: ... x = map(str.strip,x.split(';')) ... my_newlist.append(";".join(sorted(set(x),key=lambda y:x.index(y)))) ... return my_newlist ... >>> remove_duplication(a_list) ['15~105;~ PO185-400CT;NGG;DOC', '15~105;-1;NGG;DOC', '15~105;NGG;-10;DOC', '15~55;J205~J208;POI;DOC', '15-105;ZH0305~;WER /;TZZGJJ;DOC', '15-105;ZH0311;TZZGJJ;DOC', '15-115;PL026~ PL028;Dry;PTT']
如果你的字符串是由空格分隔的话:
>>> a="# -- coding: utf-8 --" >>> a= map(str.strip,a.split()) >>> a ['#', '--', 'coding:', 'utf-8', '--'] >>> a = " ".join(sorted(set(a),key=lambda x:a.index(x))) >>> a '# -- coding: utf-8'
split
字符串拆分为一些分隔符,它可能是空格拼写或字符或可以是任何东西。>>> a = "15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC" >>> a = map(str.strip,a.split(';')) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'ZH0311', 'ZH0311', 'DOC'] >>> a = sorted(set(a),key=lambda x:a.index(x)) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'DOC'] >>> ";".join(a) '15-105;ZH0311;TZZGJJ;DOC'
i have used split to split it then strip to remove extra spaces. I have use set to remove duplication, but set dosent care about order. so i need to sort in the order as they are
>>> def remove_duplication(my_list): ... my_newlist = [] ... for x in my_list: ... x = map(str.strip,x.split(';')) ... my_newlist.append(";".join(sorted(set(x),key=lambda y:x.index(y)))) ... return my_newlist ... >>> remove_duplication(a_list) ['15~105;~ PO185-400CT;NGG;DOC', '15~105;-1;NGG;DOC', '15~105;NGG;-10;DOC', '15~55;J205~J208;POI;DOC', '15-105;ZH0305~;WER /;TZZGJJ;DOC', '15-105;ZH0311;TZZGJJ;DOC', '15-115;PL026~ PL028;Dry;PTT']
if your string is delimited by space:
>>> a="# -- coding: utf-8 --" >>> a= map(str.strip,a.split()) >>> a ['#', '--', 'coding:', 'utf-8', '--'] >>> a = " ".join(sorted(set(a),key=lambda x:a.index(x))) >>> a '# -- coding: utf-8'
split
split the string on some delimiter, it may be space punchuatation or character or can be anything.Go though all this documentation, you will understand. Built-in types, Built-in function
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
使用split()和remove() In [11]: s = '30121,long,Mehtab,10,20,,30' In [14]: l = s.split(',') In [15]: l.remove('') In [16]: l Out[16]: ['30121', 'long', 'Mehtab', '10', '20', '30'] Use split() and remove() In [11]: s = '30121,long,Mehtab,10,20,,30' In [14] ...
-
如何从列表中删除空字符串,然后从列表中删除重复的值(how to remove empty strings from list, then remove duplicate values from a list)[2023-05-29]
dtList = dtList.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList() 我假定为空字符串,空格为空。 如果不是,可以使用IsNullOrEmpty (允许空格),或者s != null dtList = dtList.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList() I assumed empty string and whitespace a ... -
我会用过filter : str_list = filter(None, str_list) # fastest str_list = filter(bool, str_list) # fastest str_list = filter(len, str_list) # a bit of slower str_list = filter(lambda item: item, str_list) # slower than list comprehension Python 3从filter返回一个迭代f ...
-
你最好的表现是设置: String[] xs = { "a", "a", "b", "c", "c" }; Set
singles = new TreeSet<>(); Set multiples = new TreeSet<>(); for (String x : xs) { if(!multiples.contains(x)){ if(singles.contains(x)){ ... -
使用remove: myStrings.remove("Alpha"); 请注意,这只会从列表中删除第一次出现的“Alpha”。 Use remove : myStrings.remove("Alpha"); Note that this would only remove the first occurrence of "Alpha" from your list.
-
您可以拨打以下其中一项: 删除所有条目 textArray.clear(); 从特定位置移除(例如第一项) textArray.remove(0); 删除特定的字符串(即equals你的) textArray.remove("myString"); You can call one of: to remove all entries textArray.clear(); to remove from a specific position (e.g. first item) textArray.re ...
-
>>> a = "15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC" >>> a = map(str.strip,a.split(';')) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'ZH0311', 'ZH0311', 'DOC'] >>> a = sorted(set(a),key=lambda x:a.index(x)) >>> a ['15-105', 'ZH0311', 'TZZGJJ', 'DOC'] >>> ";".join(a ...
-
假定排序并不重要: >>> [[tup[0], ', '.join(d for d in set(tup[1].split(', ')))] for tup in mylist] [[20, 'August 2013, September 2015, September 2016'], [30, 'August 2012']] Assuming that ordering is not important: >>> [[tup[0], ', '.join(d for d in set(tup[1].spl ...
-
我建议你创建一个IEqualityComparer来封装逻辑,以确定两个字符串是否相等。 一个例子,如果你想混合和匹配SoundEx和Levenshtein可能是这样的 public class CompanyNameComparer : IEqualityComparer
{ public bool Equals(string x, string y) { if (x == null && y == null) { ...