How to disable Cursor values on value axis (Yaxis) on amCharts4 - javascript

I have used am4charts.XYCursor(), which shows cursor values on Y & X axes. I wish to hide / disable values showing on Y axis.
chart.cursor.lineY.disabled = true;
CodePen:
https://codepen.io/pthakkar/pen/rgLqYY
/* Create a cursor */
chart.cursor = new am4charts.XYCursor();
/* Configure cursor lines */
chart.cursor.lineX.stroke = am4core.color("#8F3985");
chart.cursor.lineX.strokeWidth = 4;
chart.cursor.lineX.strokeOpacity = 0.2;
chart.cursor.lineX.strokeDasharray = "";
chart.cursor.lineY.disabled = true;
I expect the cursor values appearing on the Y axis (in black background) to disappear.

The cursor values are controlled by another properties called Axis Tooltips and they are configured per axis, and not per cursor (as it would be assumed). Calling:
axis.cursorTooltipEnabled = false;
should disable the tooltip. See the modified codepen for a working solution.

Related

FabricJS Group selection / bounding box after child resize

I'm making a flowchart editor with FabricJS and I'm having troubles with my group bounding / selection box and/or the positioning of the child withing. I'm not sure what's happening.
My items are a fabric.Group (activity) with a fabric.Rect and fabric.Text inside it. The problem occurs when I change the text and want to change the size of the Rect with it. The text is changed from outside the canvas, so not with IText.
It works like this:
for(var i in finly.dossiertypes.workflow.activities ) {
if( finly.dossiertypes.workflow.activities[i].activityId === activityId ) {
var activity = finly.dossiertypes.workflow.activities[i];
var rect = activity._objects[0];
var text = activity._objects[1];
/**
* Set text
*/
text.set({
'text': name
}).setCoords();
/**
* Get width from text object
*/
var width = text.width + (finly.dossiertypes.workflow.activityPadding * 2);
/**
* Set rect width
*/
rect.set({
'width': width
}).setCoords();
/**
* Caculate group bounds
*/
activity._calcBounds( true );
break;
}
}
What happens is that the rect is shifting to the right outside the selectable group bounding. As you can see, the mousepointer suggests where the group is. The right side of the rect is not selectable, since it is outside of the group.
I've tried several things, like setting the width of the group. Could anyone help me with this one?

Show single category Axis For Amchart Multi Panel Horizon Chart

I'm trying to show category axis for Amcharts Multi Panel Horizon chart. I tried setting the category axis property to true, but it enabled the x axis for all the charts.
"showCategoryAxis": true,
Is there a work around to show Multi horizon chart with a single x axis.
Here is demo with "showCategoryAxis": true,.
Modify the buildPanel function so that showCategoryAxis is set to false by default for all panels and then set one of them (presumably the last one) at the end of the init handler loop to false. You'll also want to set axisHeight to 0 in categoryAxesSettings so that the height of the last panel, or whichever one has the category axis enabled, doesn't shrink.
function buildPanel( dim ) {
return {
// ...
"showCategoryAxis": false,
// ...
};
}
//in addInitHandler:
for ( var i = 0; i < dimensions.length; i++ ) {
// ...
}
chartPanels[chartPanels.length - 1].showCategoryAxis = true;
chart.panels = chartPanels;
Demo

amcharts customized label position

Right now my graph's label is placed in a default position, but my label texts are rather long and its sticking out from the graph.
If possible, I want to place it so that the labels don't stick out from the graph.
Pic of Current situation & Ideal graph
Or if the above is not possible, I want to fix the visible labels. Is this possible?
right now, the "best" label gets lost/hidden when the graph width is reduced. The "too much" label also gets lost when the width is largely reduced.
I have been searching all over stackoverflow and amcharts website but I can't seem to find a good solution.
Is there any way to solve either of the problems...?
// tried these but doesnt work for what I want to do
va.labelOffset = -5;
va.position = "bottom";
va.inside = false;
full code in JSfiddle
In order to keep the chart from hiding the labels on resize, you need to disable the valueAxis' autoGridCount and set the gridCount to the number of tick marks you want to see. You'll also need to remove the labelFrequency setting.
va.autoGridCount = false;
va.gridCount = 3;
//va.labelFrequency = 5;
As for label positioning, you are limted to rotating and vertical offsets out of the box. As a workaround, you can position the labels by modifying the SVG nodes directly through the drawn event, for example:
// prior to chart.write
chart.addListener("drawn", function(e) {
var textNodes = e.chart.valueAxes[0].labelsSet.node.childNodes;
var transform;
//Position "too little"
transform = parseTransform(textNodes[0].getAttribute('transform'));
transform.translate[0] = parseFloat(transform.translate[0]) + 25;
textNodes[0].setAttribute('transform', serializeTransform(transform));
// Position "too much"
transform = parseTransform(textNodes[2].getAttribute('transform'));
transform.translate[0] = parseFloat(transform.translate[0]) - 25;
textNodes[2].setAttribute('transform', serializeTransform(transform));
});
// ...
// from http://stackoverflow.com/questions/17824145/parse-svg-transform-attribute-with-javascript
function parseTransform(a) {
var b = {};
for (var i in a = a.match(/(\w+\((\-?\d+\.?\d*e?\-?\d*,?)+\))+/g)) {
var c = a[i].match(/[\w\.\-]+/g);
b[c.shift()] = c;
}
return b;
}
//serialize transform object back to an attribute string
function serializeTransform(transformObj) {
var transformStrings = [];
for (var attr in transformObj) {
transformStrings.push(attr + '(' + transformObj[attr].join(',') + ')');
}
return transformStrings.join(',');
}
Updated fiddle

SVG: Scale one element of group from specified anchor point

OK, so I have a group of four elements rotating 90 degrees as I want them to, around an origin point in the middle of the four elements.
I would like to scale the top left block before and after spinning as well, outward from said origin point, but I'm having much difficulty doing so.
Here is a fiddle for my sample (read: overly simplified) progress so far:
http://jsfiddle.net/Vac2Q/2843/
The fiddle's javascript:
/* create an svg drawing */
var draw = SVG('drawing')
/* draw rectangle */
var dial = draw.circle(60)
.move(125,125)
.fill('#0099ff')
var rect_yellow = draw.rect(50,50)
.move(100,100)
.fill('gold')
var rect_blue = draw.rect(50,50)
.move(160,100)
.fill('navy')
var rect_black = draw.rect(50,50)
.move(160,160)
.fill('black')
var rect_green = draw.rect(50,50)
.move(100,160)
.fill('green')
var blades = draw.group()
.add(rect_yellow)
.add(rect_blue)
.add(rect_black)
.add(rect_green)
.back()
var angle = 0
var rotation = 90
var spin = document.getElementById('spin')
var spun = 0
/* make rectangle jump and change color on mouse over */
spin.addEventListener('click', function() {
/* calculate new ending orientation for blades */
angle += rotation
var new_rotate = angle
/* rotate the blade group */
blades.animate(1000, '>')
.rotate(new_rotate, 155, 155)
++spun
})
And here is a slightly more glamorous example of what I'm trying to do re: scaling:
The first issue is being able to determine which blade is in the top left position after a given rotation. The second issue is scaling itself; I've gotten the blade to scale, but then it goes crazy and moves off the screen at the same time. I'm not sure how to get it to scale properly from the specified origin point (the middle of the center circle).
You can use the .after() function to chain animations.
I'm not sure if I am using svg.js correctly, but here's what I did:
var rects = [rect_yellow, rect_green, rect_black, rect_blue];
// define the animations
var enlarge_blade = function() {
rects[spun % 4].animate(250, '<')
.scale(1.25, 1.25)
.translate(-38,-38);
};
function spin_anim() {
rects[spun % 4].animate(250, '>')
.scale(1, 1)
.translate(0,0)
.after(rotate_blades);
};
var rotate_blades = function() {
blades.animate(1000, '>')
.rotate(angle, 155, 155)
.after(function() {
++spun;
enlarge_blade();
title.text('spun ' + spun + ' times');
});
};
// Pre-enlarge the first (yellow) rect
enlarge_blade();
/* make rectangle jump and change color on mouse over */
spin.addEventListener('click', function() {
angle += rotation
spin_anim();
})
Demo here
I see you're using svg.js. I don't know how it treats transforms internally. But in any case. To scale an element, you typically use its center point as a reference. Therefore you should find the center point of each rect and scale it using that point. (I assume svg.js performs the required translation internally).

Making a Javascript game, Having a little problem with scrolling

I have a #wrapper div and a #grid div nested inside. currently I can scroll around with this function below.
getCursorPos : function(){
// set the empty cursor object
var cursor = {};
//get the offset from the left of the grid container
var grid
//offset loop
$(function getCursorPos(){
grid = $('#grid').offset();
setTimeout(getCursorPos, game.loopSpeed);
});
//continuosly get the position
var that = this;
$(document).mousemove(function(e){
//if game mode is menu exit
if(game.mode === 'menu'){
return;
}
// NOTE: this looks a litle over done but don't remove anything
// its like this because javascript uses floating points
// and so in order to line up to the nearest hunderedth I
// had to make the cursor and div position intergers by
// muliplying by ten. one the two are added I reduced them
// and rounded them.
that.x = Math.round(((e.pageX * 10) - (grid.left * 10)) / 10);
that.y = Math.round(((e.pageY * 10) - (grid.top * 10)) / 10);
});
},
the problem is that the mouse coordinates only update when the mouse moves. is there any way to get the coordinates with out moving the mouse?
You always have the latest up-to-date coordinates of the mouse from the last mouse move, clarify why those are not useful to you.

Categories