Storm-React-Diagram Demo custom link 1 - reactjs

Expected outcome:
I was trying to to achieve this feature using storm react diagram. (click this link to show demo)
The Desired outcome:
convert the TypeScript to JavaScript should work, but it keep having error.
Problem:
however I ran into an error when converting this typescript to JavaScript (see below code block)
import * as SRD from 'storm-react-diagrams';
// setup diagram engine
this.engine = new SRD.DiagramEngine();
this.engine.installDefaultFactories();
//
const pathfinding = this.engine.getLinkFactories().getFactory<SRD.PathFindingLinkFactory>SRD.PathFindingLinkFactory.NAME;
What I have tried,
const pathfinding = this.engine.getLinkFactories().getFactory(PathFindingLinkFactory.NAME);
but I got this error instead
Full disclosure, I have posted this on GitHub too.

Solved.
const pathfinding = this.engine.getLinkFactories()[PathFindingLinkFactory.NAME];

Related

GlobalWorkerOptions of undefined for a React-Typescipt-Electron app

I'm trying to use pdfjs-dist's example for a Typescript-React-Electron app.
import pdfjsLib from 'pdfjs-dist';
pdfjsLib.GlobalWorkerOptions.workerSrc = 'src/node_modules/pdfjs-
dist/build/pdf.worker.js';
I get GlobalWorkerOptions of undefined.
Based on what I found here
in package.json I've put:
"source": "src/app/components/pdfHandling/entry/entry.js",
where src/app/components/pdfHandling/entry/entry.js:
import * as pdfjs from 'pdfjs-dist';
pdfjs.GlobalWorkerOptions.workerSrc = 'pdf.worker.js';
export {
pdfjs,
};
I posted the same problem in Mozilla's GitHub. And this is the answer I received:
The standalone examples in our repository work, so this must be some
integration issue with React/Electron, for which we cannot provide
assistance since we're not familiar with them. I would suggest to ask
on StackOverflow or other React/Electron-specific forums instead.
Any ideas about how to make pdfjs.GlobalWorkerOptions working?
The problem was silly and subtle....
It is enough to substitute
import * as pdfjs from 'pdfjs-dist';
with
var pdfjsLib = require("pdfjs-dist");
to make the problem disappearing....

Azure Maps - Cluster Pie Chart Markers in Perspective View

I am trying to utilize the Azure Maps Cluster Pie Chart feature with on a map in a Perspective mode, and this does not appear to be possible.
Is there a way to implement this feature in Perspective mode?
https://azuremapscodesamples.azurewebsites.net/HTML%20Markers/HtmlMarkerLayer/Clustered%20Pie%20Chart%20HTML%20Markers.html
I found the bug in the HtmlMarkerLayer class. It's actually being caused by a bug deeper within the SDK itself which I have reported to the team but will take some time to get resolved. In the mean time, here is a workaround you can implement to resolve the issue in your app:
Open the HtmlMarkerLayer.ts file I'll refer to the line numbers in the file I just linked.
At line 289 there is a line of code that looks like this:
var shapes = this._map.layers.getRenderedShapes(null, this, this._options.filter);
Replace this line with the following code:
const source = this.getSource();
const sourceId = (typeof source === 'string')? source : source.getId();
//#ts-ignore
const shapes = this._map.map.querySourceFeatures(sourceId, {
sourceLayer: this.getOptions().sourceLayer,
filter: opt.filter
});

CommonJS require vs. ES6 import discrepancy

So, I am new to React. Apologies if I am missing something obvious, I'm wrestling with a weird issue with my ES6 imports.
I'm using the #typeform/embed module (0.12.1), which oddly links to a GitHub repo on npm but that repo doesn't exist. So I haven't been able to look into potentially related issues.
Anyways, whenever I do the following:
import typeformEmbed from '#typeform/embed'
My text editor shows that the type of typeformEmbed is a string, and when I go to invoke a function on it, it is always undefined. Gives me the 'ole cannot invoke property X on undefined TypeError. It almost looks as if it is trying to import the README?
But, then I opened up my Node REPL and could write:
const typeformEmbed = require('#typeform/embed')
and it works like a charm.
Is there some discrepancy between the two that I am missing?
Edit: I know that this question is pretty text-heavy, let me know if there is crucial information that I'm missing. I should mention that I built this project with create-react-app.
import * as typeformEmbed from '#typeform/embed';
const popUpHandler = () => {
typeformEmbed.makePopup(
'https://admin.typeform.com/to/PlBzgL',
{
mode: 'drawer_left',
autoOpen: true,
autoClose: 3,
hideScrollbars: true,
onSubmit: function () {
console.log('Typeform successfully submitted')
}
}
)}
Should work for you

Setting up PDF.js to work with Meteor + Reactjs project (want to use text layer)

I've been working on a project using Meteor and React, which needs a PDF viewer with the ability to select text.
I'm currently trying to achieve this with Mozilla's PDF.js, but am having some trouble getting started. I'm a long time reader, first time asker at stackoverflow.
I've installed PDF.js with npm.
npm install pdfjs-dist --save
Now I'm trying to modify the example from pdf.js's github project here to create a React component that will render a PDF from a supplied file path and include a text layer.
imports/ui/components/PDF/PDFText.jsx
import React from 'react';
require ('pdfjs-dist/build/pdf.combined');
require ('pdfjs-dist/web/compatibility');
export default class PDFText extends React.Component {
renderPDF() {
PDFJS.workerSrc = '/node_modules/pdfjs-dist/build/pdf.worker.js';
const container = document.getElementById('pdf-container');
const scale = 1;
const pageNumber = 1;
PDFJS.getDocument(this.props.file).then(function(pdf) {
return pdf.getPage(pageNumber).then(function(page) {
var pdfPageView = new PDFJS.PDFPageView({
container: container,
id: pageNumber,
scale: scale,
defaultViewport: page.getViewport(scale),
textLayerFactory: new PDFJS.DefaultTextLayerFactory()
});
pdfPageView.setPdfPage(page);
return pdfPageView.draw();
});
});
}
render() {
this.renderPDF()
return (
<div id='pdf-container'></div>
);
}
}
If I include this component in page I get the following error:
Uncaught (in promise) TypeError: PDFJS.DefaultTextLayerFactory is not a constructor
The next thing I tried was including 'pdfjs-dist/web/pdf_viewer' in my code, as this is where DefaultTextLayerFactory is declared. I modified the code above to add the following line above the class declaration:
require ('pdfjs-dist/web/pdf_viewer');
When I run the code now, I get a different error.
Uncaught TypeError: Cannot read property 'PDFJS' of undefined
at Object.<anonymous> (modules.js?hash=9dd20a3…:114918)
at __w_pdfjs_require__ (modules.js?hash=9dd20a3…:114838)
at Object.<anonymous> (modules.js?hash=9dd20a3…:117449)
at __w_pdfjs_require__ (modules.js?hash=9dd20a3…:114838)
at Object.<anonymous> (modules.js?hash=9dd20a3…:118157)
at __w_pdfjs_require__ (modules.js?hash=9dd20a3…:114838)
at module.exports (modules.js?hash=9dd20a3…:114884)
at modules.js?hash=9dd20a3…:114887
at webpackUniversalModuleDefinition (modules.js?hash=9dd20a3…:114811)
at pdf_viewer.js (modules.js?hash=9dd20a3…:114818)
I'm really unsure what is going on here. I noticed that the function complaining refers to webpack - which I haven't been using.
I've also tried including the following check at the start of my code (this is taken from pageviewer.js in the github link above).
if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the pdfjs-dist library using\n' +
' `gulp dist`');
}
My code does in fact trigger that alert (PDFJS.PDFViewer is undefined) but the message doesn't seem correct as I installed the built pdfjs-dist library using npm. That message seems for people who cloned the repo. There isn't a gulp file in the pdfjs-dist directory - which makes sense.
I'm sure part of thep problem is that I'm experimenting with a lot of new tools here. This is my first time working with meteor, react, node, and pdf.js, so apologies in advance if I've made an obvious rookie mistake.
For the record I've tried a few other libraries, including:
mikecousins/react-pdf-js (worked reasonably well for simply displaying a pdf with no text layer).
peerlibrary/meteor-pdf.js (I hit some errors with this one as well, and I didn't pursue it too much further as the repo hasn't been touched in a couple of years).
Hopefully that's enough information for someone to spot the issue. My theory is that there's some other set up step I need to do to get this working for meteor or react (and that's why it hasn't been obvious from the "getting started" in the PDF.js website.
Also, I'm not locked in to PDF.js, so if the easiest solution to my problem is to use something else, I'd be happy to try that.
Thanks for your time

NativeScript Typings

I'm working through the NativeScript getting started tutorial in TypeScript:
http://developer.telerik.com/featured/getting-started-nativescript/
In one snippet of code, I see:
exports.loadSignUpView = function(args) {
page = args.object;
page.bindingContext = journeyInfo;
}
After some research I was able to type args as
import app = require("application");
exports.loadSignUpView = function(args: app.ApplicationEventData) {
//...
}
But that still does not help me type the page object above, which has the bindingContext property. What is the TypeScript type that corresponds to the page?
Page type is defined in the "ui/page" module and the type of the args of the loaded event is EventData (from the "data/observable" module).
So you can do something like this:
import observable = require("data/observable");
import pages = require("ui/page");
// Event handler for Page "loaded" event attached in main-page.xml
export function loadSignUpView (args: observable.EventData) {
// Get the event sender
var page = <pages.Page>args.object;
}
Few more useful tips to get you started:
NativeScript has TypeScript support build in since the 1.5 release. You can now use the NativeScript CLI to setup typescript project. You can check the documentation for more.
In the documentation there is more up to date getting-started guide
All of the code snippets in the docs have also a TypeScript version so that you can see the typings there - we love typescript ;)

Resources