Wrap or cut long labels in Pentaho CCC - pentaho

How to cut long labels of the Bar Chart Control’s base axis?
I have already tried to cut them in the Extension Points (baseAxisLabel_text):
function(a){
var str=this.scene.atoms.category.label;
if (str.length>30){
str=str.substring(0,30)+' ...';
}
return str;
}
However, it seems that Chart Control width is calculated taking into account old label length. Now I have white area at the left of my bars.
How to solve this?

I found the solution.
I just moved slightly changed function from Extension Points (baseAxisLabel_text) to baseAxisTickFormatter (Advanced Properties of the chart control)
function(v){
if (v.length>30){
v=str.substring(0,30)+' ...';
}
return v;
}

Related

Custom CollapsingTopAppBar Jetpack Compose

The essence of the problem is that I want to write my own version of the AppBar that would include content as another Compose function. After looking at the source code of the current CollapsingTopAppBar implementation, I saw the following lines:
#Composable
private fun TwoRowsTopAppBar(
...
scrollBehavior: TopAppBarScrollBehavior?
) {
...
val pinnedHeightPx: Float = 64.dp
val maxHeightPx: Float = 152.dp
LocalDensity.current.run {
pinnedHeightPx = pinnedHeight.toPx()
maxHeightPx = maxHeight.toPx()
}
// Sets the app bar's height offset limit to hide just the bottom title area and keep top title
// visible when collapsed.
SideEffect {
if (scrollBehavior?.state?.heightOffsetLimit != pinnedHeightPx - maxHeightPx) {
scrollBehavior?.state?.heightOffsetLimit = pinnedHeightPx - maxHeightPx
}
}
...
Surface(...) {
Column {
TopAppBarLayout(
...
heightPx = pinnedHeightPx
...
)
TopAppBarLayout(
...
heightPx = maxHeightPx - pinnedHeightPx + (scrollBehavior?.state?.heightOffset
?: 0f),
...
)
}
}
}
As I understand it, scrollBehavior is used to handle the collapse and expansion behavior. In the current implementation, just constant values are put in heightOffsetLimit. And since I need my appbar implementation to be able to contain content of any size, I need to somehow know the size of this content in advance and put this value in heightOffsetLimit.
I have already written the code for my AppBar, so that it also contains content. But since I can't pass the height value of the content to scrollBehavior, the AppBar doesn't collapse to the end.
you need to calculate the height that the appbar will have before drawing it into the screen. I have followed this issue and solved my problem with the last solution. hope it helps:
Get height of element Jetpack Compose
use the content you can put (ex. an image or a huge text) as the MainContent
use your appbar as the DependentContent and use the size given in lambda to give the height to your appbar
finally set placeMainContent false as I believe you don't need to draw the image (or any other composable) directly in a box
and you will good to go

mpandroidchart the dot's color doesn't change in scatter chart

I'm using MPandroidchart to draw scatter chart.
I want to make a scatter chart that has a base line.
If value over the base line, in my case 0.2, its color change to red.
If not, it color is blue.
This is the codes i did.
if (d>=0.5)
{
colors.add(getBaseContext().getResources().getColor(R.color.color_red));
} else
{
colors.add(getBaseContext().getResources().getColor(R.color.color_blue));
}
value1.add(new Entry(k,d));
But it didn't change dot's color, but change squre's color next to label
I have tried
1)
if(index == specificIndex) colors.add(Color);
else colors.add(NormalColor);
2)
ArrayList<Integer> color = new ArrayList<>();
if (YOUR_CONDITION) {
color.add(ColorTemplate.rgb("#f8bf94"));
yVals1.add(new Entry(VALUE, COUNTER));
} else {
color.add(ColorTemplate.rgb("#e0e0e0"));
yVals1.add(new Entry(VALUE, COUNTER));
}
set1.setColors(color);
3)
color.add(Color.RED);
color.add(context.getResources().getColor(R.color.your_defined_color_in_colors_xml));
dataSet.setCircleColors(color);
But it didn't work.
How can i solve this?
After spending hours with this same issue, I have realized that it is the result of a bug in the MPAndroidChart project.
Basically, in the ScatterChartRenderer, the colors array is being treated such that only even colors are being applied to data points. For each Entry i, the color is set to colors[i / 2] meaning that the same color will be applied to two different entries due to integer division. This results in only half of the colors array being used.
To resolve this issue quickly, my solution was to add each entry to the DataSet twice. This means two points are drawn on top of each other, but both have the proper color set.
I am submitting a pull request to hopefully fix this issue in the next release, but for now this quick hack should work.

mpAndroidChart: Xaxis.setPosition to Bottom_Inside not working on HorizontalBarChart

I have a HorizontalBarChart with mpAndroidChart and I am having problems to display the labels on the left side, but within the graph. It looks like this:
the labels are chopped of on the left side. This is done via the line
testchart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE)
On the right side, it works smoothly:
The labels are inside the graph and fully displayed. This is done by the line:
testchart.getXAxis().setPosition(XAxis.XAxisPosition.TOP_INSIDE)
Any idea what I am doing wrong?
My Code for the chart is:
BarData data = new BarData(new BarDataSet(entries, "Labeltest"));
data.setBarWidth(1); // set custom bar width
data.setDrawValues(false);
oBinding.testchart.setData(data);
oBinding.testchart.getXAxis().setLabelCount(labels.size());
oBinding.testchart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
oBinding.testchart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
// Hide grid lines
oBinding.testchart.getAxisLeft().setEnabled(false);
oBinding.testchart.getAxisRight().setEnabled(false);
// Hide graph description
oBinding.testchart.getDescription().setEnabled(false);
// Hide graph legend
oBinding.testchart.getLegend().setEnabled(false);
oBinding.testchart.invalidate(); // refresh
and in XML:
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="#+id/testchart"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
I have encountered the same problem, I solved it this way.
chart.getXAxis().setPosition(XAxisPosition.BOTTOM_INSIDE)
In that way the labels should be drawn over the bars. You can further reposition the labels by using the setXOffset(...) and setYOffset(...) methods of the XAxis class.
If you have a better way, please let me know, thank you
Try this:
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
Added in response to comment from #andreas-zuercher:
This way has always worked for me. This also makes it easy to set other axis parameters like:
xAxis.setDrawGridLines(true);
xAxis.setGranularity(1f);
xAxis.setGranularityEnabled(true);
final String[] xTime = time.split(",");
xAxis.setValueFormatter(new IAxisValueFormatter() {
#Override
public String getFormattedValue(float value, AxisBase axis) {
return xTime[(int) value-1];
}
});
xAxis.setValueFormatter(new IndexAxisValueFormatter(xTime));

constrain proportions while resizing images

I implemented drag and drop of images and now i want to constrain proportions of images while resizing.
/**
* Variable: constrainChildrenOnResize
*
* Specifies if children should be constrained according to the <constrainChildren>
* switch if cells are resized (including via <foldCells>). Default is false for
* backwards compatiblity.
*/
mxGraph.prototype.constrainChildrenOnResize = false;
i set this to true but its not working :s
What API/property i need for this functionality..
constrainChildrenOnResize is responsible for positioning and size of the children of resized cell. It means that children should keep their position relatively to the parent-cell.
In your case I would suggest to extend mxVertexHandler using union method. In this example you can see how to implement min-width/min-height restrictions. Using this example you are able to write your own rules for constrain.
Here is my simple solution:
var vertexHandlerUnion = mxVertexHandler.prototype.union;
mxVertexHandler.prototype.union = function (bounds) {
var result = vertexHandlerUnion.apply(this, arguments);
var coff = bounds.width / bounds.height
result.width = result.height * coff;
return result;
};
So this function is called every time you move mouse during dragging the resizer.
bounds - object, always same and represent old geometry of the cell (before resizing)
result - object, represents new values, which are going to be applied. Between this line ad return statement you can place any code you need to modify result.
In my simple example I just get the initial relation between width and height of the cell (coff) and then set new width by multiplying coff and new height. It will work if you drag corner or top/bottom. In real project this logic should be slightly extended, or you should make visible only corner handlers.
By the way, this code will work for all resizable cells on your graph. If you want to apply it only to images or some other kind of cells - you can put condition and check the cell type before recalculating. You can get current cell or its state via this.state.cell or this.state inside of union function.
For example only for vertecies:
... ...
var result = vertexHandlerUnion.apply(this, arguments);
if (this.state.cell.isVertex()) {
//calculations here
}
return result;

GraphKit framework in Cocoa

I try to draw an XY graph using GraphKit.
Information of this framework is very limited on the internet...
Here's what I did:
// a xychart is predefined in header as GRChart
GRDateSet *dataset = [[GRXYDataSet alloc] initWithOwnerChart:xychart];
[xychart addDataSet:dataSet loadData:YES];
[xychart reloaddata];
also I implement delegate methods:
(double)chart:(GRChartView *)aChart xValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index
{ return index * 10.0; }
(double)chart:(GRChartView *)aChart yValueForDataSet:(GFDataSet*)aDataSet element:(NSUInteger)index
{ return index * 10.0; }
(NSUInteger) chart:(GRChartView *)aChart numberOfElementsForDataSet:(GFDataSet*)aDataSet {
return 10;
}
however, it only draws the axes but no data points at all...
what did I miss here?
thanks!
I got it. This framework only stores data points and draws axes according to the data points. (It automatically calculates the bounds of each axes and zoom into a suitable plot area.)
However, no drawing method is rooted. To get an immediate graph, I have to use GRAreaDataSet, which is a subclass of GRXYDataSet. Then it will draw an area chart.
I also tried out core-plot. But it's more difficult to use to me. I have to calculate the bounds myself; and padding the graph to show the label values of axes. Also, it's not so beautiful if I don't customize the symbols and lines. However, the default GraphKit charting is nice-looking enough. Though it doesn't have a document...
I'll try to write a tutorial of it when I try out everything in it :)