I have a custom layout that adds a "field" style to LyX. Each time a "field" is created, I'd like to also have a corresponding label attached to the "field" in LyX. Is there a way to do this programmatically in LyX?
Counter fieldCnt
LabelString "Field: \arabic{fieldCnt}."
PrettyFormat "Field: ##"
End
AddToPreamble
\usepackage{tocloft}
\usepackage{ifthen}
\usepackage{nameref}%
\usepackage{hyperref}%
%\usepackage{refstyle}
\newcommand{\listfieldname}{List of Fields}
\newref{field}{ %
%refcmd = {\ref{#1}, `\nameref{#1}'},
name = {Field~},
names = {Field~},
Name = {Field~},
Names = {Field~},
rngtxt = \RSrngtxt,
lsttxt = \RSlsttxt
}
EndPreamble
Style Field1
Category Field
RefPrefix field
LatexType Command
LatexName field
LabelType Counter
LabelCounter fieldCnt
LabelString "Field \arabic{fieldCnt}: "
OptionalArgs 1
LabelSep xxx
ParSep 0.7
Margin Dynamic
Font
Series Bold
EndFont
Preamble
\newlistof{field}{field}{\listfieldname}
\newcommand{\field}[1]{%
\refstepcounter{field}
\par\noindent\textbf{Field \thefield: #1}
\addcontentsline{field}{field}{\protect\numberline{\thefield}#1}\par}
\setcounter{fielddepth}{1}
EndPreamble
End
There is no means by which LyX code can be added in style section of the layout file.
Related
I am using Tabulator and the default "fitData" function to size the cells. This works exactly as intended when I a) Have a default font size set and b) change the row font size using the rowFormatter:
rowFormatter:function(row){
var rowData = row.getData();
row.getElement().style.fontSize = config.body_font_size + "px";
The above works, however, when I want to change the font size of the column titles:
var curHeaders = document.getElementsByClassName("tabulator-col");
for (var i = 0; i < curHeaders.length; i++) {
curHeaders[i].style.fontSize = fontSize.toString() + "px";
}
This changes all the column font sizes, but does not resize the column width appropriately. Is there a different class where I should assigning the font? Is there a way to apply this in a similar way to the rowFormatter?
You shouldn't try and programatically alter elements inside Tabulator from outside the table. Because Tabulator uses a virtual DOM these changes can be overwritten at any point without notice.
If you need to format column header titles you should use a titleFormatter in the column definition for the column you want to change:
//define custom formatter
var customFormatter = function(cell, formatterParams, onRendered){
//set font size
cell.getElement().style.fontSize = fontSize.toString() + "px";
return cell.getValue();
}
//in the column definition for a column
{title:"Name", field:"name", titleFormatter:customFormatter },
Full documentation on how to use formatters can be found here: http://tabulator.info/docs/4.0/format
If you need to keep using your approach then you can call the table redraw function to force the table to be rebuilt:
table.redraw(true);
Is there a reason you need to change it at run time rather than just making the changes in CSS?
I am using Bokeh to create a series of pie charts with bokeh.charts.Donut. The charts are based off of subsets of the same DataFrame, and all have the same category labels. I want to ensure that the same categories are displayed in the same colors across the various charts, but I haven't been able to figure out a consistent way of controlling the colors.
Currently I am sorting my input DataFrames by the label, and passing the same array of colors to the palette property of Donut. This still does not work as intended. Code is as follows:
main_colors = ['#10A400','#DB5E11','#C8C500','#CF102E','#00AFA8','#82BC00','#A40D7A','#FF7100','#1349BB']
#split out youth health problems
for_youth_health = detailed_assessment_safety.loc[detailed_assessment_safety.youth_health_prob.notnull()]
youth_health_issues = pd.DataFrame(for_youth_health.youth_health_prob.str.split(' ').tolist())
for col in youth_health_issues.columns:
newcol = 'youth_health_prob_' + str(col)
youth_health_issues = youth_health_issues.rename(columns={col:newcol})
youth_health_trans = pd.melt(youth_health_issues)
youth_health_trans = youth_health_trans.loc[youth_health_trans.value.notnull()]
youth_health_trans['issue_text'] = youth_health_trans.value.map(map_health_issues)
youth_health_trans.drop('value',axis=1,inplace=True)
youth_health_trans.sort_values(by='issue_text',ascending=True,inplace=True)
#pie of youth health issues
youth_health_issues = Donut(youth_health_trans,label='issue_text',
values='variable',agg='count',plot_width=plot_width,
plot_height=plot_height,title='Reported Youth Health Issues',
color=main_colors)
hover = HoverTool(point_policy='follow_mouse')
hover.tooltips = [('Number Reported','#values'),('Health Issue','#issue_text')]
youth_health_issues.add_tools(hover)
#split out adult health problems
for_adult_health = detailed_assessment_safety.loc[detailed_assessment_safety.adult_health_prob.notnull()]
adult_health_issues = pd.DataFrame(for_adult_health.adult_health_prob.str.split(' ').tolist())
for col in adult_health_issues.columns:
newcol = 'adult_health_prob_' + str(col)
adult_health_issues = adult_health_issues.rename(columns={col:newcol})
adult_health_trans = pd.melt(adult_health_issues)
adult_health_trans = adult_health_trans.loc[adult_health_trans.value.notnull()]
adult_health_trans['issue_text'] = adult_health_trans.value.map(map_health_issues)
adult_health_trans.drop('value',axis=1,inplace=True)
adult_health_trans.sort_values(by='issue_text',ascending=True,inplace=True)
#pie of adult health issues
adult_health_issues = Donut(adult_health_trans,label='issue_text',
values='variable',agg='count',plot_width=plot_width,
plot_height=plot_height,title='Reported Adult Health Issues',
palette=main_colors)
hover = HoverTool(point_policy='follow_mouse')
hover.tooltips = [('Number Reported','#values'),('Health Issue','#issue_text')]
adult_health_issues.add_tools(hover)
What's the proper way to map the same categories of Donut charts to colors across multiple charts? The other idea that I had was inserting a column into the DataFrame that mapped label values to colors, and then passing that column as an argument to Donut, but I couldn't make that work either. Any help is much appreciated.
After some experimentation, it turns out that when you pass an array of colors to the palette argument of Donut, the colors are associated with the donut slices based on an alphabetical sort of the slice name. So, the first color in your array of palette colors will be associated with the slice with the alphabetically first name, etc.
I want to add a title to the legend box in Flot? For example, if my legend shows different Products, I want the title above the legend box to say "Products".
Somewhat hacky, but you can do it like this:
var $legend = $('#chart > div.legend'); // replace #chart with the id from your div
var $legendTitle = $legend.find('div').first();
$legendTitle.html('Products').height($legendTitle.height() + 15);
$legend.find('table').first().css('top', $legendTitle.position().top + 15);
I'm trying to create a script which, in the process of opening a template file, asks the user for a set of CMYK values.
The idea is to then either change the value of an existing colour (called "Primary Colour") therefore changing the colour of every item to which it is applied...or add this new colour and delete 'Primary Colour' replacing it with new colour.
The problem is I can't get past creating a new colour with user input values. I can create a new colour with;
set New_Swatch to make color with properties {name:"New Primary Colour", model:process, color value:{82,72,49,46}}
however as soon as I try to replace the color value with a variable I get the error;
"Adobe InDesign CS5 got an error: Invalid parameter."
Here is a snippet of code in context;
set primaryColour to text returned of (display dialog "Enter CMYK calues of Primary Colour (separated by commas e.g. 0,0,0,0)" default answer "") as string
tell application "Adobe InDesign CS5"
activate
tell active document
set New_Swatch to make color with properties {name:"new", model:process, color value:primaryColour}
end tell
end tell
Any help gratefully received.
I currently use this:
set primaryColor to text returned of (display dialog "Enter CMYK values of Primary Colour (separated by commas e.g. 0,0,0,0)" default answer "") as string
set text item delimiters to ","
set colorvalue to {}
repeat with color from 1 to count of text items of primaryColor
copy (text item colour of primaryColor as number) to end of colorvalue
end repeat
set colorname to "TEST"
tell application "Adobe InDesign CS5"
activate
tell active document
set newcolor to make color with properties {name:colorname, space:CMYK, model:process, color value:colorvalue}
end tell
end tell
Why? Because it works. It is not pretty and it was not my first, or even 10th method to get the job done...Why this works? No idea...
It just does. You would think that:
set text item delimiters to ","
set {C,M,Y,K} to text items of primaryColor
...
set newcolor to make color with properties {name:colorname, space:CMYK, model:process, color value:{C,M,Y,K}}
Would do the trick, but it doesn't... I'm sure your attempts so far have proven just how much of a pain this particular function is.
You may also want to use the AppleScript “choose color” command, which presents a color picker, rather than presenting your user with a dialog into which they have to enter numeric color values.
This example inserts RGB colors as text into a BBEdit window, but you would use the same principle to insert CMYK colors as text into InDesign.
tell application "BBEdit"
activate
set theColorValues to choose color
set theR to round (the first item of theColorValues) / 257
set theG to round (the second item of theColorValues) / 257
set theB to round (the third item of theColorValues) / 257
set theRGBColor to "rgb(" & theR & ", " & theG & ", " & theB & ")"
set selection to theRGBColor
end tell
set primaryColor to text returned of (display dialog "Enter CMYK values of Primary Color (separated by commas e.g. 0,0,0,0)" default answer "") as string
set text item delimiters to ","
set colorvalue to {}
repeat with color from 1 to count of text items of primaryColor
copy (text item color of primaryColor as number) to end of colorvalue
end repeat
set colorname to primaryColor
tell application "Adobe InDesign CC 2017"
activate
tell active document
set newcolor to make color with properties {name:colorname, space:CMYK, model:process, color value:colorvalue}
end tell
end tell
I was writing a custom chart component where. To add labels, I create a spark label and add it on screen. Although all other labels rendered, I noticed that the zero label does not render at all. Here's my code:
var invisibleTextField:TextField = new TextField();
var zeroLabel:spark.components.Label = new spark.components.Label();
zeroLabel.text = "0";
zeroLabel.name = "0Label";
invisibleTextField.text = " 0 ";
zeroLabel.width = invisibleTextField.textWidth;
zeroLabel.height = invisibleTextField.textHeight;
addChild(zeroLabel);
After multiple attempts, I figure that the label discards "0" as an empty string. I managed to workaround using spaces before and after the zero. Only one space would also do, but I needed center aligning. Anyone has any idea why this happens?
There's a delay between text is filled into a text field and when it's dimensions are updated. Try using TextExtent instead of an invisible text field to do what you're doing.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextExtent.html