How do I embed all icons within an array? - ruby

I am trying to get Squib to embed images. I have an excel doc (totm.xlsx) that has fields for Title, Gold, Description, etc. In the Excel doc, most of the cards have :A: or :M: in the description and I would like to replace those with a small SVG icon.
The following code coughs up 'unidentified local method [embed]' and a litany of other errors:
require 'squib'
Squib::Deck.new(cards: 54) do
background color: :white
data = xlsx file: 'totm.xlsx'
text str: data['Title'], x: 250, y: 55, font: 'Arial 12'
text str: data['Gold'], x: 65, y: 65, font: 'Arial 12'
text(str: data['Description'], x: 65, y: 600, font: 'Arial 12') do [embed]
embed.svg key: ':A:', width: 28, height: 28, file: 'battle-axe.svg'
embed.svg key: ':M:', width: 28, height: 28, file: 'burning-meteor.svg'
end
text str: data['Flavortext'], x: 65, y: 100, font: 'Arial 12'
text str: data['Type'], x: 65, y: 400, font: 'Arial 12'
save_sheet prefix: 'totm_sheet_', margin: 75, gap: 5, trim: 37
end
In the examples with embedding text, the code always uses a single named string, embed_text, but I would like to call an array of strings.
embed_text = 'Take 1 :tool: and gain 2 :health:.'
text(str: embed_text, font: 'Sans', font_size: [18, 32, 45],
x: 0, y: 0, width: 180, height: 300, valign: :bottom,
align: :left, ellipsize: false, justify: false, hint: :cyan) do |embed|
embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg'
embed.svg key: ':health:', width: 28, height: 28, file: 'glass-heart.svg'
end

You have brackets around your [embed]; as the code example shows, it should be using vertical bars, like |embed|.

Related

Scrollabel label is limited in text?

sorry to bother you. I have recently started devolping in Kivy and i am trying to show a scrollable text file in a window. The text comes from a .txt file, and a use the id of the label to put the string obtained from the file into the text field in the Label.
The problem i am having is that, althouugh kivy documentation firmely states that the label has no lines limit (by default), when i pass a certain number the text starts to be showed all in black as the picture i will attached. Before adding one more line to the .txt, the text can be read just fine but after adding the line the problem starts.
After adding the line
Before adding the line
Here is my code, the id of the label i am having troubles with is called "documento". Can some please tell me if there is some error in my label configuration or something else?
from kivy.lang import Builder
Builder.load_string('''
<RootWidget>:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
color: (0, 0, 0, 1.0)
background_color: (255, 255, 255, 1.0)
carousel: carousel
Carousel:
on_index: root.on_index(*args)
id: carousel
ignore_perpendicular_swipes: True
FloatLayout:
id: tab1
Label:
id: identification
text: ''
markup: True
color: (0, 0, 0, 1.0)
halign: 'left'
valign: 'top'
font_size: '18pt'
x: 100
y: -80
opacity: 0
Image:
id: avatar
source: 'assets/avatar.png'
keep_ratio: True
size_hint_x: 0.3
x: 60
y: -70
opacity: 0
Image:
id: banner
source: 'assets/banner.png'
keep_ratio: True
size_hint_x: 1
x: 0
y: 160
opacity: 0
Image:
id: lock
source: 'assets/lock.png'
FloatLayout:
id: tab2
Label:
id: asunto
text: 'Asunto: [b] Expdte. 234/98634987/54[/b]'
markup: True
color: (0, 0, 0, 1.0)
halign: 'left'
valign: 'top'
font_size: '18pt'
x: 40
y: 170
opacity: 0
Image:
id: votacion
size_hint_x: 0.2
x: 20
y: 80
opacity: 1
Label:
id: voto_text
text: '[b]VOTO POSITIVO[/b]'
markup: True
color: (0, 0, 0, 1.0)
halign: 'left'
valign: 'top'
font_size: '40pt'
y: 90
x: 40
opacity: 1
Image:
id: biometric_icon
source: 'assets/biometric.png'
keep_ratio: False
size_hint_x: 0.2
y: -90
x: 320
opacity: 1
Label:
id: confirm_label
text: 'CONFIRMACI\xc3\x93N BIOM\xc3\x89TRICA'
markup: True
color: (0, 0, 0, 1.0)
halign: 'center'
valign: 'top'
font_size: '10pt'
y: -190
x: 00
opacity: 1
FloatLayout:
id: tab3
ScrollView:
on_scroll_start: print("arranque")
on_scroll_move: print("me muevo")
on_scroll_stop: print("pare")
Label:
id: documento
text_size:700, None
size_hint_y: None
height: self.texture_size[1]
color: (0, 0, 0, 1.0)
Label:
id: debugger
text: ''
color: (0, 0, 0, 1.0)
halign: 'left'
valign: 'top'
width: 200
''')
I continue my search for a solution to this problem only to discover there was a limitation in my gpu for rendering the text, so the problem was that. So to sum-up and help everyone who is having the same problem, the limitation is not from kivy but from the gpu

C3js Area Range chart

Is it possible to create an Area range chart in C3.js similar to that of Highcharts? I've attached a screenshot and link to the live sample http://www.highcharts.com/demo/arearange-line.
The idea is to show range data, perhaps the historical high and low values, and then overlay the current year's values with a line chart. Can C3 do this?
Thanks in advance!
I don't think there is an area range graph option, but you might be able to fake it like so:
var chart = c3.generate({
data: {
columns: [
['data1', 300, 350, 300, 290, 225, 220],
['data2', 250, 320, 280, 250, 170, 180],
['data3', 230, 300, 240, 200, 150, 150]
],
types: {
data1: 'area',
data2: 'line',
data3: 'area'
},
colors: {
data1: 'rgb(215, 232, 248)',
data2: 'rgb(120, 178, 235)',
data3: '#ffffff'
}
},
point: {
r: 1
}
});
With css:
.c3-area {
opacity:1;
}
Here's a fiddle:
http://jsfiddle.net/ot19Lyt8/17/

resizing per storyboard issue swift

I am wondering if someone can show me how to write this code so it resizes automatically for different screen sizes. I have 4 storyboards with different screen sizes and just want a way to show the code, if this storyboard then (numbers change) follow this code, else (numbers chafe according to storyboard size) this code.
I already tried resizing by adding to each axis number for example / 568 * size.frame.height after each y and height axis and same for x and width of course, but the code becomes too long and complex to read.
Ideally I'd like an if statement saying if this screen size then it's storyboard 'this' then go to this code..
pianoButtonsWaterDropFrames = [
cNote: (CGRect(x: 33 , y: 40 , width: 20, height: 35), CGRect(x: 33, y: 360, width: 20, height: 35)),
dNote: (CGRect(x: 66 , y: 42 , width: 20, height: 35), CGRect(x: 66, y: 360, width: 20, height: 35)),
eNote: (CGRect(x: 99 , y: 41 , width: 20, height: 35), CGRect(x: 99 , y: 360, width: 20, height: 35)),
fNote: (CGRect(x: 132, y: 48, width: 20, height: 35), CGRect(x: 132, y: 360, width: 20, height: 35)),
gNote: (CGRect(x: 165, y: 39, width: 20, height: 35), CGRect(x: 165, y: 360, width: 20, height: 35)),
aNote: (CGRect(x: 198, y: 57, width: 20, height: 35), CGRect(x: 198, y: 360, width: 20, height: 35)),
bNote: (CGRect(x: 231, y: 60, width: 20, height: 35), CGRect(x: 231, y: 360, width: 20, height: 35)),
cFourNote: (CGRect(x: 263, y: 54, width: 20, height: 35), CGRect(x: 263, y: 360, width: 20, height: 35))
]
Any help would be appreciated !
You can use HAS answer in this question to check, which iPhone your app is running on. Then you can use a switch statement and call different methods:
let modelName = UIDevice.currentDevice().modelName
switch modelName{
case "iPhone 3G", "iPhone 3GS":
method1()
case "iPhone 4", "iPhone 4S":
method2()
default:
println("no size found")
}

The property of maxWidth does not work for the Chinese words

$('canvas').drawText({
fillStyle: '#36c',
fontStyle: 'bold',
fontSize: '20pt',
fontFamily: 'Trebuchet MS, sans-serif',
text: '一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十,一二三四五六七八九十。',
x: 50, y: 50,
maxWidth: 300
});
In the above example, "text wrap" is not working for the Chinese words. How do I solve this problem?

How could I draw a line inside several shapes in KineticJS?

In my application I have several shapes that intersect with each other, for example, Shape A, Shape B and Shape C. A need to draw a polyline from Shape A to Shape C through Shape B, so the line lies inside all the shapes and crosses them almost at center.
What is the most efficient way to implement this? Here is the code of example: http://jsfiddle.net/dselkirk/ZMUkE/.
I need to draw a yellow line, but not manually:
var stage = new Kinetic.Stage({
container: 'container',
width: 850,
height: 750
});
var layer = new Kinetic.Layer({
x: 0,
y: 0
});
var rect = new Kinetic.Rect({
x: 100,
y: 100,
width: 80,
height: 60,
fill: '#E67E22'
});
var rect2 = new Kinetic.Rect({
x: 640,
y: 70,
width: 40,
height: 70,
fill: '#3498DB',
});
var circle = new Kinetic.Circle({
x: 600,
y: 150,
radius: 70,
fill: '#2ECC71',
});
var polyOne = new Kinetic.Polygon({
x: 80,
y: 100,
points: [73, 192, 73, 160, 340, 23, 500, 109, 499, 139, 342, 93],
fill: '#9B59B6'
});
var polyTwo = new Kinetic.Polygon({
x: 100,
y: 160,
points: [-5, 0, 75, 0, 70, 10, 70, 60, 60, 90, 61, 92, 64, 96, 66, 100, 67, 105, 67, 110, 67, 113, 66, 117, 64, 120, 63, 122, 61, 124, 58, 127, 55, 129, 53, 130, 50, 130, 20, 130, 17, 130, 15, 129, 12, 127, 9, 124, 7, 122, 6, 120, 4, 117, 3, 113, 3, 110, 3, 105, 4, 100, 6, 96, 9, 92, 10, 90, 0, 60, 0, 10],
fill: '#e74c3c'
});
var imageObj = new Image();
imageObj.onload = function () {
var yoda = new Kinetic.Image({
x: 120,
y: 120,
image: imageObj,
width: 15,
height: 18
});
// add the shape to the layer
layer.add(yoda);
stage.add(layer);
};
imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/yoda.jpg';
var imageObj2 = new Image();
imageObj2.onload = function () {
var dart = new Kinetic.Image({
x: 650,
y: 80,
image: imageObj2,
width: 20,
height: 21
});
layer.add(dart);
stage.add(layer);
};
var yellowLine = new Kinetic.Line({
points: [{x:125,y:140},{x:125,y:280}, {x:425,y:150}, {x:555,y:220}, {x:655,y:100}],
stroke: 'yellow',
strokeWidth: 2,
lineJoin: 'round',
dashArray: [33, 10]
});
layer.add(polyOne);
layer.add(polyTwo);
layer.add(yellowLine);
layer.add(circle);
layer.add(rect);
layer.add(rect2);
stage.add(layer);
yellowLine.moveToTop();
For now I think the algorithm should be:
1) Find intersection points of all shapes.
2) Draw lines between these intersectiopn points. If any line point lies outside the shape - move it horizontally/vertically till it lies inside the shape.
But this algorithm seems not efficient at all.

Resources