project-nv / night-vision

Highly customizable charting library, created for professional traders
https://nightvision.dev
MIT License
237 stars 54 forks source link

Uncaught SyntaxError: Unexpected identifier 'name' custom.navy #89

Closed quantfreedom closed 10 months ago

quantfreedom commented 11 months ago

Describe the bug

Whenever i try to run any main.js with a navy file i am getting this error Uncaught SyntaxError: Unexpected identifier 'name'

i am literally just trying to run custom overlays and it isn't working for me https://nightvision.dev/guide/intro/10-basic-examples.html#_7-custom-overlays

even if i take the line of name out it hits me with another unexpected token of { ....

everything works fine if i am not using a navy file ... but as soon as i try to use it then i am getting all these unexpected token errors

do i have to install something special to run navy files or something?

does anyone have any idea on why this is happening image image

Reproduction

if you want you can check out my code here ... everything should be working https://github.com/QuantFreedom1022/QuantFreedom/tree/neo/nightvision/overlay_test

Steps to reproduce

No response

Javascript Framework

no-framework (vanilla-js)

Logs

No response

Validations

quantfreedom commented 11 months ago

ok so i finally got it to work ... can you guys please include in the example that you have to make sure you do npm install vite npm install @sveltejs/vite-plugin-svelte

then you have to add

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import viteRawPlugin from "./vite/vite-raw-plugin.js";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    svelte({
      emitCss: false,
    }),
    viteRawPlugin({
      fileRegex: /\.navy$/,
    })
  ]
})

as a vite.config.js file then you have to create a folder called vite in your main folder and inside that vite folder you have to have a vite-raw-plugin.js file that says

export default function viteRawPlugin (options) {
  return {
    name: 'vite-raw-plugin',
    transform (code, id) {
      if (options.fileRegex.test(id)) {
        const json = JSON.stringify(code)
          .replace(/\u2028/g, '\\u2028')
          .replace(/\u2029/g, '\\u2029')

        return {
          code: `export default ${json}`
        }
      }
    }
  }
}

i mean wow ... there is sooooooooooooooo much missing from that example ... hopefully you guys are able to update it

quantfreedom commented 11 months ago

but all i am trying to do is draw a circle above one of the candles in my data and i have no idea how to do that because there aren't any examples on how to draw objects in the examples section ... if you guys could please add an example of how to draw a simple circle at the open of a candle and maybe three candles later you put a square 10 dollars points above the high of the candle that would be great ... all you would need is like 10 candles to do this

right now i am trying to do that with no success

https://github.com/QuantFreedom1022/QuantFreedom/tree/neo/nightvision/overlay_test ... you can refer to this to see what i am trying to do

the main reason why this is also hard is because there isn't a way to debug the navy file so i have no idea what i am doing wrong :(

C451 commented 11 months ago

Good to hear you solved the first problem. This library requires a good level of understanding of js / canvas api. I can suggest you to go through the examples here https://github.com/project-nv/night-vision-os/tree/main/overlays.

quantfreedom commented 11 months ago

Good to hear you solved the first problem. This library requires a good level of understanding of js / canvas api. I can suggest you to go through the examples here https://github.com/project-nv/night-vision-os/tree/main/overlays.

yeah i understand that ... but to leave out such important info when others have had problems with this same situation 2 years ago shoudl show that the examples should be updated? would highly suggest just adding those very few lines ... you can even copy paste what i put up as an example

you can see someone else with the same type of issue 1 year ago https://github.com/project-nv/night-vision/issues/26

maybe also it could be included in the overlay or navy.js section of the docs as the first thing someone must do before using it because i am sure there are others out there who just don't report the issue

C451 commented 10 months ago

Added the line to docs