So, Im trying to use a for in loop to generate some classes (using Stylus preprocessor).
I have defined an object like this:
$color = {
... (lot of properties) ...
product: {
product1 : {
base : #8c735e,
dark : #715544,
darkest : #674b3c
},
product2 : {
base : #a77c3e,
dark : #8f6129,
darkest : #835020
},
product2 : {
base : #6d91a4,
dark : #4d748c,
darkest : #416d88
},
}
... (lot of properties) ...
}
What I want to produce is the following:
.product-is--product1 {
h1, h2 { color: #715544; }
}
.product-is--product2 {
h1, h2 { color: #8f6129; }
}
.product-is--product3 {
h1, h2 { color: #4d748c; }
}
What I have tried is something like this:
products = product1, product2, product3;
for product in products {
.product-is {
&--{product} {
h1, h2 { color: $color.product[product].dark; }
}
}
}
This obviously doesn't work. Tried lot of different combinations and google, stack overflowed it, read the docs, etc, but nothing.
Does anybody know how can I access the $color object based on the value on the for ?
You can iterate right through the object, getting the key and the values like this:
$color = {
product: {
product1 : {
base : #8c735e,
dark : #715544,
darkest : #674b3c
},
product2 : {
base : #a77c3e,
dark : #8f6129,
darkest : #835020
},
product3 : {
base : #6d91a4,
dark : #4d748c,
darkest : #416d88
},
}
}
for $product_key, $product_colors in $color.product {
.product-is {
&--{$product_key} {
h1, h2 { color: $product_colors.dark; }
}
}
}
But I've tried the example you provided in the latest Stylus (0.52.4) and it works:
$color = {
product: {
product1 : {
base : #8c735e,
dark : #715544,
darkest : #674b3c
},
product2 : {
base : #a77c3e,
dark : #8f6129,
darkest : #835020
},
product3 : {
base : #6d91a4,
dark : #4d748c,
darkest : #416d88
},
}
}
products = product1, product2, product3;
for product in products {
.product-is {
&--{product} {
h1, h2 { color: $color.product[product].dark; }
}
}
}
As well as my first example both generate
.product-is--product1 h1,
.product-is--product1 h2 {
color: #715544;
}
.product-is--product2 h1,
.product-is--product2 h2 {
color: #8f6129;
}
.product-is--product3 h1,
.product-is--product3 h2 {
color: #4d748c;
}
Related
Highcharts | Network Graph - Is there a way to expand leaf nodes on click of the Parent node?
Sample Code`Highcharts.addEvent(
Highcharts.Series,
'afterSetOptions',
function (e) {
var colors = Highcharts.getOptions().color
i = 0,
nodes = {};
if (
this instanceof Highcharts.seriesTypes.networkgraph &&
e.options.id === 'lang-tree'
) {
e.options.data.forEach(function (link) {
if (link[0] === 'Parent') {
nodes['Parent'] = {
id: 'Parent',
marker: {
radius: 20
}
};
nodes[link[1]] = {
id: link[1],
marker: {
radius: 10
},
color: colors[i++]
};
} else if (nodes[link[0]] && nodes[link[0]].color) {
nodes[link[1]] = {
id: link[1],
color: nodes[link[0]].color
};
}
});
e.options.nodes = Object.keys(nodes).map(function (id) {
return nodes[id];
});
}
}
);`
Currently, this feature is not available to achieve from the API options without any customization.
Please take a look at this demo where you can find some custom functions to collapse the child nodes on the click event: https://jsfiddle.net/BlackLabel/9mv0ny3j/
point: {
events: {
click: function() {
var point = this;
point.linksFrom.forEach(link => {
if (link.toNode.isHidden) {
link.graphic.show();
link.toNode.graphic.css({
opacity: 1
});
link.toNode.dataLabel.css({
opacity: 1
})
link.toNode.isHidden = false;
} else {
link.graphic.hide();
link.toNode.graphic.css({
opacity: 0
});
link.toNode.dataLabel.css({
opacity: 0
})
link.toNode.isHidden = true;
}
})
}
}
},
API: https://api.highcharts.com/highcharts/series.line.events.click
I'm using https://github.com/HsuanXyz/ion2-calendar to generate a calendar in ionic. I can't make color changes to dates using dateconfig's cssClass.
Below is the code i'm using
` daysConfig() {
let _daysConfig = [
{
date:new Date(2018,0,1),
subTitle:'New Year\'s',
marked:false,
cssClass: 'my-cal'
},
{
date:new Date(2017,1,14),
subTitle:'Valentine\'s',
disable:true
},
{
date:new Date(2017,3,1),
subTitle:'April Fools',
marked:true
},
{
date:new Date(2017,3,7),
subTitle:'World Health',
marked:true
},
{
date:new Date(2017,4,31),
subTitle:'No-Smoking',
marked:true
},
{
date:new Date(2017,5,1),
subTitle:'Children\'s',
marked:true
}
];
_daysConfig.push(...this.days);
this.calendarCtrl.openCalendar({
from: new Date(2017,0,1),
to : new Date(2018,11.1),
daysConfig:_daysConfig
})
.then( (res:any) => { console.log(res) })
.catch( () => {} )
}`
css Class
.my-cal {
color: yellow
}
After a long RnD of almost 5 hour could solve this issue.
Please find the below solution in ionic
Define the below class in global.scss
.my-cal {
background-color: red !important;
}
and remember not to define this class anywhere else.
now use this in you days config as below:
let _daysConfig: DayConfig[] = [];
for (let i = 0; i < 31; i++) {
_daysConfig.push({
date: new Date(2020, 4, i + 1),
marked: false,
subTitle: `$${i + 1}`,
cssClass: 'my-cal'
})
}
Hope it will help someone :)
I just encountered the same problem, and I solved it by adding the follow style in the .scss file:
button.days-btn.my-cal {
p, small {
color: yellow;
text-decoration: underline;
font-weight: bold;
}
}
The cssClass is only added to the button that the <p> element containing the text is in.
So to properly change the color, you'll have to reference the <p> element first and assign the color to that.
Example
.ts
cssClass: 'my-cal'
.scss
.my-cal {
p {
color: green;
}
}
One of the solutions would be to add this code to your global scss/css style
ion-calendar { .my-cal{ background-color: #6E6B6B !important; p{ color: white !important; } }}
Later add "my-cal" class to wanted day.
I am trying to bind to value in defined class, to react on it change.
But no reaction happens. I extended object from data.Model, and trying to bind via links, but something doing wrong.
class with parameter:
Ext.define('Platform.core.OssStatusAdapter', {
extend : 'Ext.data.Model',
alternateClassName : [ 'OssStatusAdapter' ],
singleton : true,
fields : [ {
name : 'ossConected',
type : 'boolean',
defaultValue : false
} ]
});
Code in some class where value is changed:
OssStatusAdapter.set('ossConected',event.connected);
code where expect reaction to binding:
Ext.define('Plugin.scheduler.package.config.PackageConfigurationViewModel', {
extend : 'Ext.app.ViewModel',
...
links: {
ossAdapter: {
type: 'Platform.core.OssStatusAdapter',
create: true
}
},
...
formulas : {
canDeploy : {
bind : {
isOssUp : '{ossAdapter.ossConected}'
},
get : function(data) {
return data.isOssUp;
}
}
}
but in formula value is not changing.
What I missed?
Try to define your formula this way:
formulas: {
canDeploy: function(get) {
var connected = get('ossAdapter.ossConected');
// see if this moves when you change the record
console.log('connected', connected);
return connected;
}
}
I want to create a message dialog in the following way
For example:My combobox has 2 name, “chkbx”(symbolic name for the checkbox), “txtedt”(symbolic name for the text field).
Whenever i select chkbox or txtedt from combobox drop down list, then my combo box should connect me to actual checkbox and textedit element respectively.
I have a “show dialog” button on status bar when i press that button it should popup selected option(checkbox or line edit)
Please suggest me how can i do it.
EDIT Here is the code and the problem i am facing with combobox options is, neither i am not able to get icons in my message dialog nor i dont know how i can see checkbox or line edit in message dialog, i am a beginner and struggling to explore the tricky ways used in QML..
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.0
Item {
id: root
width: 580
height: 400
SystemPalette { id: palette }
clip: true
//! [messagedialog]
MessageDialog {
id: messageDialog
visible: messageDialogVisible.checked
modality: messageDialogModal.checked ? Qt.WindowModal : Qt.NonModal
title: windowTitleField.text
text: customizeText.checked ? textField.text : ""
informativeText: customizeInformativeText.checked ? informativeTextField.text : ""
onButtonClicked: console.log("clicked button " + clickedButton)
onAccepted: lastChosen.text = "Accepted " +
(clickedButton == StandardButton.Ok ? "(OK)" : (clickedButton == StandardButton.Retry ? "(Retry)" : "(Ignore)"))
onRejected: lastChosen.text = "Rejected " +
(clickedButton == StandardButton.Close ? "(Close)" : (clickedButton == StandardButton.Abort ? "(Abort)" : "(Cancel)"))
onHelp: lastChosen.text = "Yelped for help!"
onYes: lastChosen.text = (clickedButton == StandardButton.Yes ? "Yeessss!!" : "Yes, now and always")
onNo: lastChosen.text = (clickedButton == StandardButton.No ? "Oh No." : "No, no")
}
//! [messagedialog]
Column {
anchors.fill: parent
anchors.margins: 12
spacing: 8
Text {
color: palette.windowText
font.bold: true
text: "Message dialog properties:"
}
CheckBox {
id: messageDialogModal
text: "Modal"
checked: true
Binding on checked { value: messageDialog.modality != Qt.NonModal }
}
CheckBox {
id: customizeTitle
text: "Window Title"
checked: true
width: parent.width
TextField {
id: windowTitleField
anchors.right: parent.right
width: informativeTextField.width
text: "Alert"
}
}
Row {
Text {
text: "Combo box items and icon selection:"
}
spacing: 8
function createIcon(str) {
switch(str) {
case Critical:
messageDialog.icon = StandardIcon.Critical
console.log("Critical")
break;
case Question:
messageDialog.icon = StandardIcon.Question
break;
case checkbox:
//how to add checkbox here in order to show it in my message dialog ?
break;
case textedit:
//how to add textedit here in order to show it in message dialog ?
break;
default:
break
}
}
ComboBox {
id : cbox
editable: true
currentIndex: 0
model: ListModel {
id: cbItems
ListElement { text: "Critical"}
ListElement { text: "Question"}
ListElement { text: "checkbox"}
ListElement { text: "textedit"}
}
onCurrentIndexChanged: console.debug(cbItems.get(currentIndex).text)
onAccepted: parent.createIcon(cbItems.get(currentIndex).text)
}
}
CheckBox {
id: customizeText
text: "Primary Text"
checked: true
width: parent.width
TextField {
id: textField
anchors.right: parent.right
width: informativeTextField.width
text: "Attention Please"
}
}
CheckBox {
id: customizeInformativeText
text: "Informative Text"
checked: true
width: parent.width
TextField {
id: informativeTextField
anchors.right: parent.right
width: root.width - customizeInformativeText.implicitWidth - 20
text: "Be alert!"
}
}
Text {
text: "Buttons:"
}
Flow {
spacing: 8
width: parent.width
property bool updating: false
function updateButtons(button, checked) {
if (updating) return
updating = true
var buttons = 0
for (var i = 0; i < children.length; ++i)
if (children[i].checked)
buttons |= children[i].button
if (!buttons)
buttons = StandardButton.Ok
messageDialog.standardButtons = buttons
updating = false
}
CheckBox {
text: "Help"
property int button: StandardButton.Help
onCheckedChanged: parent.updateButtons(button, checked)
}
CheckBox {
text: "Close"
property int button: StandardButton.Close
onCheckedChanged: parent.updateButtons(button, checked)
}
CheckBox {
text: "Cancel"
property int button: StandardButton.Cancel
onCheckedChanged: parent.updateButtons(button, checked)
}
}
}
Rectangle {
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
height: buttonRow.height * 1.2
color: Qt.darker(palette.window, 1.1)
border.color: Qt.darker(palette.window, 1.3)
Row {
id: buttonRow
spacing: 6
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 12
width: parent.width
Button {
text: "Show Dialog"
anchors.verticalCenter: parent.verticalCenter
onClicked: messageDialog.open()
}
Button {
text: "Close"
anchors.verticalCenter: parent.verticalCenter
onClicked: messageDialog.close()
}
}
}
}
I still can't understand what are you going to do. Assume, you want some custom dialog with varying content. First of all, I guess MessageDialog is not good idea just because you cannot define custom controls inside it. But you can create a custom one.
Simple example:
Popup.qml
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
Window {
id: mypopDialog
title: "MyPopup"
width: 300
height: 100
flags: Qt.Dialog
modality: Qt.WindowModal
property int popupType: 1
property string returnValue: ""
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 20
Image {
source: popupType == 1 ? "combo.png" : "edittext.png"
}
Loader {
id: loader
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
sourceComponent: popupType == 1 ? comboboxComponent : editboxComponent
property string myvalue : popupType == 1 ? item.currentText : item.text
Component {
id: comboboxComponent
ComboBox {
id: comboBox
model: ListModel {
ListElement { text: "Banana" }
ListElement { text: "Apple" }
ListElement { text: "Coconut" }
}
}
}
Component {
id: editboxComponent
TextEdit {
id: textEdit
}
}
}
}
Rectangle {
height: 30
Layout.fillWidth: true
Button {
text: "Ok"
anchors.centerIn: parent
onClicked: {
returnValue = loader.myvalue;
mypopDialog.close();
}
}
}
}
}
Here I use Loader to load appropriate content according to popupType property (1 - combobox, 2 - textedit)
So now you can use this file in any place where you want.
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
Button {
text: "Test dialog"
onClicked: {
var component = Qt.createComponent("Popup.qml");
if (component.status === Component.Ready) {
var dialog = component.createObject(parent,{popupType: 1});
dialogConnection.target = dialog
dialog.show();
}
}
Connections {
id: dialogConnection
onVisibleChanged: {
if(!target.visible)
console.log(target.returnValue);
}
}
Here I use Connections to get back some result from the dialog. If you don't need it just remove the Connections item
You can use this
For example :
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
title: qsTr("main 4")
color: "white"
Button {
onClicked: customMessage.open();
}
// Create Object dialog box
Dialog {
id: customMessage
width: 300 // Set the width of the dialog, which works on the desktop, but it does not work on Android
height: 200 // Set the height of the dialog, which works on the dekstop, but does not work on Android
// Create the contents of the dialog box
contentItem: Rectangle {
width: 600 // Set the width, necessary for Android-devices
height: 500 // Set the height, necessary for Android-devices
color: "#f7f7f7" // Set the color
CheckBox { z: 1;text: 'check it!'}
ComboBox {
z: 1
anchors.right: parent.right
}
// The area for the dialog box message
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: dividerHorizontal.top
color: "#f7f7f7"
Label {
id: textLabel
text: qsTr("Hello, World!!!")
color: "#34aadc"
anchors.centerIn: parent
}
}
// Create a horizontal divider with the Rectangle
Rectangle {
id: dividerHorizontal
color: "#d7d7d7"
height: 2
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: row.top
}
Row {
id: row
height: 100 // Set height
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
Button {
id: dialogButtonCancel
anchors.top: parent.top
anchors.bottom: parent.bottom
// Set width button halfway line minus 1 pixel
width: parent.width / 2 - 1
style: ButtonStyle {
background: Rectangle {
color: control.pressed ? "#d7d7d7" : "#f7f7f7"
border.width: 0
}
label: Text {
text: qsTr("Cancel")
color: "#34aadc"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
onClicked: customMessage.close()
}
Rectangle {
id: dividerVertical
width: 2
anchors.top: parent.top
anchors.bottom: parent.bottom
color: "#d7d7d7"
}
Button {
id: dialogButtonOk
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width / 2 - 1
style: ButtonStyle {
background: Rectangle {
color: control.pressed ? "#d7d7d7" : "#f7f7f7"
border.width: 0
}
label: Text {
text: qsTr("Ok")
color: "#34aadc"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
onClicked: customMessage.close()
}
}
}
}
}
Note:
This is a cross post at:extjsForum
since I got no answer there,so I ask here.
Anyone who decide to answer this post can see the forum first to make sure if the question has been answer. :)
The following is my core code to make a Column chart to show the visitors and bytes of my website, however I found that I can not handle the label of the xAxis.
visitAndBytesStore = new Ext.data.JsonStore(
{
fields :
[
{
name : 'time',
type : 'string'
// dateFormat : 'Y-m-d H:i:s'
}, 'visits', 'bytes' ]
});
var visitAndBytesData =
[{"time" : "2010-09-17 16:24:06","visits" : "23","bytes" : "4545"},
{"time" : "2010-09-17 02:23:33","visits" : "3233","bytes" : "3232"},
{"time" : "2010-09-17 16:23:52","visits" : "456","bytes" : "3242342"},
{"time" : "2010-09-17 15:23:52","visits" : "6456","bytes" : "2314252"} ];
visitAndByteChart = new Ext.chart.ColumnChart(
{
store : visitAndBytesStore,
xField : 'time',
// xAxis : new Ext.chart.TimeAxis(
// {
// title : 'time',
// displayName : 'time',
// labelRenderer : function(dd)
// {
// // return dd.format("m-d")+"\n"+dd.format("H:i");
// return "";
// }
// }),
yAxis : new Ext.chart.NumericAxis(
{
displayName : 'Visits',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
series :
[
{
type : 'column',
displayName : 'Bytes',
yField : 'bytes',
style :
{
color : 0x99BBE8
}
},
{
type : 'line',
displayName : 'Visits',
yField : 'visits',
style :
{
mode : 'stretch',
color : 0x15428B
}
} ]
});
visitorAndBytesChartPanel = new Ext.Panel(
{
iconCls : 'chart',
title : ' ',
frame : true,
renderTo : 'bytes',
autoWidth : true,
height : 300,
layout : 'fit',
items : visitAndByteChart
});
As shown above if I use the "string" format of the "time" field, I can not handle the format of the time label in the chart, their value are too long (2010-09-20 23:00:00 is too long),so they are displayed by Automaticly chosed.
This is the result:
http://awesomescreenshot.com/0e41vu0c0
I want all of them displayed.
So I set the "time" field to "date" (Just remove the comments in the above codes),
And now the last label in the chart can not displayed completely,so is the "dot" in the chart which trig the tip event.
This is the result:
http://awesomescreenshot.com/04c1vtq94
Is there any problems?
extraStyle: {
padding: 20
}
From the Forum