SublimeText API - shifting the region position? - plugins

This has been super annoying because it's the last thing that needs to be fixed before the Sublime plugin is ready.
An HSLa converter. The goal is to do this, example:
Before:
color : #000;
After (intended):
color: #000;
color : hsla(...);
But I get this:
color : hsla(...);
color: #000;
Wrong order.
The routine:
duplicate the original region.
insert the converted hsla equivalent.
But it is referencing the original region position, so the inserted HSLa always ends up first. It needs to end up second since the HEX should come first as a CSS fallback.
I need to shift the region either down before inserting. Not clear from the Sublime API how to do this. Or if you have another solution?
Tnx, help appreciated.
----------- code --------
for region in selection:
if not region.empty():
line = self.view.line(region)
line_str = '\n' + self.view.substr(line) // HEX/RGB fallback
self.view.insert(self.edit, line.end(), line_str)
word = self.view.substr(region)
css_hsl = convert_to_hsl(word,force_alpha) // HSLa equivalent
if isinstance(css_hsl, str):
self.view.replace(self.edit, region, css_hsl)

Related

Is there a way to get the ECharts series symbol to be passed in as the marker in the tooltip

I've got an ECharts chart that has multiple line series and a scatter series that represents events. For the line series, we left the symbol at the default, but for the event scatter series we set the symbol to 'diamond'. These symbols show up on the chart & in the series legend as expected. However, the tooltip always shows a 10 pixel dot for the marker. The color however is picked up from the series (and even from the visualMap config!). My initial assumption had been that the symbol would also be picked up from the series. In our case we wanted to use a function for tooltip.formatter and even in that function we couldn't figure out how to access and swap in the series symbol for the marker. We ended up working around it by just custom styling our own html to plug in for the marker that matched the diamond symbol pretty well.
So the open questions are:
Is there a way to have the tooltip marker pick up the symbol from the series?
If not, is this a bug? I'm happy to put in an issue on the project but I don't want to do that until I understand a bit more.
Here's some code to illustrate what we had to do to get the diamond in there in case it helps the discussion or if others want to leverage this workaround:
formatTooltip(args){
let time = DateTime.fromISO(args[0].data[0], { zone: this.user.timeZone })
let tooltip = `<div><b>${time.toFormat(TOOLTIP_FORMAT)}</b></div>`
args.forEach(({ marker, seriesName, value }) => {
if (seriesName === 'Events'){
let myMarker = `<span style="display:inline-block;margin-right:4px;width:10px;height:10px;background:${value[4]};transform:rotate(45deg);"></span>`
tooltip += `<div>${myMarker} ${value[3] ? value[3]: ''}</div>`
} else {
value = value || [0, 0]
tooltip += `<div>${marker} ${seriesName}: ${value[1]}</div>`
}
})
return tooltip
},

Removing x number of characters from the caret position in tinyMCE

I am working on a project where the user can enter a special character and then tab to auto complete the values. This part is mostly working, but I want to be able to delete x number of characters from before the caret position.
E.g. if | is the caret and I have the following text #chr|.
I want to be able to delete 3 characters before the cursor position, e.g. I would just end up with #.
I have found a way to get the current cursor position using the below code, but I haven't been able to find any way of being able to delete x number of characters from that position.
function getCaretPosition()
{
var ed = tinyMCE.get('txtComment'); // get editor instance
var range = ed.selection.getRng().startOffset; // get range
return range;
}
You can do this by creating a Range ending at the current caret position:
var ed = tinyMCE.get("mce_0"); // get editor instance
var editorRange = ed.selection.getRng(); // get range object for the current caret position
var node = editorRange.commonAncestorContainer; // relative node to the selection
range = document.createRange(); // create a new range object for the deletion
range.selectNodeContents(node);
range.setStart(node, editorRange.endOffset - 3); // current caret pos - 3
range.setEnd(node, editorRange.endOffset); // current caret pos
range.deleteContents();
ed.focus(); // brings focus back to the editor
To use the demo, position the caret somewhere in the text and then click the "Remove 3" button at the top to delete the preceding 3 characters.
Note that my demo is simplified and doesn't do any bounds checking.
Demo: http://codepen.io/anon/pen/dWVWYM?editors=0010
Compatibility is IE9+

Unicode Character for Funnel to Signify Filtering

Is there a unicode character that signifies filtering (for example, a funnel) that is widely available on common computer operating systems?
Some of the most similar chars I've found so far:
∀, ∨, ∇, ▼, Y, Ⴤ, V, ᗊ, ⑂,
ツ
You can use search engines that allow you to draw like
http://shapecatcher.com/
http://www.mausr.com/
http://detexify.kirelabs.org/classify.html
I'm not able to find anything similar to the funnel but here are some possible results:
Turned shogi piece: ⛉ ⛊
Sector: ⌔
Down-pointing triangle with right half black: ⧩
Alchemical symbol for water: 🜄
Alchemical symbol for horse dung: 🝖
Canadian syllabics carrier hee: ᐶ
Rightwards arrow through superset ⭄
Subset above rightwards arrow ⥹
Rightwards arrow through greater-than ⭃ (probably should be rotated when display)
Greater-than above rightwards arrow ⥸
Rightwards arrow with tail ↣
Z notation range antirestriction ⩥
Excel does have a funnel shape when filtering data (see the icon in the c column above "7" in the below table) but I'm not sure whether they use an image or character for that since window inspection tools can't work out that symbol
In some cases the scissors ✀ can be used to signify "cut out unnecessary parts"
This is not really an answer, but possibly useful for anyone finding this page looking for a filter funnel icon. Here's a hack to make something look like a funnel - stack a triangle and a bar!
.filter-triangle,
.filter-bar {
position: absolute;
top: 0;
left: 0;
width: 1em;
text-align: center;
}
.filter-bar {
top: 0.1em;
}
<div class=filter-bar>❘</div>
<div class=filter-triangle>▼</div>
Alternatively this is an SVG icon I made:
<svg viewBox="0 0 80 90" focusable=false><path d="m 0,0 30,45 0,30 10,15 0,-45 30,-45 Z"></path></svg>
Both need aria attributes for accessability, amongst other problems! Both snippets are WTFPL-licenced!
Or you can use the MIT licenced filter icon from Feather.
I usually use the following:
y filter
Y active filter
¥ cancel or disable filter
Late here, but I like this ⫧
Found it by using shapecatcher.com which someone here suggested.
It works particularly well as a small placeholder in the inputs for my column filters.
(image)
https://unicode-table.com/en/2AE7/
I needed the same, and as far as I can tell there is no FUNNEL, FILTER or REDUCE symbol in Unicode.
However there is this:
⊆ U+2286 SUBSET OF OR EQUAL TO
You can use the character "X" with the Webdings Font, and it will give you a Speaker icon. Rotate it 90° and it'll be like a Funnel.
There is a proposal for a funnel (filter):
https://www.unicode.org/wg2/docs/n5181-repertoire-postAmd1.pdf
1CE08
Until it is released, the best character is the one provided by #phuclv (https://stackoverflow.com/a/51728429/5390321)
🝖 (1F756)
This is the best character I could find for myself ⊕
Unicode Character 'CIRCLED PLUS' (U+2295)
Which is by no means a funnel, but a kind of like a cross-hair insinuating "target more specific results". There are literally thousands of characters though...
In my case, I am going to use IcoMoon to replace the icon for this character, check out the IcoMoon app here
If you dont have a character map tool, you can use this quick PHP snippet to print out a range of unicode characters:
<?php
for ($i=hexdec("25ff");$i<=hexdec("26ff");$i++) echo sprintf("&#%u; ",$i);
Prints
◿ ☀ ☁ ☂ ☃ ☄ ★ ☆ ☇ ☈ ☉ ☊ ☋ ☌ ☍ ☎ ☏ ☐ ☑ ☒ ☓ ☔ ☕ ☖ ☗ ☘ ☙ ☚ ☛ ☜
☝ ☞ ☟ ☠ ☡ ☢ ☣ ☤ ☥ ☦ ☧ ☨ ☩ ☪ ☫ ☬ ☭ ☮ ☯ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷ ☸ ☹ ☺ ☻
☼ ☽ ☾ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇ ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ♔ ♕ ♖ ♗ ♘ ♙
♚ ♛ ♜ ♝ ♞ ♟ ♠ ♡ ♢ ♣ ♤ ♥ ♦ ♧ ♨ ♩ ♪ ♫ ♬ ♭ ♮ ♯ ♰ ♱ ♲ ♳ ♴ ♵ ♶ ♷ ♸ ♹
♺ ♻ ♼ ♽ ♾ ♿ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚆ ⚇ ⚈ ⚉ ⚊ ⚋ ⚌ ⚍ ⚎ ⚏ ⚐ ⚑ ⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘
⚙ ⚚ ⚛ ⚜ ⚝ ⚞ ⚟ ⚠ ⚡ ⚢ ⚣ ⚤ ⚥ ⚦ ⚧ ⚨ ⚩ ⚪ ⚫ ⚬ ⚭ ⚮ ⚯ ⚰ ⚱ ⚲ ⚳ ⚴ ⚵ ⚶ ⚷ ⚸
⚹ ⚺ ⚻ ⚼ ⚽ ⚾ ⚿ ⛀ ⛁ ⛂ ⛃ ⛄ ⛅ ⛆ ⛇ ⛈ ⛉ ⛊ ⛋ ⛌ ⛍ ⛎ ⛏ ⛐ ⛑ ⛒ ⛓ ⛔ ⛕
⛖ ⛗ ⛘ ⛙ ⛚ ⛛ ⛜ ⛝ ⛞ ⛟ ⛠ ⛡ ⛢ ⛣ ⛤ ⛥ ⛦ ⛧ ⛨ ⛩ ⛪ ⛫ ⛬ ⛭ ⛮ ⛯ ⛰ ⛱
⛲ ⛳ ⛴ ⛵ ⛶ ⛷ ⛸ ⛹ ⛺ ⛻ ⛼ ⛽ ⛾ ⛿
Good luck
While it won't be a funnel, I would suggest to use the web symbol: 🕸
After all, a web allows to catch the resource after which its user is looking for while letting much of the rest going to some ignored places.
Ψ 03A8
ψ 03C8
¥ 00A5
⁝ 205D
⁞ 205E
⥺ 297A (Rotated to point down)
⦀ 2980
⧨ 29E8
⧩ 29E9
⧪ 29EA
⏚ 23DA
🔍 128269
🔎 1F50E
There are a lot pictured here https://www.vertex42.com/ExcelTips/unicode-symbols.html
This may help. While looking for the same thing I found that I could print a funnel using this JavaScript line:
String.fromCharCode(57710); // Prints: 
But it doesn't work all the time. Most of the time I end up with a box, like: "". I'm still trying to figure out why that is.

google charts annotations show right side of point

I am using google charts for plotting a graph
How can I show annotation of the point at right-hand-side of the point but it showing on the top of point
http://i.stack.imgur.com/UHhQH.png
I want it like as follow
http://i.stack.imgur.com/lUBcq.png
Please any one help me out
You can actually change the position of the annotations, by using css tranform.
You should first get a handle to the anntation text, if you want to change all the text, then you can use the text tag name in css
text {
transform: translate(10px, 30px);
}
I was able to adjust annotations to the right by doing 2 things:
1) Entered some white spaces (\u00A0 is white space) and a long dash (—) on the left side of the desired annotation.
2) Added stem length of -3.
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'Model');
dataTable.addColumn('number', 'T');
dataTable.addColumn({type:'string', role:'annotation'});
dataTable.addRows([
['ABC',30,'\u00A0\u00A0\u00A0\u00A0 — X'],
['DEF',20,'\u00A0\u00A0\u00A0\u00A0 — Y'],
['GHI',10,'\u00A0\u00A0\u00A0\u00A0 — Z'],
]);
var options = {
1: {annotations: {stem: {length: -3}}
};

def negatives in JES

I am trying to show my picture as a negative, and I coded it, but it wont show the picture as a negative, did I do something wrong?
def negative(picButterfly2):
for px in getPixels(picButterfly1):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
ALSO HOW DO I DRAW HORIZONTAL LINES? Thanks!
Try with correct variables names: you have picButterfly2 NOT EQUAL TO picButterfly1:
This works:
def negative(picButterfly1):
for px in getPixels(picButterfly1):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
file = pickAFile()
picture = makePicture(file)
negative(picture)
show(picture)
Also look at:
This (for negating images).
This (for drawing lines) - or any of those.
Your variables "red", "blue", and "green" already have a function in it, change it to a single character or just a capital letter like "Red". I know this was posted in 2014 but I'll leave a comment for the future.