Any RaphaelJS Guru knows how to draw this image? - raphael

Any Raphael JS guru (or any genius who doesn't know Raphael JS) knows how to simply draw this?
the solid yellow color is 4.2 / 10 of part of the circle.

First approach using svg's elliptical arc curve command
Demo: http://jsbin.com/iwuqe3/edit
Raphael.fn.zeroToTenArc = function (x, y, r, value) {
var set = this.set();
var pi = Math.PI;
var cos = Math.cos;
var sin = Math.sin;
var maxValue = 10;
var t = (pi/2) * 3; //translate
var rad = (pi*2 * (maxValue-value)) / maxValue + t;
var colors = ["#F79518", "#FCE6BF", "#FFF"];
set.push(this.circle(x, y, r).attr({ fill : colors[+!value], stroke : 0 }));
var p = [
"M", x, y,
"l", r * cos(t), r * sin(t),
"A", r, r, 0, +(rad > pi + t), 1, x + r * cos(rad), y + r * sin(rad),
"z"
];
set.push(this.path(p).attr({ fill : colors[1], stroke : 0 }));
set.push(this.circle(x, y, r*0.7).attr({ fill : colors[2], stroke : 0 }));
return set;
};
var canvas = Raphael("hello", 300, 300);
var arc = canvas.zeroToTenArc(150, 150, 30, 4.2);
.
Second approach using (a lot of) svg's lineto commands
Demo: http://jsbin.com/usotu5/edit
Raphael.fn.zeroToTenArc = function (x, y, radius, value) {
var angle = 0;
var endAngle = (value*360)/10;
var path = "";
var clockwise = -1;
var translate = Math.PI/2;
while(angle <= endAngle) {
var radians= (angle/180) * Math.PI + translate;
var cx = x + Math.cos(radians) * radius;
var cy = y + Math.sin(radians) * radius * clockwise;
path += (angle === 0) ? "M" : "L";
path += [cx,cy];
angle += 1;
}
return this.path(path);
};
var canvas = Raphael("hello", 200, 200);
canvas.zeroToTenArc(50, 50, 30, 10).attr({ stroke : "#FCE6BF", "stroke-width" : 12 });
canvas.zeroToTenArc(50, 50, 30, 4.2).attr({ stroke : "#F79518", "stroke-width" : 12 });

Related

'for' loop and 'lists' in plotly - R

I want to add some shapes to my chart:
p <- p %>% layout(shapes = list(list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_1, x0 = x0_1, x1 = x1_1, xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_2, x0 = x0_2, x1 = x1_2, xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_3, x0 = x0_3, x1 = x1_3, xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_4, x0 = x0_4, x1 = x1_4, xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
...
Can I have dynamic number od these shapes?
I prefer to have shapes in data frame with different x0, x1, fillcolor and opacity (or parameter permitting to draw or not) and use for ... loop rather than list them one by one like above?
rgds & thks
Grzegorz

Power BI Conditional formating: the formula works but does not apply to the visual

I have a formula to apply a front color according to the background color. Here it is:
FontColour =
// 1. Grab the background colour for the current row
VAR selectedColour = SELECTEDVALUE(FactIFSMANAGERS[BGColor])
// 2. Extract the hexadecimal value for each digit in each colour couplet, and translate to the decimal representation of that value
VAR redDig1 = MID(selectedColour, 2, 1)
VAR redDig1Number = SWITCH(redDig1,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
VAR redDig2 = MID(selectedColour, 3, 1)
VAR redDig2Number = SWITCH(redDig2,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
VAR greenDig1 = MID(selectedColour, 4, 1)
VAR greenDig1Number = SWITCH(greenDig1,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
VAR greenDig2 = MID(selectedColour, 5, 1)
VAR greenDig2Number = SWITCH(greenDig2,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
VAR blueDig1 = MID(selectedColour, 6, 1)
VAR blueDig1Number = SWITCH(blueDig1,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
VAR blueDig2 = MID(selectedColour, 7, 1)
VAR blueDig2Number = SWITCH(blueDig2,"0",0,"1",1,"2",2,"3",3,"4",4,"5",5,"6",6,"7",7,"8",8,"9",9,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15)
// 3. Assign the value of the Gamma exponent
VAR gamma = 2.2
// 4. Calculate the RGB values and normalize
VAR redNumber = ((redDig1Number * 16) + redDig2Number) / 255
VAR greenNumber = ((greenDig1Number * 16) + greenDig2Number) / 255
VAR blueNumber = ((blueDig1Number * 16) + blueDig2Number) / 255
// 5. Apply calculation as per Stack Exchange answer
VAR luminance = (0.2126 * POWER(redNumber, gamma)) + (0.7152 * POWER(greenNumber, gamma)) + (0.0722 * POWER(blueNumber, gamma))
// 6. If the luminance is greater than 0.5, return "Black". Else return "White".
RETURN IF(luminance > 0.5, "#000000", "#ffffff")
Presented as a table the formula works very well:
Formula in table
But once I switch to a bar visual the font color remains white when it should be black on light backgrounds.
Formula in bar
I did use the Fn function available in 'Data Labels' 'Values'
Does anyone have any idea why this is not working? First time I've encountered this type of problem.
Thank you for your help!

How to draw a radar scanning animation in osmdroid

I use polygon and set its fillpaint with RadialGradient,but it doesn't work!
val polygon = Polygon()
val pp = polygon.fillPaint
val xx = mapView.projection.toPixels(pointCenter, null).x
val yy = mapView.projection.toPixels(pointCenter, null).y
pp.shader = RadialGradient(xx.toFloat(), yy.toFloat(), radius.toFloat(), Color.GREEN, Color.RED, Shader.TileMode.MIRROR)
polygon.points = points
mapView.overlayManager.add(polygon)

What's the equivalent of np.delete in libtorch?

It seems we don't have an np.delete equivalent in libtorch yet, so how can we emulate its behavior? For example I'm trying to rewrite the following bit of code in libtorch:
ids = np.delete( ids, np.concatenate([[last], np.where(overlap > overlap_threshold)[0]] ) )
How should I go about this? I thought about slicing, but I'm not sure if there are implications involved that I'm not aware of. This is what I came up with:
neg = torch.where(overlap < overlap_threshold)[0]
ids = ids[neg].clone()
libtorch:
auto neg = torch::where(overlap <over_threshold)[0];
ids.index_put_({Slice()}, ids.index({neg}));
//or simply
ids = ids.index({neg}).clone();
And this is an example demo to test out their result is the same:
x1 = np.asarray([125.,152., 155., 155., 202.])
y1 = np.asarray( [52., 72., 92., 95., 95.])
x2 = np.asarray( [145., 172., 175., 175., 222.])
y2 = np.asarray( [ 72., 92., 112., 115., 115.])
score = np.asarray([0.60711509, 0.63444906, 0.85604602, 0.60021192, 0.70115328])
area = (x2 - x1 + 1.0) * (y2 - y1 + 1.0)
ids = np.argsort(score)
overlap_threshold = 0.5
mode = 'union'
while len(ids) > 0:
# grab index of the largest value
last = len(ids) - 1
i = ids[last]
# left top corner of intersection boxes
ix1 = np.maximum(x1[i], x1[ids[:last]])
iy1 = np.maximum(y1[i], y1[ids[:last]])
# right bottom corner of intersection boxes
ix2 = np.minimum(x2[i], x2[ids[:last]])
iy2 = np.minimum(y2[i], y2[ids[:last]])
# width and height of intersection boxes
w = np.maximum(0.0, ix2 - ix1 + 1.0)
h = np.maximum(0.0, iy2 - iy1 + 1.0)
# intersections' areas
inter = w * h
if mode == 'min':
overlap = inter / np.minimum(area[i], area[ids[:last]])
elif mode == 'union':
# intersection over union (IoU)
overlap = inter / (area[i] + area[ids[:last]] - inter)
# delete all boxes where overlap is too big
# ids = np.delete(ids,np.concatenate([[last], np.where(overlap > overlap_threshold)[0]]))
neg = np.where(overlap <= overlap_threshold)[0]
ids = ids[neg]
print(f'ids: {ids}')
And here is the cpp counter part in libtorch:
void test5()
{
auto x1 = torch::tensor({ 125., 152., 155., 155., 202. });
auto y1 = torch::tensor({ 52., 72., 92., 95., 95. });
auto x2 = torch::tensor({ 145., 172., 175., 175., 222. });
auto y2 = torch::tensor({ 72., 92., 112., 115., 115. });
auto score = torch::tensor({ 0.60711509, 0.63444906, 0.85604602, 0.60021192, 0.70115328 });
auto area = (x2 - x1 + 1.0) * (y2 - y1 + 1.0);
auto ids = torch::argsort(score);
auto overlap_threshold = 0.5;
auto mode = "union";
while (ids.sizes()[0] > 0)
{
//# grab index of the largest value
auto last = ids.sizes()[0] - 1;
auto i = ids[last];
//# left top corner of intersection boxes
auto ix1 = torch::max(x1[i], x1.index({ ids.index({ Slice(None,last) }) }));
auto iy1 = torch::max(y1[i], y1.index({ ids.index({ Slice(None,last) }) }));
//# right bottom corner of intersection boxes
auto ix2 = torch::min(x2[i], x2.index({ ids.index({Slice(None,last)}) }));
auto iy2 = torch::min(y2[i], y2.index({ ids.index({Slice(None,last)}) }));
//# width and height of intersection boxes
auto w = torch::max(torch::tensor(0.0), ix2 - ix1 + 1.0);
auto h = torch::max(torch::tensor(0.0), iy2 - iy1 + 1.0);
//# intersections' areas
auto inter = w * h;
torch::Tensor overlap;
if (mode == "min")
{
overlap = inter / torch::min(area[i], area.index({ ids.index({Slice(None,last)}) }));
}
else if (mode == "union")
{ //# intersection over union (IoU)
overlap = inter / (area[i] + area.index({ ids.index({Slice(None,last)}) }) - inter);
}
//# delete all boxes where overlap is too big
//# ids = np.delete(ids, np.concatenate([[last], np.where(overlap > overlap_threshold)[0]] ))
auto neg = torch::where(overlap < overlap_threshold)[0];
ids = ids.index({ neg });
std::cout << "ids: " << ids << std::endl;
}
}
Both of them print the same output, so is there something that I'm missing here or this is actually the reasonable way of implementing delete in libtorch?
What other possibly more efficient ways do I have to implement/emulate np.delete()?
It seems this is the reasonable way of doing it as pointed out in the comments. That is to reverse the condition and only filter out based on the new condition.
I also would like to fix a slight issue in my original post.
the correct form that would be equivalent to the Pythons :
ids = np.delete(ids, np.concatenate([[last], np.where(overlap > overlap_threshold)[0]] ))
would be :
auto neg = torch::where(overlap <= overlap_threshold)[0];
ids = ids.index({ neg });
mind the <=!

Python auto select color bar

I want to set color bar "green" when data direction1 = 005.
How to make it auto select color bar in Python 2.7 from these case?:
direction1=['200','250','180','200','300','270','005','080']
time1=['0000','0030','0100','0130','0200','0230','0300','0300']
Current script as follows :
ind = np.arange(len(time1))
width = 0.50
rects1 = plt.bar(ind, direction1, width, color='r')
for x in range(0,len(direction1)):
if x in direction1==005:
rects1[x].set_color('g')
This is the answer for sharing:
values=np.array(direction1)
searchval = '005'
location = np.where(values == searchval)[0]
print location
rects1 = plt.bar(ind, direction1, width, color='r')
for x in location:
rects1[x].set_color('g')
Cheers!!!...