How to change dashs style in Vaadin 14 graphs? - vaadin-flow

In Vaadin 14, I'm trying to determine how to change the graph's line style from solid to dashed? (I need to do this programatically.) At first, it seemed trivial (based on https://vaadin.com/blog/styling-your-vaadin-charts), but I do not see API for either color setting (eg
PlotOptionsLine redBirdOptions = new PlotOptionsLine();
redBirdOptions.setColor(new SolidColor("#d62031"));
) or dash-style setting available in Vaadin 14. Anyone have examples on how one can programmatically set the dash style (and color) of series in a Vaadin 14 line graph?

Disclaimer: There is no way to do it Java only. You would need to style chart using CSS. Though, the color can be changed via styles settings in Java like shown here Treemap custom colors, I will follow the CSS approach below
The documentation you are referring to is for Vaadin 8, which uses another version of the highcharts library. In Vaadin 14, you need to configure settings via css. There is no example especially for your use case, but you can find in the links below all the needed info :
CSS file configuration and correct import annotation CSS Styling
Class names that can be used to style charts Highcharts API
The color is set using .highcharts-color-{n} class (or the --vaadin-charts-color-{n} property, which is preferred here), where n can be defined for options on Java side like this : plotOptions.setColorIndex(2);. A highchart example for colors can be found here : CSS Colors
For dashed css you could check this : CSS dashstyle.
Overall, this should do the trick:
Create a chartStyles.css file
Put the content below there :
:host {
--vaadin-charts-color-2: red;
}
.highcharts-series-0 {
stroke-dasharray: 1, 3;
}
Import the style using :
#CssImport(value = "./styles/chartStyles.css", themeFor = "vaadin-chart", include = "vaadin-chart-default-theme")
Plot options have colorIndex of 2 (as this is the value in css we are referring to):
PlotOptionsAreasplinerange range=new PlotOptionsAreasplinerange();
range.setColorIndex(2);
dataSeries.setPlotOptions(range);
After that the chart color should change. You can skip the index assignment and use --vaadin-charts-color-0, if you have only one chart on the page. If not, I would suggest to add theme names to the chart and adjust css file to use them. This way you would ensure that only the chart you want is affected.

Related

Rescaling a figure in quarto

I'm using quarto to prepare some slides (i.e., revealjs output), and I can't find a way to scale an embedded image (e.g., from Wikipedia). It seems the "width" parameters should do but neither a percentage
![](https://upload.wikimedia.org/wikipedia/commons/a/a4/Discharging_capacitor.svg){width="50%"}
nor an absolute value
![](https://upload.wikimedia.org/wikipedia/commons/a/a4/Discharging_capacitor.svg){width=600}
seems to have any effect on the rendered picture. Any clues?
Cheers.
Option 1: The easy solution: See here for more information.
For slides that contain only a single top-level image, the .r-stretch class is automatically applied to the image. You can disable this behavior by setting the auto-stretch: false option
format:
revealjs:
auto-stretch: false
Option 2:
If you like that general stretching behavior you can
A) deactivate the stretching behavior for an individual slide using
## Slide Title {.nostretch}
B) Create own css class:
The following code uses the same width (30px), but only the one with the own css style works where the trick is the !important to overwrite the default set by .r-stretch class.
.qmd
---
format: revealjs
css: styles.css
---
## using css class
![Caption](https://upload.wikimedia.org/wikipedia/commons/a/a4/Discharging_capacitor.svg){.width-image}
## using inline css does not work
![Caption](https://upload.wikimedia.org/wikipedia/commons/a/a4/Discharging_capacitor.svg){width=30px}
styles.css
.width-image{
width: 30px!important;
}

Angular Material Custom Theme from Material Color Tool

Material.io has this great tool called the Material Palette Generator: https://material.io/design/color/#tools-for-picking-colors. Using it, you can pick a primary and secondary color, and then click a link "View in Color Tool" which takes you to a page where you can see your choices in different ways: https://material.io/resources/color/#!/?view.left=0&view.right=0&primary.color=6002ee&secondary.color=c63131.
But there doesn't seem to be an easy way of exporting your palette into a format usable for generating a custom Angular Material theme. They have an export link, but the closest format seems to be CodePen. But once you open it in CodePen, the CSS doesn't seem to have the palette information you need.
My question: has anyone tried these tools, and is there a pre-established pathway from Material palette to Angular Material custom theme? Or are they unrelated? If unrelated, is there a simple way to copy the color codes needed from the former to the latter?
Thanks.
You can use this website for generate a material color. For you only need a hex code, and after this you can generate the expected color format.
Expected color format:
Generated result:

Theme colors Material Design vs Angular Material

If I refer to Material Design guidelines about Colors, they define :
Primary
Primary Variant
Secondary
Secondary Variant
Background
Surface
Error
Angular material define
Primary
Secondary
Warn
In addition the contrast color in angular is the equivalent of the On* in MDC.
1> In Angular Material background and surface are set to white or black depending of the theme builder function. No access for custom.
[edit] (thanks #G. Tranter):
Custom background color here
2> In Angular Material, I can define lighter and darker variant of each of the 3 colors, but I do not have control of where those variants are used !
(unless I manually overwrite each mat-* class...)
I am able to build my theme with two colors (primary and accent). But I don't get the point to define variants if I cannot assign the variants to specific UI elements.
[edit] (thanks #G. Tranter):
In Angular Material the use of variants is defined by the component itself.
If I refer to Material design examples (same page linked above) I cannot reproduce the theme with primary, primary variant and secondary for example...
did I miss something ? or does someone can enlighten me about this 2 major restrictions in theming ?
[edit] (thanks #G. Tranter):
In Angular Material we can define a second theme (with Primary and Accent colors) that will be applied to a specific CSS class
.item-second-theme {
#include angular-material-theme($second-theme);
}
Neither is actually a restriction (at least completely).
You can customize the foreground and background by modifying the theme before you apply it to your application and to Angular Material. See this post. However, it is probably not a great idea from a Material Design point of view to use background and foreground palettes that don't follow the guidelines, so there's usually no reason to not use the default ones in Angular Material.
You can't control how Angular Material components use the variants - that is part of the design of the components themselves. But you can control what those variants are when you create your palettes. For example:
$primary-palette: mat-palette($mat-blue, 500, 100, 700); // default
or
$primary-palette: mat-palette($mat-blue, 700, 300, 900); // darker
And of course you have complete control within your own components as to how shades are used.

How to set Angular Material primary color to custom value?

I need to set custom color as primary in Angular Material. Reading some theaming guides and SO answers like Changing Primary Color in Angular Material 2 shows that I need to pick color from predefined set of colors. Can I use custom value?
You can use any color you want, but it must be defined in your own custom 'palette' in order to be used in theming. Have a look at the Angular Material palettes for examples. You would then use your palette in place of the material palettes like $mat-blue when you create your theme:
$my-blue: (
50: #e3f2fd,
...
)
...
$primary: mat-palette($my-blue);
...
$theme: mat-light-theme($primary, $accent);
Search the web for angular material palette tool or similar. There are a number of free online tools for creating palettes from a base color.

Cannot get Highcharts solidgauge stops to work in styled mode

I am converting all the charts in an application to Highcharts 5.x styled mode.
I cannot find how to make the solidgauge stops work in styled mode. When I inspect the SVG, I do not see any class for the colors.
I couldn't find any solidgauge stops example with styled mode.
Anyone can post a working example?
In a solid gauge series color is calculated dynamically based on stop values - currently, I do not think you can do the same with only css. The point fill atribute is calculated and set correctly but in this case css class takes precedence and the point's color has a fixed fill taken from the css file (highcharts-color-{n} class).
Keep stops in options and remove class from the point (or set colorIndex to a non existing number, e.g. 99)
.highcharts-color-0 {
fill: #7cb5ec; //remove fill attribute
stroke: #7cb5ec;
}
or:
data: [{y: 80, colorIndex: 99}], // the point's class will highcharts-color-99 now
example: http://jsfiddle.net/gj8zfw73/

Resources