Creating straight line using drag and custom js

Before going further, I think you should take a closer look at the PolyDrawTool. Despite it’s name, it can be used to draw multiple polylines:

The coordinates of what gets drawn are conveniently, automatically stored in a ColumnDataSource for you to do whatever you want with.

I very strongly suggest you should consider finding a way to utilize this existing tool first. Simply because: any similar custom tool you create would be nearly as complicated as it is, and you can see by looking at the source code that is it is quite complicated (nearly 300 lines of TypeScript). If you must make a custom tool, then that is a bigger task than I can help with in detail, but all the source code for all the existing tools is available on GitHub to reference.