I'm trying to put a script into jade, but it won't let me use multiple curly braces. Here is the chartist code I am trying to put in jade.
body
h1 Crimes by Category
.ct-chart
script(new Chartist.Bar('.ct-chart', {
labels: ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'],
series: [20, 60, 120, 200, 180, 20, 10]
}, {
distributeSeries: true
});)
I am getting Duplicate attribute "{" is not allowed. I don't know how to get around this. Any help would be appreciated.
To insert multi-line javascript in Jade, use the script. tag (with the content of the script indented):
body
h1 Crimes by Category
.ct-chart
script.
new Chartist.Bar('.ct-chart', {
labels: ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'],
series: [20, 60, 120, 200, 180, 20, 10]
}, {
distributeSeries: true
});
You probably also need to indent script. one notch if you want it inside your .ct-chart div.
source: How can I render inline JavaScript with Jade?
Related
Iam trying to learn how to program with KivyMD. After doing some research and watching some tutorials iam putting a GUI together with the trail-and-error approach.
At the moment iam trying to change the colors of the Tab text and icons. After hours of online searching iam still not able to change them. The text_color_normal:and text_color_active: in the .kv file simply
seems to have no effect on them. I have the feeling iam doing something fundamentally wrong here. Can somebody give me some tips how to proceed? Main.py and .KV file are below.
Thanks in advance!
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.tab import MDTabsBase
from kivymd.font_definitions import fonts
from kivymd.icon_definitions import md_icons
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
Window.size = (300, 500) # voor develop doeleinden mobielscherm
class Screen1(Screen):
pass
class Screen2(Screen):
pass
class Screen3(Screen):
pass
class Screen4(Screen):
pass
class Tab(FloatLayout, MDTabsBase):
pass
class Tab1(FloatLayout, MDTabsBase):
pass
class DemoApp(MDApp):
def build(self):
self.theme_cls.primary_palette = 'Red'
screen = Builder.load_file('demo_file.kv')
return screen
def navigation_draw(self):
print('navigation')
DemoApp().run()
demo_file.kv
Screen:
NavigationLayout:
ScreenManager:
id:screen_manager
Screen1:
name: 'home_screen'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'Home'
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
elevation: 0
specific_text_color: 0,0,0,1
MDTabs:
id:android_tabs
tab_bar_height: '35dp'
background_color: 1,0,0,0.85
elevation: 0
text_color_normal: 0, 1, 0, 1
text_color_active: 1, 0, 0, 1
color_indicator: 0.95, 0.95, 0.1, 1
Tab:
text: 'Tab1'
Tab1:
text: 'chart-pie'
MDBottomAppBar:
MDToolbar:
title: 'Start sessie'
mode: 'end'
type: 'bottom'
on_action_button: app.navigation_draw()
icon: 'beer'
icon_color: 0.95, 0.95, 0.1, 1
Screen2:
name: 'profile_screen'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'Profiel'
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
elevation: 7
Widget:
Screen3:
name: 'session_screen'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'Sessies'
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
elevation: 10
Widget:
Screen4:
name: 'logout_screen'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'Uitloggen'
left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
elevation: 10
Widget:
MDNavigationDrawer:
id:nav_drawer
BoxLayout:
orientation: 'vertical'
spacing: '8dp'
padding: '8dp'
Image:
source: 'avatar.jpg'
MDLabel:
text: ' Name'
front_style: 'Subtitle1'
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: ' email#hotmail.com'
front_style: 'Caption'
size_hint_y: None
height: self.texture_size[1]
ScrollView:
MDList:
OneLineIconListItem:
text: 'Profiel'
on_press: screen_manager.current = 'profile_screen'
IconLeftWidget:
icon: 'face-profile'
on_press: screen_manager.current = 'profile_screen'
OneLineIconListItem:
text: 'Drink sessies'
on_press: screen_manager.current = 'session_screen'
IconLeftWidget:
icon: 'beer'
on_press: screen_manager.current = 'session_screen'
OneLineIconListItem:
text: 'Uitloggen'
on_press: screen_manager.current = 'logout_screen'
IconLeftWidget:
icon: 'logout'
on_press: screen_manager.current = 'logout_screen'
<Tab>:
MDLabel:
text:'tab1'
user_font_size: "48sp"
pos_hint: {"center_x": .5, "center_y": .5}
<Tab1>:
MDLabel:
text:'tab2'
user_font_size: "48sp"
pos_hint: {"center_x": .5, "center_y": .5}
I finally figured out why my code was not working. While searching the web i stumbled across the change logs and i found out that the unreleased version contains a fix for text_color_normal and text_color_active. Which means that in my current version (0.104.1) the parameters did not work the way they should. Installing KivyMD with pip install https://github.com/kivymd/KivyMD/archive/master.zip works for me.
Thanks for your effort to solve this!
Change the color of the text/icon of the tabs? That is working for me.
Maybe try reinstall KivyMD.
test this instead : text_color : rgba(253, 0, 253,255)
it's worked for me
I'm trying to display data with TCPDF from my DB which were specifically indented.
I use a writeHTMLCell to do so.
e.g. :
"This should be indented as so :
- First bullet
- Second one
Then the end of the example."
But of course, it render the text on a single line.
Does anyone know how i can render the text properly ?
Thank you very much !
With HTML preformatted text requires that you use <pre>. Here is an example:
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
<pre>
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
</pre>
Using <pre> tags with the preformatted text block should achieve the result you are looking for. Preformatted text defaults to a monospaced font and can be changed with $pdf->SetDefaultMonospacedFont(). Here is an example with and without <pre>:
<?php
require_once('tcpdf_include.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$text_sample = 'This should be indented as so:
- First bullet
- Second one
Then the end of the example.';
$y = $pdf->getY();
$pdf->SetDefaultMonospacedFont('helvetica');
$pdf->SetFont('helvetica', '', 14, '', true);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(255, 92, 92);
$pdf->writeHTMLCell(190, '', '', $y, $text_sample, 1, 0, 1, true, 'J', true);
$pdf->SetTextColor(53,183,41);
$pdf->writeHTMLCell(190, '', '', $y+20, '<pre>'.$text_sample.'</pre>', 1, 1, 1, true, 'J', true);
$pdf->Output('example.pdf', 'I');
The PDF will contain the following cells:
I'm using justgage.1.0.1.js on my ASP page. I have configured colors for the progress line into 4 sectors like this:
var g1 = new JustGage({
id: "gauge1",
value: 0,
min: 0,
max: 100,
title: "Some Title",
showMinMax: 0,
label: '0 of 2',
levelColorsGradient: false,
countComplete: 0,
countTotal: 2,
levelColors: [ "#ff0000", "#ff9900", "#ffcc00", "#cccc00" ]
});
And in case countComplete = 0 it chows me an empty pipe with a grey background color:
What I need is to change this empty pipe's background to red, but only if countComplete equals 0 and countTotal is greater than 0. In all other cases the background should stay gray:
``
If this is possible to do, can you show me how to do it?
Already figured this out. To change the background of the gauge line, you just have to add a parameter to the gauge's body:
gaugeColor: "#ff0000"
I am using morris.js to create bar chart.But the size of bar is too wide.
Can you suggest how can i restrict the bar size?
Using the Java Script Code
var bar = new Morris.Bar({
element: 'bar-chart',
resize: true,
data: [
{y: '2012', a: 100, b: 90}
],
barColors: ['#00a65a', '#f56954'],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['CPU', 'DISK'],
hideHover: 'auto'
});
You can use barSizeRatio to control the width of the bars. So, when you have few bars e.g. less than 5, set barSizeRatio to 0.2. For more than 5 bars, let don't specify barSizeRatio, let the chart control figure it out.
jsfiddle http://jsfiddle.net/bv4xezh7/1/
Morris.Bar({
barSizeRatio:0.2,
element: 'chart',
data: [
{ date: '04-02-2014', value: 3 },
{ date: '04-03-2014', value: 10 },
],
xkey: 'date',
ykeys: ['value'],
labels: ['Orders']
});
You can make it more dynamic by figuring out the width of the chart control and then decide the value of barSizeRatio to meet your maximum bar width criteria.
I need to get the following 2d array from:
[[Option 10, 2.0], [Option 10, 2.0], [Option 9, 1.0], [Option 7, 1.0]]
to
[[Option 10, 2.0], [Option 9, 1.0], [Option 7, 1.0]]
I found this post (Splitting a 2D array using some() , by date, avoiding duplicates. Just want 1 unique email, not row. Where am i wrong here?) that has a very efficient way of getting unique values, but I cannot figure out how to apply it to my situation.
Your use case is simpler than the one you refer to.
try this for example :
function myFunction() {
var source = [['Option 10', 2], ['Option 10', 2], ['Option 9', 1], ['Option 7', 1]];
var dest = [];
dest.push(source[0]);
for(var n = 1 ; n< source.length ; n++){
if(dest.join().indexOf(source[n].join()) == -1){dest.push(source[n])};
}
Logger.log(dest);
}
Because 'unique' is not always simple to describe, I often use a pattern which is is, in effect, a variation of Serge's correct answer using ES5 array map/filter functions.
An edited version:
function hash(arr) {
// in this case the hash method is the same as Serge's Array.join() method,
but could be customised to suit whatever condition you need to generate
bespoke comparators such as where `1 + 3` should match `2 + 2`, or where
particular columns in the array can be omitted
return arr.join();
}
function myFunction() {
var source = [['Option 10', 2], ['Option 10', 2], ['Option 9', 1], ['Option 7', 1]];
var hash = source.map(
function (row) {
return hash(row);
}
);
source = source.filter(
function (filterRow, i) {
return hash.slice(0, i).indexOf(hash(filterRow)) < 0;
}
);
Logger.log(source);
}
I only include this as there are times when your comparison may need to flex a little. In your example this isn't important which is why Serge's is correct, but I share to show a potential expansion food for thought for when unique needs to be 'tweaked'