popcodeorg / popcodeorg/popcode
validation on canvas element incorrectly flags 'width' attribute as an error
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 191
- Forks
- 143
- Merge medio
- 4 d 11 h
- PR fusionados (30 d)
- 5
Descripción
I'm trying to use a <canvas> element (for a Tiny Turtle exercise) and set its width to something larger than the default of 300px. Naively I tried a css rule:
canvas {
width: 100%;
min-height: 400px;
}
But with <canvas>, a css-specified width actually scales the content. This makes the turtle head and line segments appear quite large and even pixellated and does not actually give any more room to draw.
MDN recommends instead that you set the width and height directly on the element. Trying this triggered a popcode validation error on width:
9
Don't use the "width" attribute. Instead, use the CSS width property
Impact: mostly a little annoying. You can't set the real width of the canvas, so there will be unused space at the right margin -- and quite noticeable with a bigger screen. Complicated turtle drawings may not fit well into 300x150 px (although for some reason the height attribute is allowed through validation, so the canvas can be made taller).
Also, the validator-recommended fix isn't a real fix, which is minor in and of itself but we'd like users to be able to rely on its recommendations.
Steps to reproduce:
- Open this popcode link: https://popcode.org/?gist=1791db30a9fa1cbcc39e0ec181388634
- In the html panel, set the
<canvas>element's width attribute to, say, 400. Observe the validation error. - Observe the somewhat-pixellated turtle stamp render (due to the css width being set w/o html width).
- Observe the rendered length of a
forward(30)segment. Cut thatforwarddown to 10 units to allow more drawing room. Observe that the stamp now overwhelms the line segment.
On a page without validation, eg jsbin, setting the width attr has the desired result of setting the canvas's coordinate system width (which can then optionally be scaled with css).
Tested on macos 10.11 with Safari 10.0.3 and Chrome 56.0.2924.87.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el error de validación usando el gist de Popcode enlazado, centrándote en un elemento canvas con un atributo width y en el mensaje del validador que recomienda CSS width. Rastrea el punto de entrada del validador que emite este mensaje y compara su tratamiento de width con height. La tarea estará terminada cuando se acepte un width válido de canvas y la recomendación ya no contradiga el comportamiento de dimensionamiento de canvas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- html, javascript
- Área
- frontend, testing-qa, web-dev
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100