Extjs Line Chart multiline label - extjs

I want to make a label in Line Chart on X axis, that shows summary for selected category. I want to format this, so under category name I have values. It works if I do:
return Ext.Date.format(v, 'M Y') + '\r' +
(val.data.Budgeted==null?'':('$ '+Ext.util.Format.number(val.data.Budgeted, '0,000') + '\r')) +
(val.data.Actual==null?'':('$ '+Ext.util.Format.number(val.data.Actual, '0,000') + '\r'));
still, label is going down, as I found, with each \r char. So if I have no \r it shows like it should, but if there is N '\r'-s then label itself will go down as there is N lines of text over it.
Also will be nice to find a way to format text (align)
EDIT:
I found a way to do this, by changing "drawVerticalLabels" function in axis config. Still, it's a bad way in my opinion.

I had to do something pretty similar I think. There's a screenshot of it on SO here.
I ended up doing it like an HTML template. I wasn't as familiar with the ExtJS framework as I am now so if I had to redo it I would probably use an xtemplate, but this worked out for me:
series: [{
type: 'line',
title: 'This Year',
axis: 'left',
smooth: false,
xField: 'date_value',
yField: 'the_count',
// custom tips
tips: {
trackMouse: true,
width: 127,
height: 70,
hideDelay: 0,
dismissDelay: 0,
renderer: function(record) {
this.setTitle('<table width=115><tr><th><b>' +
record.get('date_value') +
':</b></th><td align=right>' +
record.get('the_count') +
'</td></tr><tr><th><b>Quota:</b></th><td align=right>' +
record.get('the_quota') +
'</td></tr><tr><th><b>Diff:</b></th><td align=right>' +
(record.get('the_quota') > record.get('the_count') ?
'-' + (record.get('the_quota') - record.get('the_count')) :
'+' + (record.get('the_count') - record.get('the_quota'))
) + '</td></tr></table>'
);
}
}
}]

Multiline can be done with inserting '\n' for line break in the axis renderer, and by default it is centered.

Related

Why is a random part of the code highlighted?

We have an online editor made by monaco-editor, here is the link: https://v3.10studio.tech/#/formula-editor-addin?app=formula-editor-addin. Users could enter an Excel formula like =1+2+3+4+5, then click on the Format button to see the formatted formula.
What is odd is that, after clicking on Format button, a random part of the formula is often highlighted in gray:
Does anyone know what may be the cause?
PS: The current options setting are as follows:
const monacoOptions: monacoEditor.editor.IEditorConstructionOptions = {
lineNumbers: 'off',
selectionHighlight: false,
glyphMargin: false, //left side,
lineDecorationsWidth: 0, // width between line number and content,
renderIndentGuides: false, // no indent guide lines
minimap: { enabled: false },
};
When you set the value of the model ie editor.getModel().setValue('FORMATTED-CODE') you should have to set the position of the cursor manually.
The selection is actually not random. Monaco will select all the extra texts you have added. For example -
Before : 1+2+3+4+5 - here last position is line 1 column 10
Format: 1 + 2 + 3 + 4 + 5 - here last position is line 1 column 18
So the extra text + 4 + 5 is selected, it means column 11 to 18 is selected
To set the position of the cursor at where it was before
const pos = editor.getPosition()
editor.getModel().setValue('FORMATTED-CODE')
editor.setPosition(pos)
To set the position of the cursor at Line 1 Column 1
editor.getModel().setValue('FORMATTED-CODE')
editor.setPosition({ lineNumber: 1, column: 1 })
To set the position of the cursor at last (using offset)
const formatted = 'FORMATTED-CODE'
const offset = formatted.length
const pos = editor.getModel().getPositionAt(offset)
editor.getModel().setValue(formatted)
editor.setPosition(pos)
You can also set selection
editor.setSelection({
startLineNumber: 1,
startColumn: 1,
endLineNumber: 1,
endColumn: 5,
})
For more informations you can follow these APIs -
setPosition - To set cursor position
setSelection - To set selection
setSelections - To set multiple positions & selections

Parsing Attribute Data from Column- SQL Server

I have a table with column "Long Description" typically the data looks like the following.
Foundation area wall, 12" H. x 20" W. x 8" projection. Galvanized. Refer to model No. SV208 (SKU 100002) for foundation area wall cover. No. FV208-12: Height: 12", Width: 20", Projection: 8", Type: Foundation Area Wall, Material: Galvanized, Pkg Qty: 1
What I am trying to do is parse out the end attributes. For example after "area wall cover." and beginning with "No." I'd like to extract the following. (Below)
Some things to note. The string '. No.' always begins the attributes in this column. All attributes are separated by columns. The attribute names differ and the amount of attributes per product also differ. Is there a way this can be done with T-SQL?
No. FV208-12:
Height: 12"
Width: 20"
Projection: 8"
Type: Foundation Area Wall
Material: Galvanized
Pkg Qty: 1
You can use a variation of the following to achieve what I believe you're attempting to achieve:
DECLARE #StartAttributesKey VARCHAR(50) = 'area wall cover. ' ,
#LongDescription VARCHAR(MAX) = 'Foundation area wall, 12" H. x 20" W. x 8" projection. Galvanized. Refer to model No. SV208 (SKU 100002) for foundation area wall cover. No. FV208-12: Height: 12", Width: 20", Projection: 8", Type: Foundation Area Wall, Material: Galvanized, Pkg Qty: 1';
SELECT REPLACE(SUBSTRING(#LongDescription, CHARINDEX(#StartAttributesKey, #LongDescription, 0) + LEN(#StartAttributesKey),
LEN(#LongDescription) - CHARINDEX(#StartAttributesKey, #LongDescription, 0)), ',', CHAR(10));
Using this in a query would be similar to:
DECLARE #StartAttributesKey VARCHAR(50) = 'area wall cover. '
SELECT REPLACE(SUBSTRING(LongDescription, CHARINDEX(#StartAttributesKey, LongDescription, 0) + LEN(#StartAttributesKey),
LEN(LongDescription) - CHARINDEX(#StartAttributesKey, LongDescription, 0)), ',', CHAR(10))
FROM [someTable] WHERE ID = 1
If you copy (or print) the result, you will see each attribute on a separate line.

Showing colour in cal-heatmap tiles

I'm using cal-heatmap for displaying a user activity for a month. My issue is that the colour change is not showing properly. My "init" function is given below.
When I provide data with integer values which have difference of 2 or 3 (eg: 8, 12, 3, 7 etc [pls note that I'm giving data as JSON]), I can't see any significant difference in colour for the blocks (screenshot is added in http://i.stack.imgur.com/xspWR.jpg - numbers given in top indicates the data corresponding to that cell).
init({
start: new Date(newDate.getFullYear(), month, 1),
cellRadius: 35,
cellSize: 58,
itemSelector: "#heatmap_busiestDays",
domain: "month", //hour|day|week|month|year
subDomain: "x_day",
subDomainTextFormat: "%b %d",
range: 1,
domainGutter: 10,
previousSelector: "#cal-heatmap-previous",
nextSelector: "#cal-heatmap-next",
displayLegend: false,
data: busiestDayHeatMap,
legendColors: {
min: "#A2F37B",
max: "#26911F",
empty: "white"
}
});
Am I missing anything in settings? Any help will be greatly appreciated. Thanks in advance.

Convert HEX to RGBA in Stylus

I have some HEX colour values in Stylus similar to the following
$my-background ?= #123456
$my-foreground ?= #ABCDEF
and would like to use them in rgba values for opacity, so that
.my-class
background rgba($my-background, .5)
foreground rgba($my-foreground, .5)
or an alternative syntax is compiled into CSS as
.my-class {
background rgba(18, 52, 86, .5);
foreground rgba(171, 205, 239, .5);
}
Is there a quick and easy way to use HEX colour values in rgba using Stylus or a plugin for Stylus (such as nib)?
Actually, the rgba in Stylus works just like that, have you tried what you wrote? In Stylus
$my-background ?= #123456
$my-foreground ?= #ABCDEF
.my-class
background rgba($my-background, .5)
foreground rgba($my-foreground, .5)
Would actually compile to
.my-class {
background: rgba(18,52,86,0.5);
foreground: rgba(171,205,239,0.5);
}
This means you can just go and do things like rgba(black, 0.5), rgba(#FFF, 0.5) and use variables inside of it, just like in your case.
In the end I made my own function to do this:
hextorgba(color, alpha = 1)
'rgba(' + red(color) + ', ' + green(color) + ', ' + blue(color) + ', ' + alpha + ')'

compare and delete on an array in matlab

I am trying to write a short code to read a .m file(testin1.m) into an array, and search for a particular word( 'auto'). if match is found,delete it. i have the following code, please help me figure out my mistake.
fid = fopen('testin1.m');
txt = textscan(fid,'%s');
fclose(fid);
m_file_idx = 1;
data=['auto'];
B=cellstr(data);
for idx = i : length(txt)
A=txt{i};
is_auto=isequal(A, B);
if is_auto==0
txt{i}=[];
end
end
if txt{i}=auto then it should delete that row.
AK4749's answer is absolutely correct in showing where you went wrong. I'll just add an alternative solution to yours, which is shorter:
C = textread('testin1.m', '%s', 'delimiter', '\n');
C = C(cellfun(#isempty, regexp(C, 'auto')));
That's it!
EDIT #1: answer modified to remove the lines that contains the word 'auto', not just the word itself.
EDIT #2: answer modified to accept regular expressions.
This is an error i have hit many amany many many times:
when you set txt(i) = [], you change the length of the array. Your for loop condition is no longer valid.
A better option would be to use the powerful indexing features:
A(find(condition)) = [];
or account for the change in length:
A(i) = [];
i--; % <-- or i++, it is too early to think, but you get the idea
EDIT: I just noticed you were also using A in your program. mine was just some random variable name, not the same A you might be using
When you set txt(i) = [], you changed the length of the array but the loop indexing does not account for the change. You can use logical indexing to avoid the loop and the problem.
Example:
wordToDelete = 'auto';
txt = {'foo', 'bar', 'auto', 'auto', 'baz', 'auto'}
match = strcmp(wordToDelete, txt)
txt = txt(~match)
Output:
txt =
'foo' 'bar' 'auto' 'auto' 'baz' 'auto'
match =
0 0 1 1 0 1
txt =
'foo' 'bar' 'baz'

Resources