Is there no text vertical align property in famo.us? - vertical-alignment

It looks like in all the famo.us examples they use a really big lineHeight property to vertically align the text on a surface to the middle, whereas they use textAlign: "center" to align it horizontally. That seems problematic if there is no vertical align because if I want a paragraph of text the line height trick will screw that up.
Thanks!

This should be an easier question than it is but because of an issue with true-sizing surfaces, you may need to pull together a hack for this one.
The issue is that true-sized surfaces, cannot report their height to modifiers for properly calculating position at a given origin. You will have to set the actual height of the surface in order to achieve true centering.
In this example, The surface is centered in the entire context based on the size of the content. I subclassed the Surface so I could redefine deploy which takes the target element as the argument. I then set the size of the surface.state so that with its origin, it is able to center the element.
These are the types of issues that will be fixed soon, but a hack will have to do for now..
Here is the example.. Good Luck
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var StateModifier = require('famous/modifiers/StateModifier');
function MySurface(options) {
Surface.apply(this, arguments);
this._superDeploy = Surface.prototype.deploy
}
MySurface.prototype = Object.create(Surface.prototype);
MySurface.prototype.constructor = MySurface;
MySurface.prototype.deploy = function deploy(target) {
this._superDeploy(target);
var size = this.getSize();
var width = size[0] == true ? target.offsetWidth : size[0] ;
var height = size[1] == true ? target.offsetHeight : size[1] ;
this.state.setSize([width,height]);
};
var context = Engine.createContext();
var lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
var surface = new MySurface({
size: [200,true],
content: lorem,
properties: {
color: 'white',
textAlign: 'center',
backgroundColor: 'green'
}
});
surface.state = new StateModifier({origin:[0.5,0.5]});
context.add(surface.state).add(surface);

Related

mobile devices are not rending components created by Array.map() function, but it does render perfectly on laptops and desktops

I'm new to React and I hope somebody helps me understand how to solve this problem.
In my code below I'm retrieving product data from AliExpress's Dropshipping API; when I make the API call it returns an array with a set of information about 20 different products. from there, I want to use the map function to render a component that I've called "ProductCard" and pass the data points from the API call into the component as props. I believe this is what I've done in my code below, so when I check my app on a laptop or desktop device the code works as expected, but when I check my app on a mobile device the "ProductCard" component that the "productDisplay" function is responsible for creating dynamically does not render. What confuses me is that I only have this problem with small devices like mobile phones. Otherwise, my code works the way I want it to on larger devices like laptops or desktops. at first, I thought maybe there was something wrong with my phone, so I tried looking at it from other people's cell phones to see if the ProductCard component would render but it didn't.
I don't want to have to manually create the ProductCard components whenever I need to pull data from an API. so, can somebody please help me understand what I'm doing wrong and how to fix it? so that my ProductCard component can render properly on all devices, and can you please provide code examples in functional components instead of class components?
import SectionTitle from "../Base/SectionTitle";
import axios from "axios";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import ProductCard from "./ProductCard";
function EcommerceMarket() {
const [aliExpressData, setAliExpressData] = useState();
useEffect(() => {
let pageIsMounted = true;
if (pageIsMounted) {
let url;
if (process.env.NODE_ENV === "production") {
url = `${process.env.REACT_APP_PRODUCTION_URL}/guest/e-commerce-service`;
} else {
url = `${process.env.REACT_APP_DEV_URL}/guest/e-commerce-service`;
}
const options = {
method: "GET",
url: url
};
axios
.request(options)
.then((response) => {
const marketData = response.data.content;
// console.log(marketData);
const filteredData = marketData.filter((product) => {
if (product.image) {
const targetProduct = product;
return targetProduct;
}
});
return filteredData;
})
.then((filteredData) => {
//console.log(filteredData);
setAliExpressData(filteredData);
})
.catch((error) => {
console.error(error);
});
}
return () => {
pageIsMounted = false;
};
}, []);
const productDisplay = () => {
if (aliExpressData) {
const updatedCards = aliExpressData.map((product) => {
const id = product.productId;
const productImage = product.image.imgUrl;
const productTitle = product.title.displayTitle;
const price = `$ ${product.prices.salePrice.minPrice}`;
return <ProductCard key={id} image={productImage} title={productTitle} productid={id} price={price} />;
});
return updatedCards;
}
};
return (
<div className="e-commerce">
<SectionTitle title="e-commerce market" />
<Container className="e-commerce__content-container" fluid>
<Row className="e-commerce__row">
<Col className="e-commerce__product-display" xs={{ span: 12, order: 2 }} lg={{ span: 8, order: 1 }}>
{productDisplay()}
</Col>
<Col className="e-commerce__service-explanation" xs={{ span: 12, order: 1 }} lg={{ span: 4, order: 2 }}>
<h2 className="e-commerce__service-explanation__title">service description</h2>
<p className="e-commerce__Product-description">
<span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis optio sed reprehenderit officiis voluptatum fugiat quas iure facere voluptas repudiandae odio distinctio itaque animi omnis doloremque, delectus tempora. Nam, iste!</span>
<span>Molestias cupiditate itaque accusantium quisquam iusto placeat ipsa facere, molestiae perferendis, magni et? Deleniti quod illum id consectetur eius dolor nesciunt delectus recusandae modi, commodi ullam odit cumque sit maiores.</span>
</p>
<p className="e-commerce__Product-description">
<span>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Veniam, earum autem unde dolore enim alias soluta cum harum at quibusdam, quam in perferendis distinctio ducimus libero quos impedit officiis itaque.</span>
<span>Necessitatibus vero sequi modi officia praesentium delectus quibusdam architecto quas unde. Inventore, officiis animi officia sit consequuntur accusamus omnis cupiditate assumenda voluptatum consequatur numquam accusantium! Quos nulla tenetur voluptatibus ipsum.</span>
</p>
<p className="e-commerce__Product-description">
<span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur laboriosam maxime corrupti vitae nostrum, fugiat, iure, blanditiis harum exercitationem neque esse consectetur est quibusdam excepturi repudiandae mollitia voluptates qui repellendus?</span>
<span>Consequuntur necessitatibus, quidem sint, delectus expedita dolores dicta non modi est saepe distinctio debitis ut obcaecati animi omnis corrupti numquam! Quod iure quaerat, vero odit eveniet dolore ratione. Nam, laborum.</span>
</p>
</Col>
</Row>
</Container>
</div>
);
}
export default EcommerceMarket;

qtip doesn't format into bold?

I have this simple well-formed html like
<span><p><b>User: </b>USERNAME<br><strong>Date: </strong>from 28-04-2022 08:00:00 to 28-04-2022 16:00:00<br><strong></p></span>
and I passed to qtip but once I show the tip I see it doesn't apply bold formatting...indeed saving into a normal html file it works well.... shall I have to add some particular option?
In the specific with this javascript :
$(info.el).qtip({
content: { text: $.ajax({url:"http://"+window.location.host+"/...../my.php?action=load_eventdetails&ID="+info.event.id, async:false}).responseText },
position: { target: 'mouse', effect: false, viewport: .... , adjust: { x: 10, y: 10, method: 'flipinvert' } },
});
I call a php to obtain an html string:
<html><body><p><span><b>User: </b>Name Surname<br><b>Date: </b>from 04-03-2016 08:00:00 to 04-03-2016 16:00:00<br><b>Room: </b>Room 1 ()<br><b>Placement: </b><br><b>Services:</b><br><ol style='list-style-type: circle'><li style='font-size: 13px'>n° 1 - Lorem Ipsum</li><li style='font-size: 13px'>n° 6 - Lorem Ipsum</li><li style='font-size: 13px'>n° 1 - Lorem Ipsum</li><li style='font-size: 13px'>n° 1 - Lorem Ipsum</li><li style='font-size: 13px'>n° 6 - Lorem Ipsum</li></ol><div style='font-size: 13px;margin-bottom: 1px'><div style='float:left'><b>Price:</b></div><div style='float:right'>€ XX,00</div></div><br><div style='font-size: 13px;margin-bottom: 5px'><div style='float:left'><b>Lorem Ipsum:</b></div><div style='float:right'>€ XX.00</div></div><br><div style='font-size: 13px;margin-bottom: 5px'><div style='float:left'><b>Lorem Ipsum:</b></div><div style='float:right'>€ XX.00</div></div><br><div style='font-size: 13px;margin-bottom: 1px'><div style='float:left'><b>Lorem Ipsum:</b></div><div style='float:right'>€ XX,XX</div></div><br> <div style="font-size: 13px;margin-bottom: 1px"><div style="float:left"><img src=".../images/myimg.png" /> <b>STATUS</b></div></div> </span></p></body></html>
Where with a simple html file I get correctly the result with bold formatting where expected...
Thanks in advance!
Cheers! :-)

Custom cms element SW6

I'm building a custom theme for a client and looks like I am going to have to create custom blocks and elements, but it has been a nightmare to understand how Shopware 6 works.
I copied the cms image element under my theme folder, following the directory structure that the documentation points. I did it that way to not miss any code or part I could forget or skip and then just added some new fields in it to kind of extend that new custom element. It kind of worked at the end, I also touched the twig and scss files and I could see at the frontend this new custom element. But then I tried to use the image element that comes with Shopware, but now looks like it is overriden by this new custom element I was trying to create.
Under ../custom/plugins/MyTheme/src/Resources/app/administration/src/module/sw-cms/elements/customElement/ the root index.js file which worked as I needed was:
import './component';
import './config';
import './preview';
Shopware.Service('cmsService').registerCmsElement({
name: 'image', // This is key I think but don't understand the relation.
label: 'Custom Element',
component: 'sw-cms-el-custom-element',
configComponent: 'sw-cms-el-config-custom-element',
previewComponent: 'sw-cms-el-preview-custom-element',
defaultConfig: {
media: {
source: 'static',
value: null,
required: true,
entity: {
name: 'media'
}
},
displayMode: {
source: 'static',
value: 'standard'
},
url: {
source: 'static',
value: null
},
newTab: {
source: 'static',
value: false
},
minHeight: {
source: 'static',
value: '340px'
},
verticalAlign: {
source: 'static',
value: null
},
cardColor: { // This is a new field I added
source: 'static',
value: 'true'
},
cardContent: { // This is a new field I added
source: 'static',
value: `
<h2>Lorem Ipsum dolor sit amet</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
`.trim()
}
}
});
The code above makes my new custom element to work but then it overrides the image element entirely if I need to use that element somewhere else. I feel like the name: 'image' is the key here because then I replace it by another name let's say name: 'custom-element' and then the custom element didn't work at all, even though I copied the image element exactly as it is and just replaced it that name. The errors are related to the new fields I added, it says the values are undefined.
I have been reading some other people with the same issue and some guys talk about entities or resolvers but not sure how to follow that up.
Any advice would be appreciated. Thanks.

Visualization of tagged elements (collapsing, expanding, highlighting) in NLP

Hi all NLP researchers,
I have a sentence in which some tokens are tagged with a customized tagset (e.g. SUB, PRD, OBJ, etc.). The offset information of these tags is represented in XML-style file format(XMI) as below.
<?xml version="1.0" encoding="UTF-8"?><xmi:XMI xmlns:pos="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/pos.ecore" xmlns:tcas="http:///uima/tcas.ecore" xmlns:xmi="http://www.omg.org/XMI" xmlns:cas="http:///uima/cas.ecore" xmlns:tweet="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/pos/tweet.ecore" xmlns:morph="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/morph.ecore" xmlns:dependency="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/dependency.ecore" xmlns:type5="http:///de/tudarmstadt/ukp/dkpro/core/api/semantics/type.ecore" xmlns:type7="http:///de/tudarmstadt/ukp/dkpro/core/api/transform/type.ecore" xmlns:type6="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type.ecore" xmlns:type2="http:///de/tudarmstadt/ukp/dkpro/core/api/metadata/type.ecore" xmlns:type3="http:///de/tudarmstadt/ukp/dkpro/core/api/ner/type.ecore" xmlns:type4="http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore" xmlns:type="http:///de/tudarmstadt/ukp/dkpro/core/api/coref/type.ecore" xmlns:constituent="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/constituent.ecore" xmlns:chunk="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/chunk.ecore" xmi:version="2.0">
<cas:NULL xmi:id="0"/>
<type2:DocumentMetaData xmi:id="1" sofa="12" begin="0" end="28" language="x-unspecified" documentTitle="visualization-example2.txt" documentId="admin" documentUri="file:/C:/Users/Administrator/.webanno/repository/project/1/document/14/source/visualization-example2.txt" collectionId="file:/C:/Users/Administrator/.webanno/repository/project/1/document/14/source/" documentBaseUri="file:/C:/Users/Administrator/.webanno/repository/project/1/document/14/source/" isLastSegment="false"/>
<type4:Sentence xmi:id="19" sofa="12" begin="0" end="28"/>
<type4:Token xmi:id="23" sofa="12" begin="0" end="1"/>
<type4:Token xmi:id="32" sofa="12" begin="2" end="6"/>
<type4:Token xmi:id="41" sofa="12" begin="7" end="8"/>
<type4:Token xmi:id="50" sofa="12" begin="9" end="12"/>
<type4:Token xmi:id="59" sofa="12" begin="13" end="17"/>
<type4:Token xmi:id="68" sofa="12" begin="18" end="22"/>
<type4:Token xmi:id="77" sofa="12" begin="23" end="27"/>
<type4:Token xmi:id="86" sofa="12" begin="27" end="28"/>
<chunk:Chunk xmi:id="95" sofa="12" begin="0" end="1" chunkValue="SUB"/>
<chunk:Chunk xmi:id="100" sofa="12" begin="2" end="28" chunkValue="PRD"/>
<chunk:Chunk xmi:id="105" sofa="12" begin="2" end="6" chunkValue="VERB"/>
<chunk:Chunk xmi:id="110" sofa="12" begin="7" end="27" chunkValue="OBJ"/>
<chunk:Chunk xmi:id="115" sofa="12" begin="7" end="12" chunkValue="HED"/>
<chunk:Chunk xmi:id="120" sofa="12" begin="13" end="27" chunkValue="PP"/>
<type2:TagsetDescription xmi:id="125" sofa="12" begin="0" end="0" layer="de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency" name="UD Universal Dependencies"/>
<type2:TagsetDescription xmi:id="132" sofa="12" begin="0" end="0" layer="de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity" name="Named Entity tags"/>
<type2:TagsetDescription xmi:id="139" sofa="12" begin="0" end="0" layer="de.tudarmstadt.ukp.dkpro.core.api.transform.type.SofaChangeAnnotation" name="Operation"/>
<type2:TagsetDescription xmi:id="146" sofa="12" begin="0" end="0" layer="de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS" name="UD Universal POS tags"/>
<cas:Sofa xmi:id="12" sofaNum="1" sofaID="_InitialView" mimeType="text" sofaString="I want a dog with long hair."/>
<cas:View sofa="12" members="1 19 23 32 41 50 59 68 77 86 95 100 105 110 115 120 125 132 139 146"/></xmi:XMI>
What I want to do is to visualize these tags like below.
" I want a dog with long hair"
|_SUB_| |___________PRD_________________|
|_VERB_| |________OBJ___________|
|__HED__||_____PP______|
Plus, I want to collapse and expand these tags in every hierarchy like, PRD-> VERB OBJ; OBJ-> HED PP.
Also, I want to highlight the span every tags covers on the sentence when moving cursor hovering over the specific tag. (so, It would be best to be shown on GUI environment)
Basically, it is a binary tree structure, so I've looked for some related visualization packages in Python such as Dash and Plotly, but it seems doesn’t suit my particular needs very well.
I’d really appreciate any advice for this task, and any tips would be very helpful for me. Thanks.
You can use BALKANGraph javascript diagramming library to achieve requested functionality
OrgChart JS supports expand/collapse
I'm not sure exactly what you want to highlight but in the demo bellow only the parent node is highlighted you can use it as starting point to implement your own logic
OrgChart.templates.sentence = Object.assign({}, OrgChart.templates.ana);
OrgChart.templates.sentence.size = [520, 120];
OrgChart.templates.sentence.field_0 = '<text class="field_0" style="font-size: 24px;" fill="#ffffff" x="260" y="90" text-anchor="middle">{val}</text>';
OrgChart.templates.sentence.field_1 = '<text class="field_1" style="font-size: 16px;" fill="#ffffff" x="500" y="30" text-anchor="end">{val}</text>';
OrgChart.templates.sentence.node = '<rect x="0" y="0" height="120" width="520" fill="#039BE5" stroke-width="1" stroke="#aeaeae" rx="5" ry="5"></rect>';
var chart = new OrgChart(document.getElementById("tree"), {
nodeBinding: {
field_0: "type",
field_1: "text"
},
orientation: BALKANGraph.orientation.top_left,
tags: {
"sentence": {
template: "sentence"
}
},
links: [
{ from: 2, to: 1 },
{ from: 3, to: 1 },
{ from: 4, to: 3 },
{ from: 5, to: 3 },
{ from: 6, to: 5 },
{ from: 7, to: 5 }
],
nodes: [
{ id: 1, text: "I want a dog with long hair", type:"SENTENCE", tags: ["sentence"] },
{ id: 2, text: "I", type: "SUB" },
{ id: 3, text: "want a dog with long hair", type: "PRD" },
{ id: 4, text: "want", type: "VERB" },
{ id: 5, text: "a dog with long hair", type: "OBJ" },
{ id: 6, text: "a dog", type: "HED" },
{ id: 7, text: "with long hair", type: "PP" }
]
});
var nodeEelements = chart.getNodeElements();
for (var i = 0; i < nodeEelements.length; i++) {
nodeEelements[i].addEventListener("mouseover", function () {
this.classList.add("highlight");
var nodeId = this.getAttribute("node-id");
var parent = chart.nodes[nodeId].parent;
if (parent != null) {
chart.getNodeElement(parent.id).classList.add("highlight");
}
});
nodeEelements[i].addEventListener("mouseleave", function () {
this.classList.remove("highlight");
var nodeId = this.getAttribute("node-id");
var parent = chart.nodes[nodeId].parent;
if (parent != null) {
chart.getNodeElement(parent.id).classList.remove("highlight");
}
});
}
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
text-align: center;
font-family: Helvetica;
}
#tree {
width: 100%;
height: 100%;
}
.highlight rect{
fill: #F57C00 !important;
}
<script src="https://balkangraph.com/js/latest/OrgChart.js"></script>
<div id="tree"></div>

How to add text to pdf using javascript and pdfkit?

I installed pdfkit and now I am trying to add text to pdf and save it to disk. I am following tutorial from http://blog.nodeknockout.com/post/9134350698/countdown-to-ko-8-introduction-to-pdfkit but I keep getting an error below. How can I add a text using node.js and pdfkit?
thank you.
source code:
doc = new PDFDocument();
doc.moveTo(300, 75)
.lineTo(373, 301)
.lineTo(181, 161)
.lineTo(419, 161)
.lineTo(227, 301)
.fill('red', 'even-odd');
var loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in...';
doc.y = 320;
doc.fillColor('black')
.text(loremIpsum, {
paragraphGap: 10,
indent: 20,
align: 'justify',
columns: 2
});
doc.write('out.pdf');
error
/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:61
.text(loremIpsum, {
^
TypeError: Property 'text' of object [object PDFDocument] is not a function
at Object.createPDF (/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:61:5)
at /Users/sadmin/Dropbox/Node JS/wordlets/requestHandlers.js:62:15
at Request._callback (/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:116:5)
at Request.init.self.callback (/Users/sadmin/node_modules/request/main.js:122:22)
at Request.EventEmitter.emit (events.js:99:17)
at Request.<anonymous> (/Users/sadmin/node_modules/request/main.js:661:16)
at Request.EventEmitter.emit (events.js:126:20)
at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (/Users/sadmin/node_modules/request/main.js:623:14)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
at IncomingMessage._emitEnd (http.js:366:10)
It should be doc.text since you have other lines of code between the .fill call and .text, creating a syntax error.

Resources