Is there a way to change the colour of a shape in a .docx document using python - jinja2

I am trying to automate a form filling process. I'm using jinja to fill in the text, however, I do have a circle in the document, when the x value if > 0.5, the circle should turn green, if its less that 0.5, the circle should turn red. Any idea how I could do this.

Related

Is there a way to determine whether there's a sufficient amount of space in a Pie chart segment for a label?

In the attached Google charts Pie chart the labels fit well inside the segments. Determining the length of a bit of text in HTML5 canvas is easy enough - but how do you determine whether the label will fit into a particular segment (using trigonometry) ? As you can see on the image, two of the segments don't have labels inside the segment.
EDIT: Here's an example of what I have at the moment: https://www.rgraph.net/tests/canvas.pie/in-pie-labels.html
As you see the labels for the small segments overlap. What I'm after is a way to calculate whether there's enough space for the labels at the point where they're going to be rendered. If not, I can just not draw the label like in the example image above.
Could chord size be useful to do this?
Here's the forumulae for the chord size that I found via Google:
"Chord length using trigonometry = 2 × r × sin(θ/2); where 'r' is the radius of the circle and 'θ' is the angle subtended at the center by the chord."
I sorted it (in about one hour) after 3 days of trying to calculate it with trig by using the built-in context.isPointInPath() function...
Draw the text (transparent color) to get the coordinates (x/y/w/h) of it. You might be able to get away with measuring it to get the width and height.
Draw the segment in a transparent color and do not stroke or fill it. Also, do not close the path.
Test each corner of the text rectangle (formed the x/y/w/h that you got above) using the context.isPointInPath() function. If the function returns true for each corner of the rectangle formed by the coordinates of the text, then the text will fit into the segment.

Stripes in background in RDL

Is it possible to add stripes in the textbox in report?
So the result looks like in the picture?
User chooses color for the column in the application
color
This is no built in way of doing this (no fill style) but you could use an image of the stripes as a background image. You would need to create and save images for each colour and style and add them as embedded images in the report.
You can then set the background image of a textbox to the required image.
... or better still use an expression to select the image based on conditions.
=SWITCH(
Fields!ItemCode.Value >10 , "RedStripe",
Fields!ItemCode.Value >50 , "GreenStripe",
True, Nothing
)
Where Redstripe and GreenStripe are the image names you embedded.
You can set the image to repeat etc from the properties panel
Update after OP stated that colour is parameterised.
If the colour is a parameter then we need a slightly different approach.
First you need to create an image with stripes (any colour will do ), and then remove the stripe pixels so that the stipes are now transparent. Save this as a PNG.
I created one quickly whist testing which you can save from here hopefully. You'll just have to move the mouse around in the area below as it's a white on white image! Or switch StackOverflow to the dark theme, then you can right-click and save the image. If not you'll just have to create one yourself.
Image below here.. switch StackOverflow to Dark theme to see it
Image above here..
Now you will need to set the background image to this image but also set the backgroundcolor property to an expression. In this exmaple, I set the background to the value of my parameter.
My parameter is just text and I typed in some hex values in the form #FFFFFF. You will have to work out how to get the value from your color pickers to the report yourself, ask a new question if required.
Here's the report design
and here is the report running using a few sample hex values.

How to render rotated groups of cells in MxGraph?

My question is about cells rotation - i'm trying to render scheme, with rotated groups of cells
First i tried to set rotation using style, and i found that selection rectangle renders incorrectly - without any angle
Then i found in source code vertexHandler rotate - this solution worked better, but it requires to render all elements, and only then - rotate them. Whole scheme with 100+ elements blinks every rerender
How to rotate selection rectangle, to render elements without blinking?

Identify color hex codes in a straight line

How can I programmatically ascertain the html color hex codes for colors in a single spectral line? I'm definitely using the wrong terminology I'm just not sure how else to phrase it. This picture should bring clarity:
Notice how the cursor in the top rectangle is always in the same position. It's simply the cursor in the first bar that moves into different color segments, thus generating the hex codes visible below.
Is it possible to generate these programmatically?
it would take 3 steps to get there programatically:
choose the base color (for each of your screen shots its the right top corner)
then lighten it to the the right amount (the X axis of your squares)
then darken it to the right amount (the Y axis of your squares)
if your'e using precompiled css like SASS it would look like that:
$someColor: red;
$lighten: brighten($someColor,20%);
$darkenedColor : darken($lighten, 32%);
$darkenedColor will get you the point that you are looking for, it will work for any given $someColor

Actionscript 3.0 drawRect works weird

I have a BitmapData object named myBitmapData. It was loaded of PNG of size 104x104. This PNG represents a red circle on the transparent background.
There is also a Sprite object named myBackground. I want render that red circle into myBackground.
myBackground.graphics.beginBitmapFill(myBitmapData);
myBackground.graphics.drawRect(0, 0, myBitmapData.width, myBitmapData.height);
myBackground.graphics.endFill();
addChild(myBackground);
Everything is fine. I see a red circle in the left top of myBackground.
But when I change the third line to
myBackground.graphics.drawRect(0, 52, myBitmapData.width, myBitmapData.height);
and expect my circle to be translated 52 pixels down, I actually obtain something strange (for me :)): there are two red half-circles (they form like hourglass).
So, the question is: how do I render myBitmapData into the random position of myBackground?
P.S.
In the case of
myBackground.graphics.drawRect(0, 104, myBitmapData.width, myBitmapData.height);
it is circle again :)
This is caused by beginBitmapFill's default repeat = true parameter. There's an example in the docs. Disabling the repetition won't work though, you'd just get a half circle then.
There are several ways to fix this:
Use a Matrix with a translation (displacement) as argument in beginBitmapFill.
Draw the rectangle at 0,0 on another Sprite, and move that sprite to where you want it on the background.
Don't draw directly to the background, but to another bitmap using copyPixels. Then fill the background with that bitmap.