Is it possible to add a line under each row in a jspd-autotable? i.e. not borders around every cell, just a bottom border on every cell.
We can specify any side border by using the hook "willDrawCell" of jspdf autotable and jspdf line method.
Example:
doc.autoTable({
willDrawCell: function(data) {
// add borders around the head cells
if (data.row.section === "head") {
doc.setDrawColor(0, 0, 0); // set the border color
doc.setLineWidth(0.5); // set the border with
// draw bottom border
doc.line(
data.cell.x,
data.cell.y + data.cell.height,
data.cell.x + data.cell.width,
data.cell.y + data.cell.height
);
// draw top border
doc.line(
data.cell.x + data.cell.width,
data.cell.y,
data.cell.x,
data.cell.y
);
// draw left border
doc.line(
data.cell.x,
data.cell.y + data.cell.height,
data.cell.x,
data.cell.y
);
// draw right border
doc.line(
data.cell.x + data.cell.width,
data.cell.y,
data.cell.x + data.cell.width,
data.cell.y + data.cell.height
);
}
},
});
Can also add border to some specific cells:
doc.autoTable({
willDrawCell: function(data) {
// add borders around the head cells
if (data.row.section === "head" && data.column.dataKey === "qty") {
doc.setDrawColor(255, 255, 0); // set the border color
doc.setLineWidth(0.5); // set the border with
// draw bottom border
doc.line(
data.cell.x,
data.cell.y,
data.cell.x + data.cell.width,
data.cell.y
);
}
},
});
Ref: https://github.com/simonbengtsson/jsPDF-AutoTable/issues/651#issuecomment-626272061
In the end I managed to do this by hiding all of the borders and adding a fake row in between every row. I then set the height of every odd row (excluding the heading) to a small value and set the background colour to black. Bit of a hack but it works and looks good.
Related
In this example, I tried to move the points by points.graphic.translate(0, -25), but it can't help to move point's label and SVGs. You can see the details in the example.
events: {
load() {
var chart = this,
series = chart.series[0];
series.points.forEach(function(point) {
point.graphic.translate(0, -25);
});
}
}
You need to move each element separately.
Label:
point.dataLabel.text.translate(0, -25)
And custom image just after rendering it:
points.forEach(function(point) {
point.customImg = chartt.renderer.image(
'https://www.highcharts.com/images/employees2014/Torstein.jpg',
point.plotX + chartt.plotLeft + point.shapeArgs.width / 2 - width / 2,
point.plotY + chartt.plotTop - height / 2,
width,
height
)
.attr({
zIndex: 5
})
.add();
point.customImg.translate(0, -25)
});
Demo: https://jsfiddle.net/BlackLabel/05hmufxa/
I want to put some images as SVG on each point in Gantt chart, I've tried something like below:
function (chartt) { // on complete
chartt.renderer.image('imageURL.png',100,100,30,30)
.add();
}
But after running this code, the image will be shown on the corner of the page. I want to draw images on each point in the chart and set their position related to its point.
Live Demo: https://jsfiddle.net/meysamm22/x41wdu5z/
You need to use the right x and y attributes, calculate them based on plotX and plotY point's properties:
function(chartt) { // on complete
var points = chartt.series[0].points,
width = 30,
height = 30;
points.forEach(function(point) {
chartt.renderer.image(
'https://www.highcharts.com/images/employees2014/Torstein.jpg',
point.plotX + chartt.plotLeft + point.shapeArgs.width / 2 - width / 2,
point.plotY + chartt.plotTop - height / 2,
width,
height
)
.attr({
zIndex: 5
})
.add();
});
});
Live demo: https://jsfiddle.net/BlackLabel/r4ph3ykz/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#image
I wish to know how many styles does OpenCV have for drawing detections. I wish know how to draw the rectangle like in this image:
OpenCV doesn't provide styles. You can only draw a rectangle with a given color, with 4/8 connected or with anti-aliasing points, with a given thickness.
You can, however, simply draw 8 lines recovering the coordinates from the rectangle:
The code is pretty straightforward:
#include <opencv2/opencv.hpp>
using namespace cv;
void drawDetection(Mat3b& img, const Rect& r, Scalar color = Scalar(0,255,0), int thickness = 3)
{
int hor = r.width / 7;
int ver = r.height / 7;
// Top left corner
line(img, r.tl(), Point(r.x, r.y + ver), color, thickness);
line(img, r.tl(), Point(r.x + hor, r.y), color, thickness);
// Top right corner
line(img, Point(r.br().x - hor, r.y), Point(r.br().x, r.y), color, thickness);
line(img, Point(r.br().x, r.y + ver), Point(r.br().x, r.y), color, thickness);
// Bottom right corner
line(img, Point(r.br().x, r.br().y - ver), r.br(), color, thickness);
line(img, Point(r.br().x - hor, r.br().y), r.br(), color, thickness);
// Bottom left corner
line(img, Point(r.x, r.br().y - ver), Point(r.x, r.br().y), color, thickness);
line(img, Point(r.x + hor, r.br().y), Point(r.x, r.br().y), color, thickness);
}
int main()
{
// Load image
Mat3b img = imread("path_to_image");
// Your detection
Rect detection(180, 160, 220, 240);
// Custom draw
drawDetection(img, detection);
imshow("Detection", img);
waitKey();
return 0;
}
I want to draw a border on chart.Basically its a rectangular chart. So I can use plotxsize,plotysize,plotleft,plottop to draw border as rectangle.
chart.renderer.rect(
chart.plotLeft,
chart.plotTop,
chart.plotSizeY,
chart.plotSizeX,
0).attr({
'stroke-width' : 2,
'stroke' : '#3fa9f5',
'fill' : 'none'
}).add();
But is there any way to remove that rectangular border.
Or is there a way to update plotborderwidth and plotbordercolor dynamically?
Keeping rendered object in variable, allows to show/hide SVG object by show/hide option.
Example:
- http://jsfiddle.net/n9tLuf92/
var r = chart.renderer,
borderColor = '#346691',
borderWidth = 2,
top = chart.plotTop,
width = chart.plotWidth,
left = chart.plotLeft,
height = chart.plotHeight,
border;
border = r.path(['M', left, top, 'L', left + width, top, 'L', left + width, top + height, 'L', left, top + height, 'Z'])
.attr({
'visible': true,
'stroke': borderColor,
'stroke-width': borderWidth
})
.add();
Docs:
- http://api.highcharts.com/highcharts#Renderer.path
By attr() function you can manipulate params.
Example:
border.attr({
'stroke': 'green'
})
I want to show the tooltip on the right side of the cursor.
I looked in the documentation/examples but I can't find a way to force the tooltips to stay on the right side of the cursor.
Can anyone tell me how to do it?
With tooltip positioner I only can set a default position.
Tooltip positioner is much more than just default position. The function arguments contain info about your point position & tooltip dimensions, using which it should be fairly simple to position it to the right.
Highchart/stock allows you to define your alternate positioner as follows
tooltip:{
positioner:function(boxWidth, boxHeight, point){
...
}
}
Note that you have three arguments (boxWidth, boxHeight, point) at your disposal, these seem to be sufficient for most of the use cases to calculate a desired tooltip position. boxWidth and boxHeight are the width and height that your tooltip will require, hence you can use them for edge cases to adjust your tooltip and prevent it from spilling out of the chart or even worse getting clipped.
The default tooltip positioner that comes with highstock is as follows (Source)
/**
* Place the tooltip in a chart without spilling over
* and not covering the point it self.
*/
getPosition: function (boxWidth, boxHeight, point) {
// Set up the variables
var chart = this.chart,
plotLeft = chart.plotLeft,
plotTop = chart.plotTop,
plotWidth = chart.plotWidth,
plotHeight = chart.plotHeight,
distance = pick(this.options.distance, 12), // You can use a number directly here, as you may not be able to use pick, as its an internal highchart function
pointX = point.plotX,
pointY = point.plotY,
x = pointX + plotLeft + (chart.inverted ? distance : -boxWidth - distance),
y = pointY - boxHeight + plotTop + 15, // 15 means the point is 15 pixels up from the bottom of the tooltip
alignedRight;
// It is too far to the left, adjust it
if (x < 7) {
x = plotLeft + pointX + distance;
}
// Test to see if the tooltip is too far to the right,
// if it is, move it back to be inside and then up to not cover the point.
if ((x + boxWidth) > (plotLeft + plotWidth)) {
x -= (x + boxWidth) - (plotLeft + plotWidth);
y = pointY - boxHeight + plotTop - distance;
alignedRight = true;
}
// If it is now above the plot area, align it to the top of the plot area
if (y < plotTop + 5) {
y = plotTop + 5;
// If the tooltip is still covering the point, move it below instead
if (alignedRight && pointY >= y && pointY <= (y + boxHeight)) {
y = pointY + plotTop + distance; // below
}
}
// Now if the tooltip is below the chart, move it up. It's better to cover the
// point than to disappear outside the chart. #834.
if (y + boxHeight > plotTop + plotHeight) {
y = mathMax(plotTop, plotTop + plotHeight - boxHeight - distance); // below
}
return {x: x, y: y};
}
With all the above information, I think you have sufficient tools to implement your requirement by simply modifying the function to make float to right instead of the default left.
I will go ahead and give you the simplest implementation of positioning tooltip to right, you should be able to implement the edge cases based on the aftermentioned default tooltip positioner's code
tooltip: {
positioner: function(boxWidth, boxHeight, point) {
return {x:point.plotX + 20,y:point.plotY};
}
}
Read more # Customizing Highcharts - Tooltip positioning
The better solution to get your tooltip always on the right side of the cursor is the following:
function (labelWidth, labelHeight, point) {
return {
x: point.plotX + labelWidth / 2 + 20,
y: point.plotY + labelHeight / 2
};
}