I'm using VS code with metal scala extension and cannot get my code to format properly. I want to have 8 spaces tab width for everything. This is my .scalafmt.conf
version = "2.0.0-RC4"
maxColumn = 80
continuationIndent.callSite = 8
continuationIndent.defnSite = 8
Then I press Ctrl+Shift+I to format the document. Only the call sites are aligned with 8 spaces, the definition sites are aligned to 2 spaces only.
This is what my formatted code looks like.
final class Goods(
_food: Int = 0,
_materials: Int = 0,
_products: Int = 0,
_fuel: Int = 0
) {
var raw = Array(_food, _materials, _products, _fuel)
def food: Int = raw(0)
def materials: Int = raw(1)
def products: Int = raw(2)
def fuel: Int = raw(3)
def weight = raw.sum
}
Why isn't the body of the class aligned with 8 space?
Because the developers of scalafmt arbitrarily don't want you to have control over your own tab width. This is the main reason I'm using scalariform instead.
https://github.com/scalameta/scalafmt/issues/1493
Related
I added inseam inch value 31.8 as default value but it show 32. This is my code.
var params = {
Inseam: 0,
inseamarea:31.8,
};
var gui = new GUI();
var folder = gui.addFolder( 'Morph Targets' );
folder.add( params, 'Inseam', -1, 1 ).step( 0.1 ).onChange( function ( value ) {
params.inseamarea = 31.8 +(1.4 * value);
} );
folder.add(params, "inseamarea", 31.8).name("Inseam Inch ").listen();
I want value in float but it show in integer.
I found a link which i followed. https://jsfiddle.net/prisoner849/514d4kmy/
and this is my fiddel link where i added my code in same place. https://jsfiddle.net/kwdphca0/
You should simply use step(), e.g. :
folder.add(params, "inseamarea", 31.8).step(0.1).name("Inseam Inch ").listen();
https://github.com/dataarts/dat.gui/blob/master/API.md#numbercontroller--datcontrollerscontroller :
if minimum and maximum specified increment is 1% of the
difference otherwise stepValue is 1
EDIT : If you want to disable this controller :
let ctrl = folder.add(params, "inseamarea", 31.8).step(0.1).name("Inseam Inch ").listen();
ctrl.domElement.style.pointerEvents = "none";
I am reading Excel sheet using Apache POI and writing it to a PDF using iText library.This has been achieved successfully but I am getting default black border for every cell that I write to PDF. So I need to get the cell border color using Apache POI which can be achieved using CellStyle class method getBottomBorderColor() which returns a short value.However I need a way to convert this value to RGB value so that while writing cell to PDF I can apply that RGB color value to the cell border.
The short value from CellStyle.getBottomBorderColor is an index of the color in the color palette of the workbook. This is an olld approach for storing colors from the old binary *.xls Excel format. So in apache poi there is only HSSFPalette which only should be used in HSSF and not more be used in XSSF.
In newer *.xlsx Excel formats, the color will either be stored directly as hex value or as reference to a theme color. So for XSSF there is XSSFCellStyle.getBottomBorderXSSFColor to get that color directly and not via index.
So unfortunately we have to differ both aproaches dependent on the kind of Excel workbook.
Example:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import java.io.FileInputStream;
class ExcelCellBorderColor{
public static void main(String[] args) throws Exception {
Workbook wb = WorkbookFactory.create(new FileInputStream("ExcelCellBorderColor.xlsx"));
//Workbook wb = WorkbookFactory.create(new FileInputStream("ExcelCellBorderColor.xls"));
String strrgb;
Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFColor xssfcolor = ((XSSFCellStyle)style).getBottomBorderXSSFColor();
if (xssfcolor != null) {
byte[] brgb = xssfcolor .getRGB();
strrgb = "R:"+String.format("%02X", brgb[0])+",G:"+String.format("%02X", brgb[1])+",B:"+String.format("%02X", brgb[2]);
System.out.println("Cell " + cell.getAddress() + " has border bottom color: " + strrgb);
}
} else if (style instanceof HSSFCellStyle) {
short colorindex = ((HSSFCellStyle)style).getBottomBorderColor();
HSSFPalette palette = ((HSSFWorkbook)wb).getCustomPalette();
HSSFColor hssfcolor = palette.getColor(colorindex);
if (hssfcolor != null) {
short[] srgb = hssfcolor.getTriplet();
strrgb = "R:"+String.format("%02X", srgb[0])+",G:"+String.format("%02X", srgb[1])+",B:"+String.format("%02X", srgb[2]);
System.out.println("Cell " + cell.getAddress() + " has border bottom color index: " + colorindex + ". This is " + strrgb);
}
}
}
}
wb.close();
}
}
you can archive this by using this color class
CTScRgbColor scrgb = (CTScRgbColor)ch;
int r = scrgb.getR();
int g = scrgb.getG();
int b = scrgb.getB();
color = new Color(255 * r / 100000, 255 * g / 100000, 255 * b / 100000);
Im trying to make a graph like this:
https://www.google.com/finance?q=BCBA:PAMP
I have a line chart in chart.js, now I want to add labels (like the letters A, B, C) for certain dates.
Can't find a doc/example to start from. Any idea?
If its more simple to do with another library a recommendation is more than welcome.
Thanks!
Unfortunately, there is no native support in chart.js for what you are wanting. However, you can certainly add this capability using the plugin interface. This requires that you implement your own logic to draw the canvas pixels at the locations that you want them. It might sound challenging, but its easier than it sounds.
Here is an example plugin that will add a value above specific points in the chart (based upon configuration).
Chart.plugins.register({
afterDraw: function(chartInstance) {
if (chartInstance.config.options.showDatapoints || chartInstance.config.options.showDatapoints.display) {
var showOnly = chartInstance.config.options.showDatapoints.showOnly || [];
var helpers = Chart.helpers;
var ctx = chartInstance.chart.ctx;
var fontColor = helpers.getValueOrDefault(chartInstance.config.options.showDatapoints.fontColor, chartInstance.config.options.defaultFontColor);
// render the value of the chart above the bar
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize + 5, 'normal', Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
ctx.fillStyle = fontColor;
chartInstance.data.datasets.forEach(function (dataset) {
for (var i = 0; i < dataset.data.length; i++) {
if (showOnly.includes(dataset.data[i])) {
var model = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._model;
var scaleMax = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._yScale.maxHeight;
var yPos = (scaleMax - model.y) / scaleMax >= 0.93 ? model.y + 20 : model.y - 5;
ctx.fillText(dataset.data[i], model.x, yPos);
}
}
});
}
}
});
It allows you to configure which points you want to annotate using this new configuration. The showOnly option contains the points that you want to label.
options: {
showDatapoints: {
display: true,
showOnly: [3, 10, 9]
},
}
Obviously, this only adds the datapoint value at the specified points, but you can just change the plugin to paint whatever you want to show instead. Simply replace ctx.fillText(dataset.data[i], model.x, yPos) with different code to render something different on the canvas.
Here is a codepen example to show you want it looks like.
I am starting with Scala and with ScalaFX, I understand most of the code but I don't understand this code using for the examples in ScalaFx;
where instantiate an anonymous class follow it by curly braces, How this works???
object ScalaFXHelloWorld extends JFXApp {
stage = new PrimaryStage {
title = "ScalaFX Hello World"
scene = new Scene {
fill = Black
content = new HBox {
padding = Insets(20)
children = Seq(
new Text {
text = "Hello"
style = "-fx-font-size: 48pt"
fill = new LinearGradient(
endX = 0,
stops = Stops(PaleGreen, SeaGreen)
)
},
new Text {
text = "World!!!"
style = "-fx-font-size: 48pt"
fill = new LinearGradient(
endX = 0,
stops = Stops(Cyan, DodgerBlue)
)
effect = new DropShadow {
color = DodgerBlue
radius = 25
spread = 0.25
}
}
)
}
}
}
}
the part I don't understand is why in the creation of an anonymous class is follow by curly braces (with some more declarations)(Scene is not a trail to be filling the abstract parts of that class) and even fill or content are functions not a variables and Black for fill for instant is a val meaning that this line
fill = Black
is doing calling a function fill and assigning a val to it(don't make sense for me ), this is fill definition
def fill: ObjectProperty[jfxsp.Paint] = delegate.fillProperty
and this is Black
val Black = new Color(jfxsp.Color.BLACK)
how works this instantiation of a new object with curly braces please help, want to understand.
This is because ScalaFx is wrapping JavaFx and something special is going on here?.
Thank you guys.
Update:
Well now I know that it is calling a setter via syntax sugar however I check that setter and I don't understand what is going on there
Check it out:
def fill: ObjectProperty[jfxsp.Paint] = delegate.fillProperty
def fill_=(v: Paint) {
fill() = v
}
how come the setter is calling the getter to update the value?
delegate.fillProperty
is a function that return a value
The syntax for anonymous classes in Scala is borrowed from Java; you can see it here, too:
class Coder {
protected String name;
public Coder(String name) {this.name = name;}
}
public static void main(String[] args) {
// Prints "Mr. Noble"
new Coder("Noble") {
private String prefix = "Mr.";
{
System.out.println(prefix + " " + name);
}
}
}
Because Scala lets you write your constructor code in the class body, all of your x = y statements are executed when you instantiate those anonymous classes. As #resueman points out, these are actually getters and setters in this format:
class Scene {
var _fill
def fill_=(color: Color) // Setter, has some hidden logic to set up the UI
def fill = _fill // Getter
}
And your statement fill = Black is desugared to fill_=(Black).
I have a StyledText widget in an SWT app with formatted text like so:
Type -> Text
MessageID -> ID:205871803-172.30.227.122(89:ab:da:58:b9:f3)-32849-1332173293715
CorrelationIDAsBytes -> [B#d1c778
Expiration -> 0
Priority -> 4
Timestamp -> 1332173293715
Redelivered -> false
However, this is what it ends up looking like:
Is there some option I can turn on to make it display the whitespace "as is"?
I tried adding some style to it to get it to look right, but it still doesn't work:
_messageDataText.addLineStyleListener( new LineStyleListener() {
public void lineGetStyle( final LineStyleEvent lineStyleEvent ) {
StyleRange styleRange = new StyleRange();
styleRange.start = 0;
styleRange.length = _messageDataText.getText().length();
styleRange.font = new Font( Display.getCurrent(), "Arial", 12, SWT.NORMAL );
lineStyleEvent.styles = new StyleRange[] {
styleRange };
}
} );
Apparently it depends on the font. If you use "Courier New" instead the whitespace lines up properly.
This is what I changed:
styleRange.font = new Font( Display.getCurrent(), "Courier New", 10, SWT.NORMAL );
Also, as a side note - it is important to reuse fonts wherever possible or you'll get nasty handle problems.