H
H
Hi-Pyncho2020-10-03 14:00:55
JavaScript
Hi-Pyncho, 2020-10-03 14:00:55

How to implement your own JS library and provide an API?

Hey!
The test task itself looks like this:

Implement a library prototype for displaying line graphs using WEB Canvas, including:
1. Provide your API to set an array of "graphs". Each "chart" must have:
a. Parameter name;
b. Array of points (X,Y).
2. The library must support the following features:
a. Track changes in your own dimensions and provide autofit;
b. Display axes, indicating the parameters displayed on the axes;
c. Track the position of the mouse with the display of a tooltip by points;
d. Scaling the plot area.
The completed test tasks will be tested, including on large arrays of input data.


The question arises: should it just be a small library with a set of methods for drawing line graphs? And what does API mean here - the external interface for working with the library itself, or something more complicated? Has anyone come across this? I myself applied for a junior, so at some moments I swim and mess in my head. Help me to understand.
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey delphinpro, 2020-10-04
@Hi-Pyncho

Since this is a test task, it should be considered that it is self-sufficient.
All disputes you resolve at your discretion.
Thus, we see that we need to be able to draw several graphs.
Prototyping a simple interface

MyChart.init({
  charts: [
    {
      name: 'name',
      axis: {
        x: { /* параметры для оси X */ }
        y: { /* параметры для оси Y */ }
      },
      data: [ /* массив данных (точек) для отрисовки */
        {x:1,y:2},
        //...
      ],
    },
  ],
});

For tooltips, you can have a separate parameter or add an option to an array of points.
Everything else - resizing, scaling - is implemented inside the library, without external interfaces (without settings). This is still a test task, not a full-fledged library.

B
bkosun, 2020-10-03
@bkosun

You need to write the library in such a way that other programmers can conveniently use it in their applications without delving into how its functionality is implemented.

API (application programming interface, application programming interface) (English application programming interface, API [hey-pee] [1]) - a description of the ways (a set of classes, procedures, functions, structures or constants) in which one computer program can interact with another program.

The API defines the functionality that a program (module, library) provides, while the API allows you to abstract from how exactly this functionality is implemented.

If a program (module, library) is considered as a black box, then the API is a set of “handles” that are available to the user of this box and which he can turn and pull.

https://ru.wikipedia.org/wiki/API

L
Leo Mavrin, 2020-10-04
@Leo5878

should it just be a small library with a set of methods for drawing line graphs?

Yes!
And what does API mean here - the external interface itself for working with the library or something more complicated

Just an interface to work with.
Has anyone come across this?

I wrote a library for creating popup windows. It was necessary to write a simple api and a flexible enough api to work with it. I described the api itself with the help of classes and accepted an object as input. I also implemented a functional (functional approach) api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question